> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quraite.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Smolagents

> How to integrate Smolagents agents with Quraite.

## Overview

Quraite provides a built-in adapter for Smolagents. This adapter allows you to integrate Smolagents agents with Quraite and run evaluations on them.

This adapter uses OpenInference instrumentation to capture the trajectory of the agent.

## Prerequisites

* Agent dependencies: `smolagents[openai]` package, OpenAI API key, and any tools you want to use.
* Quraite dependencies: `quraite[smolagents-oi]` package.

## Define Your Smolagents Agent

You create a normal Smolagents `ToolCallingAgent` first, exactly as you would in any Smolagents project.

```python theme={null}
import datetime
import os
from zoneinfo import ZoneInfo

from smolagents import OpenAIServerModel, ToolCallingAgent, tool
from sqlalchemy import (
    Column,
    Float,
    Integer,
    MetaData,
    String,
    Table,
    create_engine,
    insert,
    text,
)


db_path = "receipts_db.sqlite"
if os.path.exists(db_path):
    os.remove(db_path)
engine = create_engine(f"sqlite:///{db_path}")
metadata_obj = MetaData()
table_name = "receipts"

receipts = Table(
    table_name,
    metadata_obj,
    Column("receipt_id", Integer, primary_key=True),
    Column("customer_name", String(32)),
    Column("price", Float),
    Column("tip", Float),
    Column("city", String(32)),
)

metadata_obj.create_all(engine)

rows = [
    {
        "receipt_id": 1,
        "customer_name": "Alan Payne",
        "price": 12.06,
        "tip": 1.20,
        "city": "New York",
    },
    # ... more rows ...
]

with engine.begin() as connection:
    for row in rows:
        connection.execute(insert(receipts).values(**row))


@tool
def sql_engine(query: str) -> str:
    """Execute SQL queries against the receipts table."""
    with engine.connect() as con:
        rows = con.execute(text(query))
        return "\n".join(str(row) for row in rows)


@tool
def current_time(city: str) -> str:
    """Return the current time for a known city."""
    mapping = {
        "new york": "America/New_York",
        "san francisco": "America/Los_Angeles",
        "london": "Europe/London",
    }
    tz_identifier = mapping.get(city.lower())
    if not tz_identifier:
        return f"Timezone for {city} not available."

    now = datetime.datetime.now(ZoneInfo(tz_identifier))
    return now.strftime("%Y-%m-%d %H:%M:%S %Z%z")


sql_agent = ToolCallingAgent(
    tools=[sql_engine, current_time],
    model=OpenAIServerModel("gpt-4o"),
)
```

## Set up Tracing

Quraite provides a tracing setup helper. For Smolagents, pass the `Framework.SMOLAGENTS` enum:

```python theme={null}
from quraite.tracing import Framework, setup_tracing


tracer_provider = setup_tracing([Framework.SMOLAGENTS])
```

## Wrap the Smolagents Agent

Wrap the agent with the `SmolagentsAdapter` and pass the `tracer_provider` to it.

```python theme={null}
from quraite.adapters import SmolagentsAdapter


adapter = SmolagentsAdapter(
    agent=sql_agent,
    agent_name="Smolagents SQL Agent",
    tracer_provider=tracer_provider,
)
```

## Run the Agent

Once wrapped, you expose the adapter using Quraite's `run_agent` helper.

```python theme={null}
if __name__ == "__main__":
    from quraite import run_agent
    from dotenv import load_dotenv

    load_dotenv(override=True)

    run_agent(
        adapter,
        port=8080,
        host="0.0.0.0",
        tunnel="cloudflare",
    )
```

## End-to-End Examples

* [Smolagents SQL agent example](https://github.com/innowhyte/quraite-python/tree/main/examples/smolagents_sql_agent)
