Building an AI agent prototype is straightforward. Making it reliable in production is not. Rate limits must be retried with backoff. Context windows fill up and must be pruned carefully. Tool calls need permission checks before execution. Financial operations need a human to confirm before money moves. Failures mid-task need to checkpoint so work is not lost. Usage costs need to be tracked per session with hard limits.
Harness Template Library solves all of that. It is a production-grade open-source library of 10 AI agent harness templates, each a complete, runnable Python package that wires together 15 battle-tested infrastructure modules. Ready to deploy on day one. Built autonomously using NEO.

What This Library Does
The 15 core modules handle every infrastructure concern an agent needs in production: context management, memory, tool permissions, budget tracking, observability, state persistence, human approval, and more. The 10 templates provide domain-specific tools, system prompts, and workflow configurations on top of that shared infrastructure. Every template runs with claude-sonnet-4-20250514 out of the box.
The split is deliberate. The 15 infrastructure modules are written once and shared. Each template only provides its domain-specific tools, system prompt, and configuration. Improvements to any core module benefit all 10 templates instantly.
Architecture
The 15 core modules all live in core/. Each template's harness.py instantiates and wires them together with domain-specific configuration. The templates differ in their tools, system prompts, workflow steps, and permission policies, not in their infrastructure.
Prerequisites
- Python 3.11 or newer
- An Anthropic API key:
export ANTHROPIC_API_KEY=sk-ant-your-key-here
Getting Started
Install
cd projects/harness-template-library
pip install -e ".[dev]"
This installs the library and registers all 10 CLI entry points. Set your API key:
export ANTHROPIC_API_KEY=sk-ant-your-key-here
Run a Template via CLI
Each template registers its own CLI command. For example, the coding agent:
coding-agent "Write a Python function that checks if a string is a palindrome"
Or the research agent:
research-agent "Summarize the key architectural differences between GPT-4 and Claude"
All 10 CLIs work the same way: pass a task or query as the first argument, and the agent runs it using the full 15-module infrastructure stack.
Run an Example Script
python -m examples.run_coding_agent
python -m examples.run_research_agent
Run Tests
python -m pytest tests/ -v
78 tests across all 15 core modules. Runs in under 5 seconds.
The 15 Core Modules
All 15 modules live in core/ and are real, working Python classes with no stubs and no placeholders.
InstructionManager: Loads system prompts from file or env, supports {variable} interpolation.
ContextBuilder: Assembles the messages array, enforces token budget with intelligent truncation.
MemoryLayer: SQLite-backed persistent memory with keyword search across past sessions.
ModelAdapter: Wraps AsyncAnthropic, uses claude-sonnet-4-20250514, retries on rate limits with exponential backoff.
ToolRegistry: Register tools by name with their JSON schema and Python handler function.
PermissionResolver: Checks tool calls against an allowlist policy before execution; supports wildcards.
BudgetManager: Tracks token usage and cost per session; raises BudgetExceededError at hard limit.
WorkflowEngine: Runs a sequence of named steps with conditional branching based on step results.
StateManager: Serializes and restores full agent state to SQLite, for resuming interrupted tasks.
HumanApprovalLayer: Pauses on sensitive or financial tools and prompts the operator for confirmation.
ObservabilityLayer: Emits structured logs via structlog and OTEL spans for every tool and model call.
EvaluationFramework: Scores agent output against a rubric using a second Claude call.
RetryRecoverySystem: Exponential backoff wrapper that saves partial results to disk before re-raising.
AuditLogger: Append-only SQLite log of every action, decision, and tool call, non-repudiable.
DeploymentConfig: Generates Dockerfiles and docker-compose.yml programmatically for any template.
The 10 Templates
Each template is in templates/<name>/ with harness.py, tools.py, config.py, system_prompt.txt, Dockerfile, docker-compose.yml, and tests/test_harness.py.
Coding Agent: Reads and writes files, runs tests, diffs git changes, and searches code. Workflow: understand task, write code, run tests, fix failures, commit. System prompt: expert software engineer with TDD focus.
Research Agent: Handles web search, URL reading, note saving, and citation management, with web and URL tools currently implemented as stubs. Workflow: decompose question, search, synthesize, verify claims, write report. System prompt: rigorous researcher with citation requirements.
Customer Support: Handles ticket lookup, update, escalation, and knowledge base search, with email sending currently implemented as a stub. Workflow: understand issue, check KB, resolve or escalate, update ticket. System prompt: empathetic support agent with escalation rules.
Data Engineering: Handles SQLite queries, schema reading, data validation, and pipeline execution. Workflow: understand data need, query, validate, transform, output. System prompt: data engineer focused on data quality and lineage.
Browser Automation: Handles navigation, clicking, text extraction, screenshots, and form filling, with all browser tools currently implemented as stubs awaiting browser integration. Workflow: understand goal, plan steps, execute, verify, report. System prompt: precise automation agent that validates each step.
Multi-Agent Orchestrator: Spawns and coordinates subagents, sends messages, collects results, and merges outputs. Workflow: decompose task, assign to subagents, collect results, synthesize. System prompt: orchestrator that breaks complex tasks into parallel workstreams.
RAG Agent: Embeds queries, runs cosine similarity search over an in-memory vector store, reranks results, and cites passages. Workflow: query, retrieve, rerank, generate answer with citations. System prompt: knowledge retrieval agent that only answers from provided context.
Finance Operations: Handles balance checks, invoice creation, and payment processing, with all financial tools currently implemented as stubs, plus a full audit trail. HumanApprovalLayer is always required before any financial tool executes. Workflow: validate request, check permissions, execute with approval, audit. System prompt: finance agent with mandatory human approval for all transactions.
Document Analysis: Handles text extraction, document classification, entity extraction, summarization, and document comparison. Workflow: ingest, classify, extract, analyze, report. System prompt: document analyst focused on structured information extraction.
Long-Horizon Task: Handles checkpointing, checkpoint restoration, todo list management, and progress tracking. Workflow: plan, checkpoint, execute step, checkpoint, repeat. System prompt: methodical agent that checkpoints frequently and resumes gracefully.
Project Structure
harness-template-library/
├── pyproject.toml # Package + 10 CLI entry points
├── core/
│ ├── __init__.py
│ ├── instruction_manager.py
│ ├── context_builder.py
│ ├── memory_layer.py
│ ├── model_adapter.py # claude-sonnet-4-20250514 default
│ ├── tool_registry.py
│ ├── permission_resolver.py
│ ├── budget_manager.py # raises BudgetExceededError
│ ├── workflow_engine.py
│ ├── state_manager.py
│ ├── human_approval_layer.py
│ ├── observability_layer.py
│ ├── evaluation_framework.py
│ ├── retry_recovery_system.py
│ ├── audit_logger.py
│ └── deployment_config.py
├── templates/
│ ├── coding_agent/
│ │ ├── harness.py # Wires all 15 core modules
│ │ ├── tools.py # read_file, write_file, run_tests, git_diff, search_code
│ │ ├── config.py
│ │ ├── system_prompt.txt
│ │ ├── Dockerfile
│ │ ├── docker-compose.yml
│ │ └── tests/test_harness.py
│ ├── research_agent/ # Same structure, different tools + prompt
│ ├── customer_support/
│ ├── data_engineering/
│ ├── browser_automation/
│ ├── multi_agent_orchestrator/
│ ├── rag_agent/
│ ├── finance_operations/
│ ├── document_analysis/
│ └── long_horizon_task/
├── harness_template_library/
│ └── cli/
│ ├── coding_agent_cli.py # click CLI → CodingAgentHarness
│ ├── research_agent_cli.py
│ └── ... # 8 more CLI modules
├── examples/
│ ├── run_coding_agent.py
│ └── run_research_agent.py
└── tests/
├── conftest.py # Fixtures: mock Anthropic, temp SQLite, sample config
└── test_core_modules.py # 75 tests covering all 15 core modules
Key Design Decisions
Shared core, specialized templates.
All 15 infrastructure modules are written once and shared. Each template only provides its domain-specific tools, system prompt, and configuration. Improvements to, say, the RetryRecoverySystem benefit all 10 templates instantly.
SQLite everywhere.
Memory, state persistence, and audit logs all use SQLite via aiosqlite. No external services are required to run any template. This makes the library work in air-gapped environments, local development, and ephemeral CI environments without any setup.
HumanApprovalLayer as a hard gate.
The PermissionResolver checks allowlists before a tool runs, but HumanApprovalLayer is a separate, upstream gate that can be configured per-tool. For the finance template, every payment-related tool requires approval regardless of the permission policy. The two layers are deliberately separate so the audit log shows both the policy check and the human decision.
BudgetExceededError is synchronous.
Even though the rest of the library is async, BudgetManager.check_budget() raises BudgetExceededError synchronously. This keeps budget enforcement simple: any caller that does not catch it will propagate up, ensuring no tool call or model call can exceed the limit by accident.
EvaluationFramework uses a second Claude call.
Agent output scoring runs a separate Anthropic API call with a rubric-based prompt. This adds latency and cost, so it is opt-in per template rather than always-on. The coding agent uses it to score whether generated code is idiomatic and well-tested.
Configuration
Each template reads its configuration from environment variables using pydantic-settings. Create a .env file in the project root:
ANTHROPIC_API_KEY=sk-ant-your-key-here
MODEL=claude-sonnet-4-20250514
MAX_TOKENS=4096
BUDGET_LIMIT_USD=1.00
LOG_LEVEL=INFO
All config values have sensible defaults. Only ANTHROPIC_API_KEY is required to run.
Docker Deployment
Each template includes a Dockerfile and docker-compose.yml. To run the coding agent in Docker:
cd templates/coding_agent
docker compose up --build
Or generate a custom deployment config programmatically:
from core.deployment_config import DeploymentConfig
dc = DeploymentConfig(service_name="my-coding-agent")
dockerfile = dc.generate_dockerfile()
compose = dc.generate_compose()
Environment Variables
Verified Results
The library ships with 78 tests across all 15 core modules including BudgetManager, WorkflowEngine, HumanApprovalLayer, RetryRecoverySystem, ObservabilityLayer, and the rest. The package installs cleanly with pip install -e . and all public classes import without errors. Tests run in under 5 seconds.
AI template generation (DeepSeek V4 Flash via OpenRouter): The ModelAdapter auto-detects the OpenRouter key and routes calls through DeepSeek's 1M-context reasoning model at the correct endpoint. When asked to generate a retry decorator with exponential backoff for async Python functions, it returned a complete, production-ready implementation in 311 output tokens: a parameterized retry_async decorator accepting max_retries, base_delay, max_delay, and a tuple of exception types, with backoff capped at max_delay and the original function signature preserved via functools.wraps. The adapter handles DeepSeek thinking blocks transparently, returning only the final text content. Total cost at $0.10/M input tokens was under $0.001.
How I Built This Using NEO
This project was built using NEO. NEO is a fully autonomous AI engineering agent that can write code and build solutions for AI/ML tasks including AI model evals, prompt optimization and end to end AI pipeline development.
The requirement was a library of production-grade agent harness templates that wire together all the infrastructure concerns a real agent needs, so teams could skip the boilerplate and start from a complete, working architecture. NEO planned and produced the files in this repository: 15 core infrastructure modules, 10 complete agent templates each with its own harness, tools, configuration, system prompt, Docker setup, and test suite, 10 CLI entry points, two example scripts, and the full test suite with fixtures and module coverage. The result is a fully working library where picking a template and running one CLI command gives a complete, production-grade agent with all 15 infrastructure concerns pre-wired and no boilerplate left to write.
How You Can Use This With NEO
Pick a template and run a production-ready agent immediately.
All 10 templates register their own CLI entry points on install. Passing a task to coding-agent, research-agent, or any of the other eight commands runs the full 15-module infrastructure stack without writing any code.
Use the 15 core modules in your own agent.
Every module is a real, importable Python class. Any agent codebase can pull in ContextBuilder, BudgetManager, HumanApprovalLayer, or any other module independently and wire them into an existing architecture.
Deploy any template to Docker in one command.
Every template ships with a Dockerfile and docker-compose.yml. Running docker compose up --build inside any template directory produces a containerized, ready-to-run agent with no additional configuration beyond the API key.
Run the library in air-gapped or local environments.
Memory, state persistence, and audit logs all use SQLite via aiosqlite. No external services are required. The library runs in CI, local development, or any environment where installing dependencies from a remote service is not possible.
Final Notes
Most agent projects rebuild the same infrastructure from scratch every time: retry logic, context pruning, permission checks, budget limits, audit trails. This library solves that once across 10 use cases. Pick the template that matches the job, or take the 15 core modules and wire them into whatever architecture is already in place.
The code is at https://github.com/dakshjain-1616/Harness-Template-Library
You can also build with NEO in your IDE using the VS Code extension or Cursor.
You can use NEO MCP with Claude Code: https://heyneo.com/claude-code

Top comments (0)