Skip to main content

Hand-offs as Contracts

Why This Matters

Between agents, prose is a liability. The coordinator has to re-interpret it, and every re-interpretation is a chance to lose a detail or invent one. A schema per hand-off turns agent communication into something you can validate and test, exactly like an API between services.

Hand-offs as contracts: a finding passes from the root-cause investigator to the coordinator to the bug writer, validated in code at every step

A result schema per specialist

const findingSchema = z.object({
  testId: z.string(),
  verdict: z.enum(["flaky", "not_flaky", "unknown"]),
  confidence: z.number().min(0).max(1),
  evidence: z.array(z.object({
    source: z.enum(["history", "log", "commit", "error"]),
    reference: z.string(),   // e.g. "run-1042/t-004 log line 3"
    quote: z.string(),
  })),
  openQuestions: z.array(z.string()),
});

Three fields deserve attention:

  • evidence with its source: the coordinator (and later a human) can check every claim.
  • openQuestions: what the specialist could not answer. This is how uncertainty travels instead of disappearing.
  • confidence: useful, but never the only basis for a decision (lesson 39).

Validate every hand-off in code

Exactly as in lesson 9: validate the specialist’s result before the coordinator sees it. An invalid result gets one retry with feedback; after that the failure is marked as not triaged, with the reason.

What travels back

Conclusions and evidence, not the specialist’s whole exploration. If the root-cause investigator read 300 lines of diff, the coordinator gets the three lines that matter, with references. That keeps the coordinator’s context small and its report focused.

Chaining specialists

Some failures need two specialists. The root-cause investigator finds a product bug; the bug writer drafts the report. The second brief gets the first finding as structured input:

Confirmed finding (from root-cause investigator):
{ "testId": "t-002", "verdict": "product_bug", "evidence": [ … ] }
Task: draft a bug report from this finding. Do not add claims that are not in the evidence.

The bug writer never sees raw logs; it works from validated findings only.

Exercise

Define result schemas for the three specialists, validate them in code, and write a test where the root-cause investigator returns an invalid result twice and the failure ends up as not triaged.

Compare with solution/lesson-40-triage-team, which covers lessons 34–40 (see docs/exercises.md, module 5).