Skip to main content
The Opper Agent SDK provides a framework for building AI agents that can reason, use tools, and accomplish complex tasks. Available for both Python and TypeScript, the SDK offers a consistent API with full type safety and observability through the Opper platform.

What is an Agent?

An agent is an AI system that can:
  • Think - Reason about how to accomplish a goal
  • Act - Execute tools to interact with the world
  • Observe - Process results and decide next steps
  • Loop - Continue until the goal is achieved
Unlike simple LLM calls, agents can dynamically choose which tools to use, chain multiple actions together, and maintain context across iterations.

Key Features

Type-Safe Tools

Define tools with full type safety using Pydantic (Python) or Zod (TypeScript). Input and Output validation happens automatically.

Agent Composition

Use agents as tools within other agents. Build complex multi-agent systems with clear hierarchies.

Persistent Memory

Enable memory to persist state across iterations. The LLM decides what to remember and recall.

MCP Integration

Connect to Model Context Protocol servers for filesystem access, databases, APIs, and more.

Lifecycle Hooks

Monitor agent execution with hooks for starts, tool calls, LLM responses, and errors.

Streaming

Stream responses token-by-token for responsive UIs and real-time feedback.

How It Works

The agent follows a think-act loop:
1

Think

The LLM analyzes the goal and available tools, then decides which tools to call—or whether to respond directly.
2

Act

Execute the selected tools and collect their results. If no tools are needed, skip to the final step.
3

Observe

Process tool results and update the agent’s context for the next iteration.
4

Loop or Return

If more work is needed, return to Think. Otherwise, validate the output against the schema and return the final answer.
Each iteration adds to the agent’s context, allowing it to build on previous results until it can produce a final answer.

Quick Example

from opper_agents import Agent, tool

@tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"The weather in {city} is sunny, 22°C"

agent = Agent(
    name="WeatherAgent",
    description="Answers weather questions",
    tools=[get_weather]
)

result = await agent.process("What's the weather in Paris?")
print(result)  # "The weather in Paris is sunny, 22°C"

When to Use the Agent SDK

Good use cases:
  • Tasks requiring multiple steps or tool calls
  • Dynamic decision-making based on intermediate results
  • Complex workflows with branching logic
  • Multi-agent coordination
  • Tasks requiring persistent memory
Consider alternatives for:
  • Simple one-shot LLM calls (use the Opper API directly)
  • Fixed, deterministic workflows (use traditional programming)
  • Real-time latency-critical applications

Next Steps