AI Agents in Production: Lessons From Building Real Automation
Building AI agents that actually work in production is different from demo-land. Here's what I've learned deploying agents that run 24/7.
What 'Agent' Actually Means
An agent is a loop: observe → think → act → observe. The key properties:
- Can take actions (call APIs, write files, send messages)
- Observes results of those actions
- Adapts based on what it sees
- Has a goal, not just a prompt
The Minimal Viable Agent Pattern
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
const tools = [
{
name: 'search_web',
description: 'Search the web for current information',
input_schema: {
type: 'object' as const,
properties: { query: { type: 'string', description: 'Search query' } },
required: ['query'],
},
},
{
name: 'write_file',
description: 'Write content to a file',
input_schema: {
type: 'object' as const,
properties: {
path: { type: 'string' },
content: { type: 'string' },
},
required: ['path', 'content'],
},
},
];
async function runAgent(goal: string, maxSteps = 10) {
const messages: Anthropic.MessageParam[] = [
{ role: 'user', content: goal }
];
for (let step = 0; step < maxSteps; step++) {
const response = await client.messages.create({
model: 'claude-sonnet-4-6',
max_tokens: 4096,
tools,
messages,
});
if (response.stop_reason === 'end_turn') break;
if (response.stop_reason === 'tool_use') {
const toolResults: Anthropic.ToolResultBlockParam[] = [];
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: JSON.stringify(result),
});
}
}
messages.push({ role: 'assistant', content: response.content });
messages.push({ role: 'user', content: toolResults });
}
}
return messages;
}
Production Lessons
1. Always set max steps. Agents can loop. Budget your API calls.
2. Log every tool call. When things go wrong, you need a trace.
3. Make tools idempotent. Agents retry. Your tools should handle that.
4. Validate tool outputs. Don't trust that the agent's tool call will return what you expect.
5. Human-in-the-loop for high-stakes actions. Before deleting data, sending emails to thousands of users, or spending money — confirm.
MCP: The Right Tool Interface
Model Context Protocol standardizes how agents discover and call tools. Instead of hardcoding tool schemas, MCP servers expose them dynamically.
The Workflow Automator MCP gives your agents pre-built tools for the most common automation workflows — web scraping, email sending, data transformation, and API calls — without building each tool from scratch.
Top comments (0)