Build a coding-agent harness
Build every layer around a coding agent: loop contract, schema-checked tools, JSON-RPC, dispatcher, replanner, gates, sandbox, evals and traces, then prove it by fixing a bug in a repo you wrote.
Build it step by step
- 1Agent Harness Loop ContractPhase 19: Capstone projects
- 2Tool Registry with Schema ValidationPhase 19: Capstone projects
- 3JSON-RPC 2.0 Over Newline-Delimited StdioPhase 19: Capstone projects
- 4Function Call DispatcherPhase 19: Capstone projects
- 5Plan-Execute Control FlowPhase 19: Capstone projects
- 6Capstone Lesson 25: Verification Gates and the Observation BudgetPhase 19: Capstone projects
- 7Capstone Lesson 26: Sandbox Runner with Denylist and Path JailPhase 19: Capstone projects
- 8Capstone Lesson 27: Eval Harness with Fixture TasksPhase 19: Capstone projects
- 9Capstone Lesson 28: Observability with OTel GenAI Spans and Prometheus MetricsPhase 19: Capstone projects
- 10Capstone Lesson 29: End-to-End Coding Agent on the HarnessPhase 19: Capstone projects
What You'll Build
A stdlib Python agent harness built layer by layer, exactly as the track does it: a deterministic loop state machine, a tool registry with JSON Schema validation, a JSON-RPC 2.0 stdio transport, a dispatcher with timeouts and retries, a plan-execute replanner, a verification gate chain with an observation budget, a sandbox runner, a fixture eval harness and OTel-style telemetry. The finished harness drives a coding policy that reads a small multi-file repo, runs its tests, finds the bug, writes the fix and stops. The fixture repo and its bug are yours, not the lesson's fizz.py.
Requirements
- Loop contract. A
HarnessLoopwith the six states (IDLE, PLANNING, EXECUTING, AWAITINGTOOL, REFLECTING, DONE), the ten hook topics, the eleven typed event types and a budget envelope (turns, tool calls, wall clock) that yields to the caller instead of killing the session. All state changes go through one `transition` function. - Tool registry. Register tools with name, description, schema, handler,
idempotentandtimeout_ms. Validate the eight-keyword JSON Schema subset (type, properties, required, enum, minLength, maxLength, pattern, items) and return json-pointer error paths such as/user/email. Re-registration withoutoverride=Trueis rejected. - Transport. JSON-RPC 2.0 over newline-delimited stdio with the five standard error codes, no response to notifications, batch support, and a broken JSON line that returns -32700 with
id: nulland does not stop the stream. - Dispatcher. Per-call timeout, exponential backoff with jitter (max 3 attempts) only for timeout or transient errors on idempotent tools, idempotency-key dedupe (two concurrent calls with the same key run the handler once), a semaphore concurrency limit, and one
DispatchErrorenvelope withkind,attemptsandjsonrpc_code. - Plan-execute. Typed
Steprecords, replan from the cursor with the last error in context, aplan.diffevent (removed, added, revised) on each revision, and hardmax_stepsandmax_replansbudgets. - Gates and sandbox. A short-circuiting chain of WhitelistGate, RegexGate, RecencyGate and BudgetGate backed by an
ObservationLedger. ASandboxthat refuses denylisted executables, interpreter-c/-ecalls and shell metacharacters, jails paths withos.path.realpath, truncates oversized output and kills on timeout, returning a structuredSandboxResult. - Evals and telemetry. An eval harness with
file_equals,regex_matchandshell_exit_zeroverifiers that reports pass@1, pass@k, mean and p95 latency as JSON over at least 5 fixture tasks you wrote yourself. Spans with GenAI attributes (gen_ai.operation.name,gen_ai.tool.name, usage tokens) written one per line totraces.jsonl, plus Prometheus text with atools_called_totalcounter and atool_latency_mshistogram. - End-to-end demo.
python main.pyruns the coding policy on your fixture repo through every layer and asserts the five lesson 29 invariants: solved in fewer than 12 steps, observation budget never exceeded, zero gate denials on legal tools, one span per step intraces.jsonl, and atools_called_total{tool="read_file"}line plus atool_latency_mshistogram in the exposition. It exits 0. - Adversarial run. A second script sends at least three hostile tool calls (for example
rm -rf, a../path escape,python3 -c ...) and shows each refused with its reason, recorded in the trace. - Tests. A pytest suite covering state transitions, schema error paths, JSON-RPC error codes, retry and dedupe, replan exhaustion, gate short-circuit and every sandbox refusal axis. All pass.
Constraints
- Python 3.10+ standard library only; pytest for tests. Runs on any laptop CPU in seconds. No GPU, no network.
- No API key is needed: the graded policy is deterministic, as in lesson 29. If you want an LLM policy, plug it in at the same policy seam through any OpenAI-compatible endpoint (the KatalockAi API, or a local model via Ollama or llama.cpp), but the deterministic run is what gets graded.
- The sandbox is a development guardrail, not an OS security boundary. Run the adversarial script only inside a throwaway temp directory.
Stretch Goals
- Swap the deterministic policy for an LLM policy and report its pass@1 and pass@k on your fixture tasks.
- Add a circuit breaker to the dispatcher (
kind="circuit_open") and a per-tool observation budget gate. - Add
$refandadditionalProperties: falseto the schema validator.
How to Submit
Public GitHub repo with main.py, adversarial.py, a harness/ package (one module per layer: loop, registry, transport, dispatcher, planner, gates, sandbox, evals, telemetry), fixtures/ (your buggy repo and eval tasks), tests/ and results/ (eval report JSON, a sample of traces.jsonl, the Prometheus text). The README must give the exact run commands, a short diagram or table of how a tool call flows through the layers, one design decision per layer, what the sandbox does not protect against, and a 3 to 5 sentence reflection on a bug you hit when composing the layers. Paste the outputs listed under evidence.
How It's Reviewed
Professor Katalock reads your repository and the evidence you paste, and scores each criterion out of 100. You pass with a weighted total of 70 or more and no criterion below 40. A copied or padded submission is flagged and fails.
Submit
Push your work to a public GitHub repository with a README that explains how to run it, then paste the evidence below. Up to 3 reviews a day, free.
- Full terminal output of `python main.py`, including the step trace and the five invariant checks
- Output of `python -m pytest -q`
- Output of `python adversarial.py` showing each refused call and its reason
- The eval report JSON from results/ and the first 3 lines of traces.jsonl
- The Prometheus exposition text printed at the end of the demo
- A 3 to 5 sentence reflection on one integration bug and how you fixed it
Reviews are done by AI against the rubric above. They check the evidence in your repository; they are not a substitute for a human code review, and a review can be wrong. If you think it is, improve the README so the evidence is unmistakable and resubmit.