ConnectOnionConnectOnion
DocsAgent

Agent

The heart of ConnectOnion. Give it tools, and it figures out the rest.

Quick Start (60 Seconds)

main.py
1from connectonion import Agent 2 3# Define what your agent can do 4def calculate(expression: str) -> str: 5 """Do math calculations.""" 6 return str(eval(expression)) 7 8# Create agent 9agent = Agent("math_bot", tools=[calculate]) 10 11# Use it 12result = agent.input("What is 42 * 17?")
Python REPL
Interactive
To calculate 42 * 17, I'll use the calculator tool.
The result is 714.

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

main.py
1Agent( 2 name="my_bot", # Required: agent identifier 3 tools=[func1, func2], # Optional: functions agent can call 4 system_prompt="You are helpful", # Optional: personality/behavior 5 model="o4-mini", # Optional: LLM model 6 api_key="sk-...", # Optional: override env var 7 llm=custom_llm, # Optional: custom LLM instance 8 trust="tested", # Optional: security verification 9 log=True # Optional: logging config 10)

Using Your Agent

main.py
1# Give it a task 2result = agent.input("Do something") 3 4# Execute a tool directly (for testing) 5result = agent.execute_tool("tool_name", {"arg": "value"})

Managing Tools

main.py
1agent.add_tool(new_function) # Add tools after creation 2agent.remove_tool("name") # Remove tools 3agent.list_tools() # See available tools

Conversations & State

main.py
1agent.input("What is 10 + 5?") # Turn 1: "15" 2agent.input("Multiply that by 2") # Turn 2: "30" (remembers!) 3 4agent.reset_conversation() # Start fresh 5session = agent.current_session # Access internal state

Attributes You Can Access

main.py
1agent.name # str: Agent identifier 2agent.tools # ToolRegistry: All tools 3agent.tools.names() # list[str]: Tool names 4agent.tools.get("name") # Tool: Get by name 5agent.system_prompt # str: Personality 6agent.current_session # dict | None: Runtime state

That's the complete API.

Now let's dive into each feature below. Jump to any section that interests you!

max_iterations

Quick Facts: Default is 10 iterations (works for most tasks!). Fully customizable per-agent or per-task.

What Are Iterations?

Think of iterations as "attempts" - how many times your agent can use tools to complete a task.

main.py
1# Your agent tries to complete the task 2# Iteration 1: "I need to search for info" -> calls search tool 3# Iteration 2: "Now I'll calculate something" -> calls calculate tool 4# Iteration 3: "Let me save the result" -> calls save tool 5# Done! Task completed in 3 iterations

The Basics (90% of cases)

main.py
1from connectonion import Agent 2 3# Default: 10 iterations (works for most tasks!) 4agent = Agent("my_bot", tools=[search, calculate]) 5 6# That's it! Just use it: 7result = agent.input("What's 2+2?") # Uses 1 iteration 8result = agent.input("Search for Python tutorials") # Uses 1-2 iterations

When You Need More Power

main.py
1# Complex tasks need more iterations 2research_agent = Agent( 3 "researcher", 4 tools=[search, analyze, summarize], 5 max_iterations=25 # I need more attempts for complex research 6)

Quick Override for One Task

main.py
1# Override max_iterations for a specific task 2agent = Agent("assistant", tools=[search]) # Default: 10 3 4# Most tasks use default 5result = agent.input("Simple question") 6 7# But this one needs more 8result = agent.input( 9 "Complex multi-step task", 10 max_iterations=30 # Override just for this task 11)

When to Adjust max_iterations

Increase it when:
  • Your agent runs complex, multi-step workflows
  • Tasks require multiple tool calls (research, analysis, etc.)
  • You see "reached max iterations" in logs
Decrease it when:
  • 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:

Creating Agents
Managing Tools
Multi-Turn Conversations
Iteration Control
Common Patterns
Testing Strategies

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.