Designing the Agent's Brain (Architecture) › Making Decisions Smarter

Michael BrenndoerferJuly 9, 20252 min read
AI Agent HandbookAll chapters
Part 7 of 15Agent State and Architecture - Putting It All Together
Chapter 19Designing the Agent's Brain (Architecture) › Making Decisions Smarter
Reading section 7 of 14 · Making Decisions Smarter · 2 minSection 7 of 14 · 2 min

Book contents

Section 7 of 14 · 2 min read

Designing the Agent's Brain (Architecture) › Making Decisions SmarterOne section · Sections in this chapter7 / 14 ↓

So far, our decision logic has been pretty basic: check for keywords, look for patterns, apply simple rules. But you can make this much more sophisticated.

One powerful approach is to ask the model itself what to do. Instead of hard-coding rules, you can prompt the model to analyze the input and suggest an action:

In[6]:
Code
def decide_action_with_model(self, user_input: str) -> str:
    """Let the model help decide what to do"""
    decision_prompt = f"""You are an AI assistant with these capabilities:
- use_calculator: For math problems
- search_memory: To recall previous information
- use_model: For general questions and conversation

Given this user input: "{user_input}"

What capability should be used? Respond with just the capability name."""

    response = self.client.messages.create(
        model=self.model,
        messages=[{"role": "user", "content": decision_prompt}],
        max_tokens=50
    )
    
    action = response.content[0].text.strip()
    return action

This approach is more flexible because the model can understand nuance and context that simple pattern matching would miss. For example, "What's 2 plus 2?" and "Can you add these numbers: 2 and 2?" both need the calculator, but they don't match the same pattern.

The trade-off is that you're making an extra API call for each decision, which adds latency and cost. In practice, you might use a hybrid approach: simple rules for obvious cases, and model-based decisions for ambiguous ones.