AI agents are the hottest topic in AI engineering, but most discussions skip the architecture. Here are the patterns that actually work beyond the demo stage.

The Spectrum of Agency

Not every task needs a fully autonomous agent. Most production systems use simpler patterns:

  • Chains: Fixed sequence of LLM calls, output of one feeds the next
  • Routers: Single LLM call that selects which path to take
  • Parallelizers: Multiple LLM calls running concurrently, results merged
  • Agents: LLM decides which tools to call in a loop until done

The Basic Agent Loop

from typing import Callable

class Agent:
    def __init__(
        self,
        tools: list[Callable],
        system_prompt: str,
        max_iterations: int = 10,
    ):
        self.tools = {tool.__name__: tool for tool in tools}
        self.system_prompt = system_prompt
        self.max_iterations = max_iterations

    def run(self, task: str) -> str:
        messages = [
            {"role": "system", "content": self.system_prompt},
            {"role": "user", "content": task},
        ]
        for _ in range(self.max_iterations):
            response = call_llm(messages, tools=self.tools)
            if response.finish_reason == "stop":
                return response.content
            tool_result = self.tools[response.tool_name](**response.tool_args)
            messages.append({"role": "tool", "content": str(tool_result)})
        return "Max iterations reached without completion."

Guardrails Are Not Optional

Autonomous agents without guardrails are production incidents waiting to happen. Every agent system needs: cost limits per task, action allowlists, human-in-the-loop for destructive operations, and timeout constraints. The agent that can do anything will eventually do something you didn’t intend.

What to Actually Build

Start with chains. Add routing when you need conditional logic. Reach for full agents only when the task genuinely requires multi-step reasoning with tool use. Most problems don’t need agents — they need well-designed chains.