Build Your Own Coding Agent

Build Your Own Coding Agent

Owen Ou
This is a sample of the book's content.Buy on Leanpub

Table of Contents

Build Your Own Coding Agent

  • Preface
    • Who This Book Is For
    • What You Will Build
    • Testing Approach
    • Code Examples
    • Conventions Used in This Book
  • 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
    • Step 1: Get an API Key
    • Step 2: The Vault (.env)
    • Step 3: The Anatomy of a Request
    • Step 4: The Code
    • Step 5: 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
    • Why This Matters
    • Wrapping Up
  • 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
    • Why This is Powerful
    • Wrapping Up
  • Chapter 7: The Safety Harness (Planner Mode)
    • The Concept
    • Tests First
    • Extending ToolContext
    • The Guarded WriteFile Tool
    • 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?
    • The Architectural Significance
    • 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
    • Why This Changes Everything
    • Security Considerations
    • Wrapping Up
  • 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 Test
    • Why This Matters
    • 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)
    • The Result
    • Wrapping Up
    • Epilogue: The End of the Beginning
  • Acknowledgments
Build Your Own Coding Agent/Chapter 5: The Tool Protocol

Chapter 5: The Tool Protocol

https://leanpub.com/build-your-own-coding-agent

How Tools Actually Work

https://leanpub.com/build-your-own-coding-agent

Defining the Tool Interface

https://leanpub.com/build-your-own-coding-agent

The ReadFile Tool

https://leanpub.com/build-your-own-coding-agent

The WriteFile Tool

https://leanpub.com/build-your-own-coding-agent

Tool Helpers

https://leanpub.com/build-your-own-coding-agent

Updating the Thought Class

https://leanpub.com/build-your-own-coding-agent

Updating the Claude Class

https://leanpub.com/build-your-own-coding-agent

The Agent Class with Tools

https://leanpub.com/build-your-own-coding-agent

The Main Loop

https://leanpub.com/build-your-own-coding-agent

Test It

https://leanpub.com/build-your-own-coding-agent

Wrapping Up

https://leanpub.com/build-your-own-coding-agent

Up next

Chapter 6: The Scratchpad (Memory)

In this chapter

  • 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