What a harness is — the four layers under every coding agent — step 8 of 9
Write mini_harness(user_input, tools, fake_model, max_iters)
that implements the four layers in under 50 lines:
- Layer 1: build
messages = [{"role": "user", "content": user_input}]. - Loop up to
max_iterstimes:- Layer 2: call
fake_model(messages)(returns a dict withstop_reasonandcontent). - Layer 3: filter
contentfor text blocks (type=="text") and tool_use blocks (type=="tool_use"). - If
stop_reason == "end_turn": return{"text": <text joined with " ">, "iters": <iter count>, "tool_calls": <total tool runs across all iters>}. - Layer 4: for each tool_use block, dispatch
tools[block["name"]](**block["input"]). Track total tool runs. Append assistant + user(tool_results) turns.
- Layer 2: call
- On cap: return
{"text": "capped", "iters": max_iters, "tool_calls": <count>}.
Two cases run for you. Expected output:
text='Tokyo guide.' iters=2 tool_calls=1
text='capped' iters=2 tool_calls=2
⌘↵ runs the editor.read, then continue.
Write mini_harness(user_input, tools, fake_model, max_iters)
that implements the four layers in under 50 lines:
- Layer 1: build
messages = [{"role": "user", "content": user_input}]. - Loop up to
max_iterstimes:- Layer 2: call
fake_model(messages)(returns a dict withstop_reasonandcontent). - Layer 3: filter
contentfor text blocks (type=="text") and tool_use blocks (type=="tool_use"). - If
stop_reason == "end_turn": return{"text": <text joined with " ">, "iters": <iter count>, "tool_calls": <total tool runs across all iters>}. - Layer 4: for each tool_use block, dispatch
tools[block["name"]](**block["input"]). Track total tool runs. Append assistant + user(tool_results) turns.
- Layer 2: call
- On cap: return
{"text": "capped", "iters": max_iters, "tool_calls": <count>}.
Two cases run for you. Expected output:
text='Tokyo guide.' iters=2 tool_calls=1
text='capped' iters=2 tool_calls=2
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.