Agent Setup: Your First Agent
iAs of: September 2026
Model names and prices in the code examples reflect the state as of September 2026. Anthropic releases new models roughly quarterly — check the official docs for current model IDs.
Knowledge
At its core, an agent consists of three building blocks: a system prompt that defines its behavior, a model that does the thinking, and tools that give it capabilities. In this section, you'll build all three.
The System Prompt -- Your Agent's DNA
The system prompt is the most important decision in agent development. It determines how your agent behaves, what role it takes on, and what boundaries it respects. A good agent system prompt is fundamentally different from a simple chatbot prompt.
The five elements of an agent system prompt:
- Role: Who is the agent? ("You are a code review assistant for Python projects.")
- Capabilities: What can it do? ("You can read files, analyze code, and suggest improvements.")
- Constraints: What must it not do? ("You never modify code directly. You only suggest changes.")
- Output format: How does it respond? ("Always respond with a list of findings, sorted by severity.")
- Reasoning instruction: How does it think? ("Analyze the code step by step. Check structure first, then logic, then style.")
Model Selection -- Which LLM for Which Agent?
Not every model is suited for every agent. The choice depends on three factors:
| Factor | Small Model (GPT-5 mini, Claude Haiku 4.5) | Large Model (GPT-5.6, Claude Sonnet 5 / Opus 5) |
|---|---|---|
| Cost | GPT-5 mini: ~$0.25/M input, Claude Haiku 4.5: $1/M input | $3-5/M input tokens (Sonnet/Opus, GPT-5.6) |
| Speed | Very fast (< 1s) | Slower (2-5s) |
| Reasoning | Simple tasks | Complex analysis |
| Tool Use | Reliable | Very reliable |
Rule of thumb: Start with a small model. If the quality isn't sufficient, switch to a larger one. Most agents perform better with Sonnet 5 or GPT-5 mini than you'd expect.
Understand
The First Tool Definition
Tools give your agent capabilities beyond text. A tool is a function that the agent can call -- with a clear description so the LLM knows when and how to use it.
Python example with the Anthropic SDK:
import anthropic
client = anthropic.Anthropic()
# Tool definition: The agent can read files
tools = [
{
"name": "read_file",
"description": "Reads the contents of a file. Use this tool "
"when you need to analyze the code or content of a file.",
"input_schema": {
"type": "object",
"properties": {
"file_path": {
"type": "string",
"description": "The path to the file, e.g. 'src/main.py'"
}
},
"required": ["file_path"]
}
}
]
# Start agent with system prompt and tool
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
system="You are a code review assistant. Analyze code "
"step by step and provide concrete improvements.",
tools=tools,
messages=[
{"role": "user", "content": "Review the file src/main.py"}
]
)
TypeScript example with the Anthropic SDK:
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
// Tool definition
const tools: Anthropic.Tool[] = [
{
name: "read_file",
description:
"Reads the contents of a file. Use this tool " +
"when you need to analyze the code or content of a file.",
input_schema: {
type: "object" as const,
properties: {
file_path: {
type: "string",
description: "The path to the file, e.g. 'src/main.py'",
},
},
required: ["file_path"],
},
},
];
// Start agent
const response = await client.messages.create({
model: "claude-sonnet-5",
max_tokens: 1024,
system:
"You are a code review assistant. Analyze code " +
"step by step and provide concrete improvements.",
tools,
messages: [
{ role: "user", content: "Review the file src/main.py" },
],
});
Note: The description in the tool is critical. The LLM decides based on this description when to use the tool. A vague description leads to incorrect or missing tool usage.
Apply
Complete the tool definition for a tool that performs a web search:
Reflect
Why should you start with a small model when choosing a model for an agent?