# smolagents

Hugging Face developed smolagents as a minimalist, open-source framework for building AI agents with minimal code. The library prioritizes simplicity and efficiency, enabling developers to deploy LLM-powered agents quickly.

This guide covers capturing telemetry from smolagents applications using InteractiveAI.

### Prerequisites

* InteractiveAI account with API credentials
* Hugging Face token

***

### Installation

```bash
pip install interactiveai 'smolagents[telemetry]' opentelemetry-sdk opentelemetry-exporter-otlp openinference-instrumentation-smolagents
```

***

### Configuration

Set your API credentials as environment variables:

```python
import os

# InteractiveAI credentials
# Obtain keys from Settings > API Keys in the dashboard
os.environ["INTERACTIVEAI_PUBLIC_KEY"] = "pk-ia-..."
os.environ["INTERACTIVEAI_SECRET_KEY"] = "sk-ia-..."

# Hugging Face token
os.environ["HF_TOKEN"] = "hf_..."
```

Initialize the client and confirm connectivity:

```python
from interactiveai import Interactive

client = Interactive(
    public_key=os.environ["INTERACTIVEAI_PUBLIC_KEY"],
    secret_key=os.environ["INTERACTIVEAI_SECRET_KEY"],
    host=os.environ.get("INTERACTIVEAI_HOST", "https://app.interactiveai.com")
)

if client.auth_check():
    print("Connection established")
else:
    print("Authentication failed - verify credentials")
```

***

### Enabling Trace Capture

Initialize the SmolagentsInstrumentor before your application code:

```python
from openinference.instrumentation.smolagents import SmolagentsInstrumentor

SmolagentsInstrumentor().instrument()
```

***

### Running a smolagent

Here's an example with a manager agent orchestrating a search agent:

```python
import os
from smolagents import (
    CodeAgent,
    ToolCallingAgent,
    DuckDuckGoSearchTool,
    VisitWebpageTool,
    OpenAIModel,
)

model = OpenAIModel(model_id="gpt-4o-mini")

search_agent = ToolCallingAgent(
    tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],
    model=model,
    name="search_agent",
    description="This agent performs web searches and retrieves webpage content.",
)

manager_agent = CodeAgent(
    tools=[],
    model=model,
    managed_agents=[search_agent],
)

manager_agent.run(
    "Research the current adoption rates of renewable energy in Europe and summarize the key trends."
)
```

***

### Enriching Traces with Context

Combine the SmolagentsInstrumentor with the InteractiveAI SDK to attach identifiers and metadata:

```python
```

***

### Trace Visibility

The InteractiveAI dashboard displays:

* Manager and managed agent interactions
* Tool invocations with search queries and results
* LLM calls with prompts and completions
* Multi-step reasoning chains
* Token consumption and latency metrics


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.interactive.ai/integrations/ai-frameworks/smolagents.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
