Agent
The heart of ConnectOnion. Give it tools, and it figures out the rest.
Quick Start (60 Seconds)
That's it. Your first AI agent in 5 lines.
What Agent Can Do - Full API Overview
After that simple example, here's everything an Agent can do:
Creating an Agent
Agent(
name="my_bot", # Required: agent identifier
tools=[func1, func2], # Optional: functions agent can call
system_prompt="You are helpful", # Optional: personality/behavior
model="o4-mini", # Optional: LLM model
api_key="sk-...", # Optional: override env var
llm=custom_llm, # Optional: custom LLM instance
trust="tested", # Optional: security verification
log=True # Optional: logging config
)Using Your Agent
# Give it a task
result = agent.input("Do something")
# Execute a tool directly (for testing)
result = agent.execute_tool("tool_name", {"arg": "value"})Managing Tools
agent.add_tool(new_function) # Add tools after creation
agent.remove_tool("name") # Remove tools
agent.list_tools() # See available toolsConversations & State
agent.input("What is 10 + 5?") # Turn 1: "15"
agent.input("Multiply that by 2") # Turn 2: "30" (remembers!)
agent.reset_conversation() # Start fresh
session = agent.current_session # Access internal stateAttributes You Can Access
agent.name # str: Agent identifier
agent.tools # ToolRegistry: All tools
agent.tools.names() # list[str]: Tool names
agent.tools.get("name") # Tool: Get by name
agent.system_prompt # str: Personality
agent.current_session # dict | None: Runtime stateThat's the complete API.
Now let's dive into each feature below. Jump to any section that interests you!
max_iterations
What Are Iterations?
Think of iterations as "attempts" - how many times your agent can use tools to complete a task.
The Basics (90% of cases)
When You Need More Power
Quick Override for One Task
When to Adjust max_iterations
- Your agent runs complex, multi-step workflows
- Tasks require multiple tool calls (research, analysis, etc.)
- You see "reached max iterations" in logs
- Agent loops unnecessarily (calls same tool repeatedly)
- You want faster failures for debugging
- Simple tasks that should complete quickly
Best Practices
- Start with default (10) - it works for most use cases
- Monitor your logs - check how many iterations tasks actually use
- Set per-agent for specialized agents (researcher=25, calculator=5)
- Override per-task when you know a specific task needs more/less
Complete Documentation
This page provides a quick overview of the Agent class. For comprehensive documentation including:
Use the "Copy" button above to get the full markdown documentation with all details, examples, and patterns.
Learn More
Philosophy
"Keep simple things simple, make complicated things possible"
Simple Case
agent = Agent("bot", tools=[search])
agent.input("Find Python docs")Complex Case
trust_agent = Agent("verifier", ...)
agent = Agent(
name="production",
llm=custom_llm,
tools=[deploy, rollback],
system_prompt=Path("ops.md"),
max_iterations=30,
trust=trust_agent,
log="/var/log/production.log"
)Both are valid. Start simple, add complexity only when needed.
ConnectOnion: AI Agent = Prompt + Function
That's it. That's the framework. Now go build something useful.
