- RetryWhy a retry needs new evidence, not another attempt.
- SchemaWhat a shape contract can prove and what it cannot.
- ToolsHow to reduce tool confusion without removing useful capability.
- LearningHow one failed run becomes a test that protects the next release.
01Where Episode 02 left us
Inside a Production Agent Harness gave us five decisions around every model call.
Identity sets the operating contract. Memory policy chooses what the model sees. Orchestration decides what happens next. Interception checks the crossings. Observability and evals record and judge the run.
The reconciliation team can now draw its system. The map shows where the holes are.
The next question is practical: what can the team change this sprint?
02The sprint that changed no model
The team has spent a quarter comparing models. The invoice agent still fails in three familiar ways.
It repeats a malformed request without learning from the error. It returns fields the downstream system cannot use. It picks the wrong tool when several names sound alike.
On Monday, the team freezes the model.
Validation errors now return to the next attempt. Outputs must follow an agreed shape. The agent sees only the tools needed for the current step.
By Friday, the lesson is not that three tricks worked. It is why they worked.
Each change removed a decision the model kept getting wrong.
Reliability improves when the system replaces a vague choice with a specific signal or constraint.
03The whole pattern in one table
No code is required to understand the production loop.
| Step | What happens | What the harness decides |
|---|---|---|
| Prepare | Gather current state and relevant tools | What the model may see and choose |
| Propose | The model returns an answer or tool request | Whether the proposal has an acceptable shape |
| Act | A tool performs the approved operation | Whether the action is permitted |
| Verify | The system checks the real effect | Whether the step moved the task forward |
| Continue | The run advances, retries, escalates, or stops | Whether external completion has passed |
| Learn | The trace is stored and judged | Whether this failure becomes a regression test |
The model proposes. Reliability comes from the decisions before and after that proposal.
04Pattern 1: retry with evidence
A naive retry says, “Try again.”
The model receives the same task, context, and uncertainty. A different answer may appear, but the second attempt has no better reason to succeed.
A useful retry explains what failed.
| Weak feedback | Useful feedback |
|---|---|
| “Validation failed” | amount_cents must be a whole number |
| “Try again” | You returned $42.50; return 4250 |
| “Wrong format” | Change this field only; keep the other values |
The second version supplies the missing information: field, observed value, expected rule, and correction scope.
- InformationReturn the exact validation error.
- StrategyAsk for a different method after repeated failure.
- ContextRestart with a clean view and durable progress.
- AuthorityEscalate to another model, tool, or human.
If none changes, the retry is repetition.
| Failure | What it means | Example | What repairs it |
|---|---|---|---|
| Syntax | The output is malformed or breaks an agreed structure | Invalid JSON, a missing required field, an unsupported status label | Provider-enforced structure, then validation at your boundary |
| Semantic | The shape is valid but the business value is wrong | The amount is a whole number, but it belongs to another invoice | Business rules, source reconciliation, tests, or an eval |
| Goal | Every individual output is valid, but the job remains unfinished | 847 invoices passed validation while 1,500 were never processed | An external completion rule tied to the real workflow |
One validator cannot do all three jobs.
The key metric is not retry count. It is the percentage of failed first attempts that recover without creating a wrong business outcome.
05Pattern 2: constrain the output space
Teams often treat structured output as a developer convenience. The product value is a smaller failure space.
Free text lets the model return anything it can express. A schema, which is an agreed description of allowed fields and values, limits output to shapes the program knows how to handle.
Consider the invoice output.
| Field | Weak contract | Stronger contract |
|---|---|---|
| Vendor | Any text | Non-empty text |
| Amount | Any text | Whole number in cents, zero or more |
| Due date | Any text | YYYY-MM-DD |
| Status | Any text | Paid, pending, overdue, or disputed |
| Extra fields | Allowed silently | Rejected unless added to the versioned contract |
A weak instruction such as “return JSON” may still produce:
- Amount
"$42.50" - Due
"end of August" - Status
"awaiting payment" - ExtraAn invented explanation field the caller ignores.
The response looks sensible to a human. The next system may fail or silently discard information.
| Proves | Does not prove |
|---|---|
| Required fields exist | The amount belongs to the right invoice |
| Values use supported types | The status matches the ledger |
| Finite business states use agreed labels | The source data is current |
| Unagreed fields are rejected | The whole job is finished |
A schema checks shape. An eval checks meaning. A completion rule checks the job.
OpenAI’s current documentation makes a useful distinction. JSON mode returns valid JSON. Structured Outputs with strict mode follow a supported supplied schema. Your application should still validate semantic rules and handle refusals, empty results, timeouts, and unsupported schema features.
A schema is a contract with every downstream consumer, not only the model. When it changes:
- Version the new shape.
- Identify affected consumers.
- Test old and new cases.
- Plan compatibility or migration.
- Monitor empty, refused, and semantically invalid outputs.
A field added casually today becomes a silent mismatch three systems later.
Track schema-valid output and semantic correctness separately. A perfect shape can carry a wrong answer.
06Pattern 3: narrow the decision surface
Give an agent forty tools and it must distinguish forty operations before every action.
Some tools are irrelevant. Some overlap. Some use broad names such as query_data
or update_record. The model must infer what they mean and whether the
consequence is read, draft, or execute.
The solution is not always fewer total capabilities. It is fewer visible choices for this step.
| Vague tool | Better tool | Decision removed |
|---|---|---|
query_data | get_invoice_by_id | Which dataset and query shape? |
run_analysis | list_overdue_invoices | Which analysis and output? |
update_record | draft_payment_adjustment | Draft or execute? Which record? |
refund | draft_refund and issue_refund | Proposal or irreversible action? |
A precise name is part of the control surface.
- Delete tools with no distinct job.
- Rename vague tools to exact actions.
- Reveal specialist tools only when the task needs them.
The third uses progressive disclosure: the system keeps broad capability but shows the model a small, relevant set now.
A reconciliation skill may expose invoice lookup, payment lookup, exception drafting, and completion checks. A supplier-onboarding skill exposes another set.
A rare escalation tool may be essential. Review each tool on four dimensions.
| Dimension | Question |
|---|---|
| Usage | How often is it selected? |
| Contribution | Does it help complete the task? |
| Overlap | Does another tool do the same job? |
| Consequence | What happens if the model picks it incorrectly? |
The decision may be keep, rename, tighten, hide behind a skill, require approval, merge, or remove. The goal is not the shortest list. It is the clearest set that covers the workflow.
Near-neighbor tools fail at their boundary. Descriptions should include negative examples.
Use get_invoice_by_id when an exact invoice ID is known. Do not use it for
vendor search or status lists.
The model now knows the operation and its edge.
Track correct-tool selection and steps per validated completion. Fewer calls are useful only when completion stays correct.
07Pattern 4: verify before exit
The invoice failure in Episode 01 did not involve malformed output or the wrong tool. The run stopped before the workflow ended.
Replace model confidence with an external checklist.
| Completion check | Required evidence |
|---|---|
| Coverage | Processed count equals eligible source count |
| Exceptions | Every unmatched record has an assigned state |
| Quality | Reconciliation checks pass |
| Authority | No prohibited action occurred |
The model may propose completion. The harness checks the business state.
This is feedback at the job level:
- Output feedback“This field is invalid.”
- Completion feedback“This outcome is unfinished.”
Anthropic’s long-running-agent work uses feature inventories, progress files, startup scripts, and version history so new sessions can reconstruct what remains. LangChain’s Deep Agents work uses self-verification and pre-completion checks before exit.
A completion gate can create a loop. Define:
- BudgetTime and cost ceiling.
- AttemptsMaximum attempts without progress.
- RecordDurable progress record.
- EscalationWhere the run goes when it stalls.
- StopThe condition when the task cannot complete.
“Continue until done” is not a policy unless both done and stop are defined.
08The measured receipt
LangChain held the model fixed and changed the system prompt, tools, and middleware, its term for hooks around model and tool calls.
The work included trace-based error analysis, self-verification, pre-completion checks, environment context, and loop detection. Terminal Bench 2.0 performance moved from 52.8% to 66.5%, a 13.7-point increase.
The result does not prove every harness change helps every workflow. It supports a narrower claim: changing the control system can materially change measured behavior while the model stays fixed.
The method is more reusable than the benchmark:
- Run a defined test set.
- Read the failed traces.
- Group failures by behavior.
- Change one system surface.
- Keep the change only if evaluation improves.
09The feedback loop
A production trace is a record of what happened. It becomes an eval only after the team states what should have happened.
| Stage | Invoice example |
|---|---|
| Trace | Agent used list_invoices_by_status despite an exact ID |
| Failure label | Wrong tool selected when invoice_id is explicit |
| Eval | Exact-ID cases must choose get_invoice_by_id |
| Change | Add a negative boundary to the list tool |
| Holdout | Test new exact-ID and ambiguous cases not used to design the fix |
| Ship | Release if selection improves without harming ambiguous search |
A holdout set is a group of test cases the team does not use while designing the change. It checks whether the improvement works beyond the examples that inspired it.
Twenty well-labeled cases from real failures may be worth more than a thousand synthetic cases no user has produced.
10In practice: one sprint
Pick one high-volume model decision.
| Move | Action | Metric |
|---|---|---|
| Retry | Return the exact violation and correction scope | Recovery after first failure |
| Output | Enforce one versioned shape | Schema-valid and semantically correct outcomes |
| Tools | Show only relevant tools; rename one vague operation | Correct-tool selection |
| Completion | Add one external business check before exit | Valid completed workflows |
| Learning | Turn the next failed trace into an eval | Time from failure to regression coverage |
Do not ship all five changes at once if you cannot attribute the result. Start with the failure that appears most often or carries the largest consequence.
11Connecting the dots
The four patterns share one design principle. Let the model reason over the uncertain part. Do not make it improvise the contract around the uncertain part.
That principle connects reliability, cost, and autonomy.
A precise error reduces wasted retries. A schema protects downstream systems. A narrow tool set reduces wrong actions. A completion check lets the organization trust longer work. Each constraint may also add latency, cost, or blocked edge cases.
That trade-off is the bridge to Episode 04. The question is no longer whether constraints work. It is when they buy enough reliability, when they limit useful autonomy, and when a better model makes them unnecessary.
-
OpenAI — structured model outputs: JSON mode, strict schemas, refusals, and
unsupported features.
developers.openai.com/api/docs/guides/structured-outputs -
LangChain — improving Deep Agents with harness engineering: fixed model, changed
prompt, tools, and middleware; Terminal Bench 2.0 from 52.8% to 66.5%.
langchain.com/blog/improving-deep-agents-with-harness-engineering -
Anthropic — effective harnesses for long-running agents: feature inventories,
progress files, startup scripts, and version history.
anthropic.com/engineering/effective-harnesses-for-long-running-agents