Agent Architecture

Understanding how AI agents are structured

Every PraisonAI agent has the same core structure. Understanding it helps you build better agents.

Diagram

Agent Architecture

📥 Input
Your request

🧠 Brain
LLM processing

🔧 Tools
External actions

💾 Memory
Context storage

📤 Output
Response


The 4 Core Components


Building an Agent

  1. Instructions – Define Purpose
    python
    from praisonaiagents import Agent
    
    agent = Agent(
        instructions="You are a helpful coding assistant"
    )
  2. LLM – Choose the Brain
    python
    agent = Agent(
        instructions="You are a helpful assistant",
        llm="gpt-4o"  # Or "claude-3", "gemini-pro", etc.
    )
  3. Tools – Add Capabilities
    python
    def calculate(expression: str) -> str:
        """Calculate a math expression"""
        return str(eval(expression))
    
    agent = Agent(
        instructions="You help with math",
        tools=[calculate]
    )
  4. Memory – Remember Context
    python
    agent = Agent(
        instructions="You are a personal assistant",
        memory=True  # Remember conversations
    )

Complete Example

python
from praisonaiagents import Agent

def search_web(query: str) -> str:
    """Search the web"""
    return f"Results for: {query}"

# Full agent with all components
agent = Agent(
    name="ResearchAssistant",
    instructions="You research topics and provide summaries",
    llm="gpt-4o",
    tools=[search_web],
    memory=True
)

agent.start("Research the latest AI trends")

The Agent Loop

Every agent follows this cycle:

Diagram

Agent Loop

📥 Receive

🧠 Think

âš¡ Act

💬 Respond

StepWhat Happens
ReceiveAgent gets your message
ThinkLLM processes and plans
ActUses tools if needed
RespondReturns the answer

Multi-Agent Architecture

Multiple agents can work together:

Diagram

Team Architecture

📋 Task

🤖 Researcher

🤖 Writer

🤖 Editor

✅ Result

python
from praisonaiagents import Agent, AgentTeam

researcher = Agent(instructions="Research topics")
writer = Agent(instructions="Write content")
editor = Agent(instructions="Edit and polish")

team = AgentTeam(agents=[researcher, writer, editor])
team.start()

Key Takeaways

Start Simple

Begin with just instructions – add tools and memory later

Choose the Right LLM

GPT-4o for complex tasks, GPT-4o-mini for simple ones

Tools Extend Capabilities

Any Python function can become a tool

Memory Enables Context

Enable memory for multi-turn conversations


Next: Agent Instructions

Learn how to write effective instructions for your agents.