Every AI agent, no matter how complex, is some variation of the same loop: model reads context, decides on an action, calls a tool, observes the result, repeats. That loop is simple to describe and surprisingly hard to ship reliably. Six months of building agents in production clarifies which abstractions help, which hurt, and which problems you'll encounter regardless of your tool choices.
What an agent actually is
An agent is a system where an LLM decides what to do next rather than following a hardcoded sequence. The minimal components:
- A model that reads context and produces a decision (text or a tool call).
- A tool set the model can invoke (web search, code execution, database queries, APIs).
- A loop that feeds tool results back into the model's context until the task is complete or a limit is hit.
- Memory (optional but important) — short-term (in-context), long-term (external store), or episodic (past conversation summaries).
Everything else — multi-agent systems, orchestration frameworks, RAG pipelines — is built on this foundation.
Start with the raw SDK
Before picking a framework, build the tool loop directly in the Anthropic SDK or OpenAI SDK. Twenty lines of Python:
while not done:
response = client.messages.create(
model="claude-opus-4-7",
tools=tools,
messages=messages
)
if response.stop_reason == "tool_use":
result = call_tool(response.content)
messages.append({"role": "user", "content": result})
else:
done = True
Understanding this loop — what goes into context, how tool results propagate, how the model decides it's done — is prerequisite knowledge for using any framework effectively. Teams that skip this step spend weeks debugging framework behavior they don't understand.
The full agent stack
| Layer |
What it does |
Options |
| Model |
Generates text + tool calls |
Claude, GPT-4o, Gemini |
| Tools |
Actions the model can take |
Custom functions, MCP servers |
| Memory |
State across calls |
In-context, vector DB, Redis |
| Orchestration |
Controls the loop |
Raw SDK, LangGraph, CrewAI, Agno |
| Evals |
Measures correctness |
Custom harness, Braintrust, LangSmith |
Orchestration frameworks in 2026
| Framework |
Complexity |
Control |
Multi-agent |
Memory built-in |
Best for |
| Raw SDK |
Low |
Full |
Manual |
No |
Simple agents, learning |
| LangGraph |
Medium |
High |
Yes |
Yes |
Complex state machines |
| CrewAI |
Medium |
Medium |
Yes (native) |
Yes |
Role-based multi-agent |
| Agno |
Low |
High |
Limited |
Yes |
Lightweight, fast setup |
LangGraph is the choice for complex agents with conditional branching and human-in-the-loop pause points. The graph abstraction makes state explicit — worth the setup cost for production systems.
CrewAI excels at multi-agent role assignment: "researcher agent + writer agent + reviewer agent" workflows map naturally to its mental model.
Agno is the fastest path from idea to working agent for simpler tasks. Less ceremony, fewer concepts to learn.
Three agent patterns that work
ReAct loop — Reason, then Act, then Observe. The model thinks aloud before each tool call. Good for tasks where the path isn't fully predictable. Works well with most models out of the box.
Plan-and-execute — The model makes a full plan first, then executes each step. Better for tasks with many sub-steps where replanning is expensive. Trade-off: the plan can be wrong from step one.
Supervisor pattern — A coordinator agent delegates to specialized subagents. Good for tasks that decompose cleanly into specialist domains (research / analysis / writing). Higher latency, higher token cost, better results on complex tasks.
Three things you must have before shipping
Evals. Define what "correct" means before you ship. Even crude evals (does the agent complete the task without error on 20 representative inputs?) catch regressions. Braintrust and LangSmith both make this tractable.
Rate limits. Agents can loop. A budget/iteration cap (max_iterations=25) is the simplest safety measure and prevents runaway token spend.
A kill switch. A simple flag in a config store or database that stops the agent mid-loop. In production, you will want to stop a running agent without redeploying. Build this on day one.
Common mistakes to avoid
Reaching for an agent when a prompt works. If the task is "classify this text" or "extract these fields," structured output with a single prompt is faster, cheaper, and more reliable. Agents add real overhead.
No human-in-the-loop on destructive actions. Database modifications, emails, and payment actions should pause for human approval in production. See the best AI agent security tools for the pattern.
Building without tracing. When an agent produces a wrong output, you need to see every step — model input, tool call, tool result — to debug. Add tracing before you go to prod.
FAQ
How much does running an agent cost?
Highly variable. A simple 5-tool-call research task on Claude Opus costs ~$0.05–0.15. A multi-agent pipeline running dozens of calls can reach $1–5 per task. Measure early and set a per-task budget cap.
Should I build my own tools or use MCP servers?
For common integrations (web search, file system, code execution), use existing MCP servers. For business-specific logic, write custom tool functions. Don't abstract custom logic into a generic server unless it'll be reused.
How do I make an agent remember across sessions?
Summarize the session into a persistent store (Redis, Postgres, a vector DB) at the end of each conversation. Load the summary into context at the start of the next one. This is the most practical approach in 2026.
Where to go next
For more on agent infrastructure see best AI agent security tools in 2026, how to build an AI chatbot in 2026, and best AI agents in 2026.