Designing the Agent's Brain (Architecture) › A Minimal Agent Architecture (Example: Claude Sonnet 4.5)

Michael BrenndoerferJuly 9, 20251 min read
AI Agent HandbookAll chapters
Part 7 of 15Agent State and Architecture - Putting It All Together
Chapter 19Designing the Agent's Brain (Architecture) › A Minimal Agent Architecture (Example: Claude Sonnet 4.5)
Reading section 3 of 14 · A Minimal Agent Architecture (Example: Claude Sonnet 4.5) · 1 minSection 3 of 14 · 1 min

Book contents

Section 3 of 14 · 1 min read

Designing the Agent's Brain (Architecture) › A Minimal Agent Architecture (Example: Claude Sonnet 4.5)One section · Sections in this chapter3 / 14 ↓

Here's a basic implementation of the agent loop. We're using Claude Sonnet 4.5 because it excels at agent-based reasoning and tool use.

In[3]:
Code
import os
import anthropic

class SimpleAgent:
    def __init__(self, model="claude-sonnet-4-5"):
        self.client = anthropic.Anthropic()
        self.model = model
        # State: conversation history
        self.conversation_history = []
        
    def run(self, user_input):
        # Step 1: Receive input
        # Step 2: Update state (add to memory)
        self.conversation_history.append({
            "role": "user",
            "content": user_input
        })
        
        # Step 3 & 4: Decide and act (let the model handle it)
        response = self.client.messages.create(
            model=self.model,
            messages=self.conversation_history,
            max_tokens=1024
        )
        
        # Step 5: Respond
        assistant_message = response.content[0].text
        self.conversation_history.append({
            "role": "assistant",
            "content": assistant_message
        })
        
        return assistant_message

## Try it out
agent = SimpleAgent()
print(agent.run("What's the capital of France?"))
print(agent.run("What did I just ask you?"))
Out[3]:
Console
The capital of France is Paris.
You just asked me "What's the capital of France?"

This agent is minimal but functional. It maintains conversation history (state), sends requests to the model, and remembers what happened. The second question works because the agent has context from the first exchange.

Notice how the agent loop is implicit here. Each call to run() goes through all five steps, even though we haven't written them out explicitly. The model handles most of the decision-making for us.