A Python SDK for building AI agents with Opper Task Completion API. Create intelligent agents that use tools-based reasoning loops with dynamic tool selection, event tracking, and MCP integration.
- Features
- Getting Started
- Installation
- Quick Start
- Agent as a Tool
- MCP (Model Context Protocol) Integration
- Hooks
- Visualizing Agent Flow
- Monitoring and Tracing
- License
- Support
- Reasoning with customizable model: Think → Act reasoning loop with dynamic tool selection
- Extendable tool support: Support for MCP or custom tools
- Event Hooks: Flexible hook system for accessing any internal Agent event
- Composable interface: Agent supports structured input and output schema for ease of integration
- Multi-agent support: Agents can be used as tools for other agents to allow for delegation
- Type Safety internals: Pydantic model validation throughout execution
- Error Handling: Robust error handling with retry mechanisms
- Tracing & Monitoring: Full observability with Opper's tracing system
Building an agent takes three steps:
from opper_agent import Agent, tool
# 1. Define your tools
@tool
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"The weather in {city} is sunny"
# 2. Create the agent
agent = Agent(
name="WeatherBot",
description="Helps with weather queries",
tools=[get_weather]
)
# 3. Run it
result = await agent.process("What's the weather in Paris?")
- Python >= 3.11
pip install opper-agents
Or using UV:
uv pip install opper-agents
If you want to contribute or modify the SDK:
- Clone the repository:
git clone https://github.com/opper-ai/opperai-agent-sdk.git
cd opperai-agent-sdk
- Install in editable mode:
# Using pip
pip install -e .
# Or using UV (recommended)
uv pip install -e .
export OPPER_API_KEY="your-opper-api-key"
Get your API key at platform.opper.ai.
Check out the examples/
directory for working examples:
- Getting Started (
examples/01_getting_started/
): Basic agent usage, memory, hooks - MCP Integration (
examples/02_mcp_examples/
): Connect to MCP servers - Applied Agents (
examples/applied_agents/
): Real-world examples like multi-agent systems - Custom Agents (
examples/custom_agents/
): Build specialized agent types (React, Chat)
Run any example:
python examples/01_getting_started/01_first_agent.py
You can specify AI models at the agent level to control which model is used for reasoning. The SDK supports all models available through the Opper API:
# Create agent with specific model
agent = Agent(
name="ClaudeAgent",
description="An agent that uses Claude for reasoning",
tools=[my_tools],
model="anthropic/claude-4-sonnet" # Model for reasoning and tool selection
)
If no model is specified, Opper uses a default model optimized for agent reasoning.
Agents can be used as tools by other agents for delegation and specialization:
# Create specialized agents
math_agent = Agent(name="MathAgent", description="Performs calculations")
research_agent = Agent(name="ResearchAgent", description="Explains concepts")
# Use them as tools in a coordinator agent
coordinator = Agent(
name="Coordinator",
tools=[math_agent.as_tool(), research_agent.as_tool()]
)
See examples/01_getting_started/02_agent_as_tool.py
for a complete example.
The SDK supports MCP servers as tool providers, allowing agents to connect to external services. Both stdio
and HTTP-SSE transports are supported.
from opper_agent import mcp, MCPServerConfig
# Configure an MCP server
filesystem_server = MCPServerConfig(
name="filesystem",
transport="stdio",
command="docker",
args=["run", "-i", "--rm", "..."]
)
# Use MCP tools in your agent
agent = Agent(
name="FileAgent",
tools=[mcp(filesystem_server)],
)
See examples/02_mcp_examples/
for working examples with filesystem, SQLite, and Composio servers.
Hooks let you run code at specific points in the agent's lifecycle for logging, monitoring, or custom behavior:
Available hooks: agent_start
, agent_end
, agent_error
, loop_start
, loop_end
, llm_call
, llm_response
, think_end
, tool_call
, tool_result
from opper_agent import hook
from opper_agent.base.context import AgentContext
from opper_agent.base.agent import BaseAgent
@hook("agent_start")
async def log_start(context: AgentContext, agent: BaseAgent):
print(f"Agent {agent.name} starting with goal: {context.goal}")
agent = Agent(
name="MyAgent",
hooks=[log_start],
tools=[...]
)
See examples/01_getting_started/05_hooks.py
for all available hooks with detailed examples.
Generate Mermaid diagrams of your agent's structure showing tools, sub-agents, schemas, and hooks. Perfect for documentation and understanding complex multi-agent systems.
agent.visualize_flow(output_path="agent_flow.md")
The agent provides comprehensive observability for production deployments:
- Agent-level spans: Track entire reasoning sessions
- Thought cycles: Monitor think-act iterations
- Tool execution: Performance metrics for each tool call
- Model interactions: AI reasoning and decision making
View your traces in the Opper Dashboard
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Opper Documentation
- Issues: GitHub Issues
- Community: Opper Discord
Built with Opper