2/10
Agent Architectures & Frameworks · Page 1 of 1

Popular Agent Patterns

Agent Architectures

ReAct (Reasoning + Acting)

Insight: LLMs do better with explicit reasoning before action.

ReAct Loop:
1. Thought: Agent reasons about next step
2. Action: Agent specifies tool to use
3. Observation: Tool result is returned
4. Repeat

Example:
Thought: "I need to find the population of France"
Action: search("France population")
Observation: "67 million people"
Thought: "I have the answer"

Benefits:

  • More transparent (we see agent's reasoning)
  • Better performance (explicit thinking helps)
  • Easier to debug (can see where agent went wrong)

Chain-of-Thought (CoT)

Agent breaks problems into steps before acting.

Without CoT:
Question: "If a store has 100 apples and sells 25, then receives 50 more, how many do they have?"
Agent: "175" (quick but sometimes wrong)

With CoT:
Question: [same]
Agent:
  Step 1: Start with 100 apples
  Step 2: Sell 25 → 100 - 25 = 75 remaining
  Step 3: Receive 50 → 75 + 50 = 125
  Answer: 125 apples

Better reasoning = Better results!

Reflexion Pattern

Agent reviews its own actions and learns from mistakes.

Step 1: Agent attempts goal
Step 2: Agent observes outcome
Step 3: Reflection: "Did I succeed? What went wrong?"
Step 4: Update strategy
Step 5: Try again with improved approach

Example:
Attempt 1: Book expensive flight → Reflection: "I should check budget first"
Attempt 2: Check budget → Search flights within budget → Book

Agents improve over time!

LangChain Architecture

Popular open-source framework for building agents.

Components:
1. LLM (e.g., GPT-4, Claude)
2. Tools (functions agent can call)
3. Memory (conversation history)
4. Prompts (instructions for agent)
5. Agent executor (orchestrates loop)

Example:
agent = Agent(
  llm=OpenAI(),
  tools=[Calculator, WebSearch, Python],
  memory=ConversationMemory(),
  prompt="You are a helpful assistant"
)

result = agent.run("Solve: 3^4 + sqrt(16)")

Hierarchical Agents

Complex goals broken into sub-agents.

Main Goal: "Generate weekly report"

Sub-agent 1: Collect data
  - Query database
  - Fetch metrics
  
Sub-agent 2: Analyze
  - Statistical analysis
  - Trends & insights
  
Sub-agent 3: Format & Share
  - Create document
  - Send via email

Each agent specialized for their task!

Comparison: Which Architecture?

ReAct: Good for reasoning-heavy tasks
CoT: Good for step-by-step problem solving
Reflexion: Good for iterative improvement
Hierarchical: Good for complex, multi-part goals
main.py
Loading...
OUTPUT
Click "Run Code" to execute…