Lesson 29 of 30 ~15 min
Course progress
0%

When Agents vs Simple Prompts

Rozhodněte se kdy použít agenta a kdy stačí jednoduchý prompt.

Agenti nejsou vždy správná odpověď. Naučte se vybrat správný nástroj pro danou úlohu.

Decision Matrix

SituaceDoporučení
Jednorázová otázkaSimple prompt
Potřebuji externí dataAgent with tools
Multi-step reasoningExtended thinking
Opakující se workflowAgent
Interakce s external systemsAgent with tools
Vysoká přesnost kritickáAgent s validací
Quick prototypeSimple prompt
Production systemAgent

Kdy použít Simple Prompt

✅ Ideální pro:

# 1. Direct questions
response = claude("What is dependency injection?")

# 2. Text transformation
response = claude(f"Translate to Czech: {text}")

# 3. Analysis without external data
response = claude(f"Review this code: {code}")

# 4. Creative writing
response = claude("Write a poem about programming")

# 5. Explanations
response = claude(f"Explain this error: {error}")

Výhody simple prompts:

  • Nižší latence
  • Nižší cost
  • Méně bodů selhání
  • Jednodušší debugging

Kdy použít Agent

✅ Ideální pro:

# 1. Needs external data
agent.run("What's the current stock price of AAPL?")

# 2. Multi-step tasks
agent.run("Create a new React component with tests")

# 3. Conditional logic
agent.run("If tests pass, deploy to staging")

# 4. Iterative refinement
agent.run("Keep improving until score > 0.9")

# 5. Complex workflows
agent.run("Review PR, suggest fixes, apply them, run tests")

Výhody agentů:

  • Mohou interagovat s external systems
  • Mohou se rozhodovat dynamicky
  • Mohou iterovat a opravovat chyby
  • Mohou orchestrovat komplexní workflow

Hybridní přístup

Často je nejlepší kombinace:

class HybridAssistant:
    def __init__(self):
        self.client = Anthropic()
        self.agent = FullAgent()
    
    async def handle(self, request: str):
        # Nejdřív zeptej Clause jestli potřebuje nástroje
        classification = await self.classify(request)
        
        if classification == "simple":
            # Direct answer
            return await self.simple_response(request)
        elif classification == "needs_tools":
            # Use agent
            return await self.agent.run(request)
        else:
            # Extended thinking bez nástrojů
            return await self.thinking_response(request)
    
    async def classify(self, request: str) -> str:
        response = self.client.messages.create(
            model="claude-haiku-3-5",  # Rychlý model pro klasifikaci
            max_tokens=20,
            messages=[{
                "role": "user",
                "content": f"""Classify this request:
"{request}"

Categories:
- simple: Can answer directly from knowledge
- needs_tools: Needs to access external data or run code
- thinking: Needs deep reasoning but no tools

Return only the category."""
            }]
        )
        return response.content[0].text.strip()

Cost comparison

Scénář: Code review

Simple prompt:

Input: 2000 tokens
Output: 500 tokens
Cost: $0.037 (Opus)
Time: 5 seconds

Agent s nástroji:

Calls: 3 (analyze, run tests, final report)
Total input: 6000 tokens
Total output: 2000 tokens
Tool calls: 2
Cost: $0.24 (Opus)
Time: 45 seconds

Kdy to stojí za to:

  • Když agent najde bug který byste manuálně nenašli: ✅
  • Pro rutinní review jednoduchého kódu: ❌

Anti-patterns

❌ Over-engineering

# Nepotřebujete agenta pro:
agent = ComplexAgent(tools=[...])
result = agent.run("What is 2 + 2?")

# Stačí:
result = claude("What is 2 + 2?")

❌ Under-engineering

# Tohle nebude fungovat spolehlivě:
result = claude("Check the weather and if it's raining, 
                 send me an email reminder")

# Potřebujete agenta:
agent = Agent(tools=[weather_tool, email_tool])
result = agent.run("Check weather, email me if raining")

Rozhodovací flowchart

                    ┌─────────────────┐
                    │ New Request     │
                    └────────┬────────┘

                    ┌────────▼────────┐
                    │ Needs external  │
                    │ data/actions?   │
                    └────────┬────────┘

              ┌──────────────┼──────────────┐
              │ NO           │              │ YES
              ▼              │              ▼
    ┌─────────────────┐      │    ┌─────────────────┐
    │ Complex multi-  │      │    │ Use AGENT       │
    │ step reasoning? │      │    │ with tools      │
    └────────┬────────┘      │    └─────────────────┘
             │               │
    ┌────────┼────────┐      │
    │ NO     │        │ YES  │
    ▼        │        ▼      │
┌───────┐    │  ┌──────────┐ │
│SIMPLE │    │  │EXTENDED  │ │
│PROMPT │    │  │THINKING  │ │
└───────┘    │  └──────────┘ │
             │               │
             └───────────────┘

Vyberte správný nástroj pro danou práci - ne vždy nejsložitější.