Skip to main content

Creating an Agent

from a1 import Agent, tool, LLM
from pydantic import BaseModel

@tool
async def add(a: int, b: int) -> int:
    return a + b

class MathInput(BaseModel):
    problem: str

class MathOutput(BaseModel):
    answer: int

# Create agent
agent = Agent(
    name="calculator",
    description="Solves mathematical expressions",
    input_schema=MathInput,
    output_schema=MathOutput,
    tools=[add, multiply, LLM(model="gpt-4.1")],
)

Running Agents

Execute agents with JIT (Just-in-Time):
result = await agent.jit(problem="What is 2 + 3?")
print(result.answer)
For AOT compilation to turn agents into reusable tools, see Compilation.

Agent Properties

  • name: Unique identifier
  • description: What the agent does
  • input_schema: Pydantic model for inputs
  • output_schema: Pydantic model for outputs
  • tools: Available tools (Tool, ToolSet, or LLM instances)
  • skills: Optional reusable knowledge

Accessing Tools

# Get all tools (flattens ToolSets)
all_tools = agent.get_all_tools()

# Get specific tool
add_tool = agent.get_tool("add")

Saving and Loading

# Save to file
agent.save_to_file("my_agent.json")

# Load from file
agent = Agent.load_from_file("my_agent.json")

Next Steps