Preface
- Who This Book Is For
- What You Will Build
- Testing Approach
- Code Examples
- Conventions Used in This Book
Part I: The Brain
Chapter 1: The Zero Magic Manifesto
- What is an Agent, Really?
- What We Are Building
- Project Setup
- The AgentStop Exception
- The Agent Class
- Defining Success with Tests
- The Main Loop
- Run It
- Wrapping Up
Chapter 2: The Raw Request
- Get an API Key
- The Vault (.env)
- The Anatomy of a Request
- The Code
- Run It
- Troubleshooting
- Cleaning Up
- Wrapping Up
Chapter 3: The Infinite Loop
- The Illusion of Memory
- The Testing Problem
- Response Types
- The FakeBrain Pattern
- Defining Success
- The Claude Class
- The Agent Class (Updated)
- The Main Loop (Updated)
- Verify the Tests Pass
- Test the Memory
- The Context Window Problem
- Wrapping Up
Chapter 4: The Universal Adapter
- The Adapter Pattern
- HTTP Resilience
- The Brain Interface
- The FakeBrain (Updated)
- The Claude Brain (Refactored)
- The DeepSeek Brain
- The BRAINS Registry
- The Agent Class (Updated)
- Tests for Multi-Brain Support
- The Main Loop (Updated)
- Setting Up DeepSeek
- Try It
- “We Just Moved Code Around”
- Wrapping Up
Part II: The Hands
Chapter 5: The Tool Protocol
- How Tools Actually Work
- Defining the Tool Interface
- The ReadFile Tool
- The WriteFile Tool
- Tool Helpers
- Updating the Thought Class
- Updating the Claude Class
- The Agent Class with Tools
- The Main Loop
- Test It
- Wrapping Up
Chapter 6: The Scratchpad (Memory)
- The “Zero Magic” Memory
- The Memory Class
- The ToolContext Class
- The SaveMemory Tool
- Updating the Claude Class
- Crafting the System Prompt
- Updating the Agent Class
- The Main Loop (Updated)
- Testing Persistence
- Wrapping Up
Chapter 7: The Safety Harness (Plan Mode)
- The Concept
- Tests First
- The WritePlan Tool
- One List, Two Views
- Telling the Brain What Mode It’s In
- The Agent Class (Updated)
- The Main Loop (Updated)
- Testing the Harness
- The Psychology of the “Plan”
- Wrapping Up
Chapter 8: The Context Pipeline (Map & Search)
- The ListFiles Tool
- The SearchCodebase Tool
- Update the Tools List
- The “Zoom In” Test
- Wait, is this RAG?
- Wrapping Up
Chapter 9: The Reality Check (Running Code)
- The Feedback Loop
- Tests First
- The RunCommand Tool
- The Interactive Trap
- The Self-Healing Demo
- The TDD Workflow
- The Surgical Edit
- The Closed Loop
- Hardening the Loop
- Context Compaction
- Security Considerations
- Wrapping Up
Part III: The Frontier
Chapter 10: Going Dark (Local Models)
- The Trade-off
- Installing Ollama
- The Ollama Brain Class
- Running with Ollama
- The “Infinite Loop” Experiment
- The Practical Differences
- The Hybrid Workflow
- Model Selection
- Troubleshooting Ollama
- Wrapping Up
Chapter 11: The Extension (Web Search)
- Step 1: The Meta-Prompt
- Step 2: The Surgery
- Step 3: The Reference Implementation
- Step 4: The Tests
- Self-Modification
- Wrapping Up
Chapter 12: The Capstone (Building a Game)
- Step 1: Preparation
- Step 2: The Architect (Plan Mode)
- Step 3: The Builder (Act Mode)
- Step 4: The Reality Check
- Step 5: The Pivot (Feature Creep)
- What Goes Wrong
- Wrapping Up
- Epilogue
Appendix A: Streaming Responses
- How Streaming Works
- The Implementation
- What Changed from Chapter 11
- The Trade-Off
- Running the Code