Agent Architecture
Understanding how AI agents are structured
Every PraisonAI agent has the same core structure. Understanding it helps you build better agents.
graph TB
subgraph "Agent Architecture"
Input[📥 Input<br/>Your request] --> Brain[🧠Brain<br/>LLM processing]
Brain --> Tools[🔧 Tools<br/>External actions]
Brain --> Memory[💾 Memory<br/>Context storage]
Tools --> Output[📤 Output<br/>Response]
Memory --> Brain
end
classDef input fill:#8B0000,stroke:#7C90A0,color:#fff
classDef brain fill:#189AB4,stroke:#7C90A0,color:#fff
classDef tools fill:#2E8B57,stroke:#7C90A0,color:#fff
class Input,Output input
class Brain brain
class Tools,Memory toolsThe 4 Core Components
1. Instructions
What the agent does and how it behaves
2. LLM (Brain)The AI model that powers thinking
3. ToolsFunctions the agent can call
4. MemoryRemembers past conversations
Building an Agent
- Instructions – Define Purpose
python from praisonaiagents import Agent agent = Agent( instructions="You are a helpful coding assistant" ) - LLM – Choose the Brain
python agent = Agent( instructions="You are a helpful assistant", model="gpt-4o" # Or "claude-3", "gemini-pro", etc. ) - 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] ) - Memory – Remember Context
python agent = Agent( instructions="You are a personal assistant", memory=True # Remember conversations )
Complete Example
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",
model="gpt-4o",
tools=[search_web],
memory=True
)
agent.start("Research the latest AI trends")The Agent Loop
Every agent follows this cycle:
graph LR
subgraph "Agent Loop"
Receive[📥 Receive] --> Think[🧠Think]
Think --> Act[âš¡ Act]
Act --> Respond[💬 Respond]
Respond -.-> Receive
end
classDef receive fill:#8B0000,stroke:#7C90A0,color:#fff
classDef think fill:#189AB4,stroke:#7C90A0,color:#fff
classDef act fill:#2E8B57,stroke:#7C90A0,color:#fff
class Receive receive
class Think think
class Act,Respond act| Step | What Happens |
|---|---|
| Receive | Agent gets your message |
| Think | LLM processes and plans |
| Act | Uses tools if needed |
| Respond | Returns the answer |
Multi-Agent Architecture
Multiple agents can work together:
graph LR
subgraph "Team Architecture"
Task[📋 Task] --> A1[🤖 Researcher]
A1 --> A2[🤖 Writer]
A2 --> A3[🤖 Editor]
A3 --> Result[✅ Result]
end
classDef task fill:#8B0000,stroke:#7C90A0,color:#fff
classDef agent fill:#189AB4,stroke:#7C90A0,color:#fff
classDef result fill:#2E8B57,stroke:#7C90A0,color:#fff
class Task task
class A1,A2,A3 agent
class Result resultfrom 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.