Building Your Own Coding Agent
Build a code-editing agent from scratch in Python — an LLM, a loop, and three tools in a compact baseline implementation.
download courseware
Prefer to inspect a complete implementation? Download pre-completed courseware for this course.
- Pre-completed projectsign in to downloadA complete reference implementation of the coding agent in Python, Go, Ruby, Java, Rust, .NET, and Node.
Getting Started
Set up a Python project and define the types for talking to Claude.
-
- Explain the core components of a coding agent: loop, LLM, and tools
- Describe how coding agents differ from simple chat interfaces
- Identify the key design decisions when building an agent from scratch
-
- Set up a Python project with the required dependency for API access
- Define typed structures for the Anthropic Messages API request and response
- Implement HTTP client configuration for authenticated API calls
The Conversation Loop
Build a chat REPL and learn how stateless API calls become a continuous conversation.
-
- Build a read-eval-print loop that sends user input to Claude
- Parse and display assistant responses from the Messages API
- Handle basic input/output flow for an interactive conversation
-
- Explain how the messages list accumulates conversation history
- Distinguish between different content block types in API responses
- Handle multi-block responses correctly in the conversation loop
Adding Tools
Define tools, execute them, and watch the agent compose multi-step operations on its own.
-
- Define a tool using JSON Schema with name, description, and parameters
- Implement a read_file tool using Python's pathlib
- Observe how Claude requests tool execution through the API
-
- Detect tool_use content blocks in API responses
- Implement a dispatch loop that executes tools and returns results
- Define the loop termination condition when the model stops requesting tools
-
- Implement list_files and edit_file tools for filesystem operations
- Observe how the agent composes multi-step file operations autonomously
- Evaluate the trade-offs of different file editing strategies
Making It Real
Put the complete agent together, add error handling, and explore what comes next.
-
- Assemble all components into a complete working coding agent
- Trace end-to-end execution of multi-step coding tasks
- Identify how each component contributes to the agent's behavior
-
- Handle tool execution failures gracefully without crashing the agent
- Implement safeguards against infinite tool call loops
- Track and report token usage across agent interactions
-
- Evaluate extension points like system prompts and streaming for your agent
- Describe sandboxing strategies for safe tool execution
- Compare single-agent and multi-agent architecture trade-offs