Skip to main content

Agent Patterns

Common patterns and architectures for building effective AI agents across different use cases.

Single Agent Patterns

ReAct Agent

Reason and Act pattern where agent thinks through problems step-by-step.
from agno import Agent, OpenAI

agent = Agent(
    model=OpenAI(id="gpt-4o"),
    tools=[search_tool, calculator_tool],
    reasoning=True,
    markdown=True
)

response = agent.run("What is the GDP of Japan in 2023?")

Function Calling Agent

Agent with structured tool use via function calling.
from openai import OpenAI

client = OpenAI()

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "parameters": {"location": {"type": "string"}}
    }
}]

response = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    tools=tools
)

Multi-Agent Patterns

Sequential Coordination

Agents work in sequence, each building on previous outputs.
from agno import Agent

# Define agents
researcher = Agent(name="Researcher", role="Research")
writer = Agent(name="Writer", role="Write")
editor = Agent(name="Editor", role="Edit")

# Sequential execution
research = researcher.run(topic)
article = writer.run(research)
final = editor.run(article)

Team Coordination

Coordinator agent delegates to specialist agents.
team_agent = Agent(
    team=[web_agent, finance_agent],
    model=OpenAI(id="gpt-4o")
)

response = team_agent.run("Analyze Tesla stock")

Swarm Orchestration

Circular handoff between specialized agents using AG2.
from autogen.ext.swarm import Swarm

client = Swarm()

response = client.run(
    agent=initial_agent,
    messages=[{"role": "user", "content": query}],
    context_variables={"phase": "summary"}
)

AI Agents

Learn about different agent types

Multi-Agent Teams

Build coordinated agent teams