AgentOps provides seamless integration with Smolagents, HuggingFace’s lightweight framework for building AI agents. Monitor your agent workflows, tool usage, and execution traces automatically.

Core Concepts

Smolagents is designed around several key concepts:

  • Agents: AI assistants that can use tools and reason through problems
  • Tools: Functions that agents can call to interact with external systems
  • Models: LLM backends that power agent reasoning (supports various providers via LiteLLM)
  • Code Execution: Agents can write and execute Python code in sandboxed environments
  • Multi-Agent Systems: Orchestrate multiple specialized agents working together

Installation

Install AgentOps and Smolagents, along with any additional dependencies:

pip install agentops smolagents python-dotenv

Setting Up API Keys

Before using Smolagents with AgentOps, you need to set up your API keys:

  • AGENTOPS_API_KEY: From your AgentOps Dashboard
  • LLM API Keys: Depending on your chosen model provider (e.g., OPENAI_API_KEY, ANTHROPIC_API_KEY)

Set these as environment variables or in a .env file.

export AGENTOPS_API_KEY="your_agentops_api_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"

Then load them in your Python code:

from dotenv import load_dotenv
import os

load_dotenv()

AGENTOPS_API_KEY = os.getenv("AGENTOPS_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

Usage

Initialize AgentOps before creating your Smolagents to automatically track all agent interactions:

import agentops
from smolagents import LiteLLMModel, ToolCallingAgent, DuckDuckGoSearchTool

# Initialize AgentOps
agentops.init()

# Create a model (supports various providers via LiteLLM)
model = LiteLLMModel("openai/gpt-4o-mini")

# Create an agent with tools
agent = ToolCallingAgent(
    tools=[DuckDuckGoSearchTool()],
    model=model,
)

# Run the agent
result = agent.run("What are the latest developments in AI safety research?")
print(result)

Examples

import agentops
from smolagents import LiteLLMModel, CodeAgent

# Initialize AgentOps
agentops.init()

# Create a model
model = LiteLLMModel("openai/gpt-4o-mini")

# Create a code agent that can perform calculations
agent = CodeAgent(
    tools=[],  # No external tools needed for math
    model=model,
    additional_authorized_imports=["math", "numpy"],
)

# Ask the agent to solve a math problem
result = agent.run(
    "Calculate the compound interest on $10,000 invested at 5% annual rate "
    "for 10 years, compounded monthly. Show your work."
)

print(result)

More Examples

Visit your AgentOps Dashboard to see detailed traces of your Smolagents executions, tool usage, and agent reasoning steps.