AI Engineer1h 1m
Build a Coding Agent Harness From an Empty Loop — Tejas Kumar, IBM
Tutorial, Workshop
Speaker & Context
- Tejas (IBM AI R&D) presented a one-hour workshop on building a coding agent harness from first principles.
- IBM builds internal tools including the coding agent "Bob" and the "Granite" model family.
- The core objective is reducing token spend from ~$2B annually while building robust agents.
- The talk evolved from a 20-minute European version to a 3x longer deep-dive covering implementation details.
Core Components of a Harness
- The speaker reduced the traditional six harness components to three primary functional pillars:
- Tools: Necessary to extend model capabilities beyond language generation (e.g., file system access, bash execution).
- Context Primitives: Mechanisms to manage state, including auto-compaction, prompt caching, and truncation to control costs and prevent context loss.
- Guardrails: Safety layers to prevent agents from executing destructive actions or spiraling into infinite loops.
- The speaker reduced the traditional six harness components to three primary functional pillars:
Risks of Unharnessed Models
- Context Loss: Models forget information as context windows fill; the "Canary technique" (using a specific token) can detect when a model stops acknowledging prior context.
- Infinite Loops: Without guardrails, models may generate infinite tokens, leading to massive compute costs.
- Unauthorized Actions: Models may execute destructive commands (e.g.,
rm -rf) without user consent if not strictly tethered to reality. - Domain Specificity: Harnesses must be tailored to the domain (e.g., coding vs. computer use vs. fintech) with specific tools and rules.
Implementation Timeline & Code Evolution
- Phase 1: Basic Loop
- Initial implementation was a simple
while(true)loop reading user input and generating text via the Anthropic SDK. - Failed to retain state between sessions and lacked file system access.
- Initial implementation was a simple
- Phase 2: Adding Tools
- Introduced a
tools.tsfile defining functions likeread_fileandwrite_file. - Implemented an agent loop where the model calls a tool, the harness executes it, and the result is pushed back to the conversation history.
- Transitioned from a single tool to a scalable
toolsetusingarray.findto map tool names to execution functions.
- Introduced a
- Phase 3: Guardrails
- Implemented two types of guardrails:
- Usage Guardrails: Hard limits on steps (e.g., 25 steps/task) and token consumption (e.g., 300k tokens/task).
- Gates: Mandatory user permission required for dangerous tools (e.g.,
delete,rm).
- Guardrails prevent the agent from autonomously deleting files without confirmation.
- Implemented two types of guardrails:
- Phase 4: Context Management & Caching
- Introduced
context.tsto manage token efficiency. - Utilized Anthropic's
cache_control: ephemeralto cache historical prompts, reducing repeat processing costs. - Implemented auto-compaction logic triggered at 90,000 tokens to avoid the 5x pricing penalty associated with exceeding 100k input tokens.
- Demonstrated a 2x–3x cost reduction by comparing caching-enabled runs vs. non-cached runs.
- Introduced
- Phase 5: Sub-agents (Phases)
- Adopted a "phase" strategy to handle long-horizon tasks.
- Research indicated success rates for 120-step tasks rose from ~29% (single loop) to ~85% when broken into 10 distinct phases managed by sub-agents.
- Phase 6: Model Agnosticism
- Verified the harness works with offline models (IBM's "Granite" via Ollama) by swapping the API endpoint.
- Demonstrated that a custom harness allows seamless swapping between cloud APIs and local models.
- Phase 1: Basic Loop
Domain Adaptation
- The core harness logic (loop, caching, guardrails) remains constant across domains.
- Adaptation to new domains (e.g., "Computer Use" for web browsing) requires only replacing the Tool Registry and Guardrail Rules.
- Example: Swapped terminal tools for browser tools (
navigate,screenshot,click) to perform web searches.
Build vs. Buy Decision Matrix
- Build when:
- Tool registries contain unique business logic.
- Specific "gates" and approval flows are required for the business context.
- Sub-agent workflows must reflect specific domain processes.
- Budget constraints require custom token management strategies.
- Buy when:
- Need durable execution and infrastructure reliability (e.g., handling network partitions).
- Prefer managing risk with a provider one can sue (e.g., Anthropic's "Managed Agents" or platforms like Temporal/Ingest).
- The core loop itself is not a competitive differentiator.
- Build when:
Future Outlook
- Software Factories: Reliable harnesses will enable the automation of software production similar to industrial factories.
- Super Harnesses: The next evolutionary step involves a "super harness" capable of dynamically creating and selecting specialized sub-harnesses (e.g., merging code and general assistance) to achieve AGI.
- Evals: Emphasized the necessity of evaluation frameworks before deploying harnesses to ensure agent reliability.
Key Takeaways
- A well-built harness can achieve high-quality results using smaller, cheaper models (e.g., GPT-3.5 Turbo vs. Opus).
- Proactive context compaction is critical to avoiding exponential cost spikes.
- Agents must never act destructively without explicit user permission.
- Developers should not settle as mere users of existing tools but can build their own domain-specific harnesses.