Loading...
Loading...

Everyone's talking about AI agents. Most tutorials are toy examples. Here's how to build production-ready agents with tool use, memory, and real decision-making.
Let me clear this up right away: an AI agent is NOT a chatbot with extra steps. A chatbot responds to questions. An agent takes actions, makes decisions, and uses tools to accomplish goals autonomously.
Think of the difference like this:
| Chatbot | Agent |
|---|---|
| Answers questions | Completes tasks |
| Stateless (mostly) | Maintains memory across steps |
| Single response | Multi-step workflow |
| Human drives every step | AI decides next action |
| "What is X?" | "Do X for me" |
I've built several production agents this year β from code review bots to content automation pipelines. Here's what actually works.
Every useful agent has these four components:
βββββββββββββββ
β LLM Brain β β Reasoning engine (Claude, GPT, etc.)
ββββββββ¬βββββββ
β
ββββββββ΄βββββββ
β Tools β β Actions the agent can take
ββββββββ¬βββββββ
β
ββββββββ΄βββββββ
β Memory β β Context from previous steps
ββββββββ¬βββββββ
β
ββββββββ΄βββββββ
β Orchestratorβ β Loop: Think β Act β Observe β Repeat
βββββββββββββββwhile (!taskComplete) {
// 1. Think: What should I do next?
const thought = await llm.reason(memory, tools, goal);
// 2. Act: Use a tool
const result = await executeTool(thought.selectedTool, thought.params);
// 3. Observe: What happened?
memory.add({ action: thought, result });
// 4. Check: Am I done?
taskComplete = await llm.evaluate(memory, goal);
}That's it. Every agent framework β LangChain, CrewAI, Anthropic's Agent SDK β is some variation of this loop.
Here's a real, working agent using the Anthropic SDK:
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
// Define tools the agent can use
const tools = [
{
name: "read_file",
description: "Read the contents of a file",
input_schema: {
type: "object",
properties: {
path: { type: "string", description: "File path to read" }
},
required: ["path"]
}
},
{
name: "search_code",
description: "Search for a pattern in the codebase",
input_schema: {
type: "object",
properties: {
query: { type: "string", description: "Search query" }
},
required: ["query"]
}
},
{
name: "write_file",
description: "Write content to a file",
input_schema: {
type: "object",
properties: {
path: { type: "string" },
content: { type: "string" }
},
required: ["path", "content"]
}
}
];
// The agent loop
async function runAgent(task: string) {
const messages = [{ role: "user", content: task }];
while (true) {
const response = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 4096,
tools,
messages,
});
// Check if agent is done
if (response.stop_reason === "end_turn") {
return response.content;
}
// Execute tool calls
if (response.stop_reason === "tool_use") {
const toolResults = [];
for (const block of response.content) {
if (block.type === "tool_use") {
const result = await executeTool(block.name, block.input);
toolResults.push({
type: "tool_result",
tool_use_id: block.id,
content: result,
});
}
}
messages.push({ role: "assistant", content: response.content });
messages.push({ role: "user", content: toolResults });
}
}
}This is a real, working agent pattern. Claude decides which tools to use, executes them, observes results, and continues until the task is complete.
Give one agent one job. Don't try to build a Swiss Army knife.
| Agent | Tools | Job |
|---|---|---|
| Code Reviewer | read_file, search_code, comment_pr | Reviews PRs |
| Blog Writer | search_web, write_file, publish_sanity | Creates blog posts |
| Bug Fixer | read_file, run_tests, write_file | Fixes failing tests |
| Researcher | search_web, summarize, save_notes | Gathers information |
One "manager" agent coordinates multiple specialist agents:
Orchestrator: "I need to fix bug #123"
β Spawns Research Agent: "Find the root cause"
β Spawns Fix Agent: "Write the patch"
β Spawns Test Agent: "Verify the fix works"
β Orchestrator: "All passed, creating PR"This is how Claude Code's /batch command works internally β one orchestrator, many parallel workers.
// Before executing any tool
async function safeExecute(tool: string, params: any) {
// Allowlist of permitted actions
const allowed = ["read_file", "search_code", "list_files"];
// Dangerous actions need confirmation
const needsApproval = ["write_file", "delete_file", "run_command"];
if (needsApproval.includes(tool)) {
const approved = await askHumanApproval(tool, params);
if (!approved) return "Action denied by user";
}
return executeTool(tool, params);
}π₯ Never let an agent run unrestricted. Always have a human approval step for destructive actions.
Agents without memory are useless for multi-step tasks. Here are the three types:
| Memory Type | What It Stores | Lifetime |
|---|---|---|
| Short-term | Current conversation/task context | This session |
| Working | Intermediate results, decisions made | This task |
| Long-term | User preferences, learned patterns | Persistent |
class AgentMemory {
shortTerm: Message[] = []; // Conversation history
working: Map<string, any> = new Map(); // Current task state
longTerm: VectorStore; // Persistent knowledge
async recall(query: string) {
// Search long-term memory for relevant context
const memories = await this.longTerm.search(query, { limit: 5 });
return memories;
}
async remember(fact: string) {
// Store important information for future sessions
await this.longTerm.add(fact);
}
}| Pitfall | What Happens | How to Avoid |
|---|---|---|
| Infinite loops | Agent keeps trying the same failed approach | Max iteration limit + loop detection |
| Token explosion | Memory grows until context is full | Summarize/compact after N steps |
| Tool hallucination | Agent calls tools that don't exist | Strict tool validation |
| Goal drift | Agent forgets the original task mid-way | Re-inject goal every N steps |
| Overly autonomous | Agent makes destructive decisions | Human-in-the-loop for risky actions |
| Use Simple Prompt | Use Agent |
|---|---|
| One-shot questions | Multi-step tasks |
| Known input β output | Dynamic decision-making |
| No tools needed | Needs to call APIs/read files |
| Predictable workflow | Uncertain paths |
| Speed matters most | Accuracy matters most |
Don't use agents for everything. A simple API call to Claude with a good prompt is faster, cheaper, and more reliable for most tasks. Reserve agents for genuinely complex, multi-step work.
The agent ecosystem is exploding. Here's what's exciting:
We're in the early days. The developers who learn to build agents now will have a massive advantage in 2-3 years when this becomes mainstream.
Start small. Build a single-purpose agent. Make it reliable. Then expand. π
It's the most capable coding model I've used. It's also relentlessly proactive in ways that made me nervous about running it unsandboxed. A week of real usage, real costs, and one genuinely surprising outcome.
Dynamic Workflows is the most ambitious feature in Opus 4.8 β Claude writes its own orchestration script, spins up hundreds of parallel agents, has them adversarially verify each other, and returns only converged results. Here's how it actually works.
Fable 5 is more than double Opus 4.8 on the hardest coding benchmarks. It's also 5x the output cost and comes with an export-control history. Here's how I actually decide which one gets the API key.