How optimalone/build-your-own-coding-agent works
Nanocode is a terminal-based AI coding agent, presented as a sequence of runnable chapter snapshots rather than a single modular application. In the capstone workflow, a user submits a request, the agent consults a model, invokes tools as needed, and returns results while retaining conversation and persistent context. Documented capabilities include file editing, command execution, codebase search, safety modes, multiple model providers, and web search. The sampled code shows provider and agent behavior; several tool details are documented in the README but not present in the excerpts.
Main entry points: nanocode.py Agent
Components 18
Agent interaction
- Terminal loop
ch12/nanocode.py - Agent
ch12/nanocode.py - Conversation state
ch12/nanocode.py
Model providers
- Brain selection
ch12/nanocode.py - Claude API
ch12/nanocode.py - DeepSeek API
ch12/nanocode.py - Ollama API
ch12/nanocode.py
Coding capabilities
- File tools
ch12/nanocode.py - Shell execution
ch12/nanocode.py - Codebase search
ch12/nanocode.py - Web search
ch12/nanocode.py
Context and memory
- Persistent memory
ch12/nanocode.py - Plan and act modes
ch12/nanocode.py
Other components
- Terminal user
- Model services
- DuckDuckGo
- Project files
- Operating system
Connections 21
- Terminal user → Terminal loop: enters request
- Terminal loop → Agent: passes input
- Agent → Conversation state: updates history
- Agent → Brain selection: requests response
- Brain selection → Claude API: selects provider
- Brain selection → DeepSeek API: selects provider
- Brain selection → Ollama API: selects provider
- Claude API → Model services: sends request
- DeepSeek API → Model services: sends request
- Ollama API → Model services: sends request
- Brain selection → Agent: returns thought
- Agent → File tools: dispatches tool
- Agent → Shell execution: dispatches tool
- Agent → Codebase search: dispatches tool
- Agent → Web search: dispatches tool
- File tools → Project files: reads and writes
- Codebase search → Project files: searches files
- Shell execution → Operating system: runs command
- Web search → DuckDuckGo: searches web
- Agent → Persistent memory: uses context
- Agent → Plan and act modes: checks mode