Skip to content

feat(agent): explicit pre-delegation gate before spawning the Report agent#95

Merged
atomicdragonranch merged 1 commit into
masterfrom
feat/94-predelegation-gate
Jul 9, 2026
Merged

feat(agent): explicit pre-delegation gate before spawning the Report agent#95
atomicdragonranch merged 1 commit into
masterfrom
feat/94-predelegation-gate

Conversation

@atomicdragonranch

Copy link
Copy Markdown
Owner

Closes #94.

Problem (cert Ep 04, fail-fast delegation)

Ep 04's capstone lesson: verify an upstream sub-agent's structured finding before delegating to the next, and short-circuit if it's thin, or "the second sub-agent might also execute and return hallucinated results."

run_cycle's only gate before the Report agent was _all_claims_low_confidence, which returns False for an empty claims list:

if not diagnosis.claims:
    return False

So a diagnosis with no claims (Diagnostic agent found nothing concrete) or a parse_error fallback (unparseable diagnostic output, no claims/sources) sailed past it into the Report agent, which then synthesized a full IncidentReport from nothing, the exact hallucinate-on-thin-context failure Ep 04 warns about.

Fix

_verify_diagnosis_precondition(diagnosis) -> str | None returns a reason when the diagnosis is not fit to delegate (parse-error fallback, no claims, or all claims LOW/UNSOURCED) and None when it is. run_cycle calls it in place of the inline low-confidence check; on a reason it logs and returns None without spawning the Report agent or escalating. Multi-agent path only; single-agent mode (no sub-agent claims by design) is unchanged.

Tests

Gate for reportable / no-claims / parse-error / all-low, plus a run_cycle test asserting an empty diagnosis never spawns the Report agent and never escalates.

Full suite 260 passed; ruff + mypy clean.

Note on the Ep 04 task-tool caveat

Ep 04 flags that task-based sub-agent spawning is a Claude Code / Agent SDK feature, not the raw anthropic SDK, and that hand-rolled function spawning is architecturally correct. This project already hand-rolls spawning with plain functions + asyncio.gather, so it's aligned with the pattern the exam tests; no change needed there.

https://claude.ai/code/session_01R5VygSzbGTggW7mHd3PVwE

…agent

Closes #94.

Cert Ep 04's fail-fast lesson: a coordinator must verify an upstream sub-agent's
structured finding before delegating to the next, and short-circuit if it is
thin, or the downstream agent hallucinates on empty context. run_cycle's only
gate before the Report agent was _all_claims_low_confidence, which returns False
for an empty claims list, so a diagnosis with NO claims (or a parse_error
fallback with none) sailed past it into the Report agent, which then synthesized
a full incident from nothing.

Add _verify_diagnosis_precondition(diagnosis) -> str | None, returning a reason
when the diagnosis is not fit to delegate (parse-error fallback, no claims, or
all claims LOW/UNSOURCED) and None when it is. run_cycle calls it in place of
the inline low-confidence check; on a reason it logs and returns None without
spawning the Report agent or escalating. Multi-agent path only; single-agent
mode (no sub-agent claims by design) is unchanged.

Tests: the gate for reportable / no-claims / parse-error / all-low, plus a
run_cycle test asserting an empty diagnosis never spawns the Report agent and
never escalates. Full suite 260 passed; ruff + mypy clean.
@atomicdragonranch atomicdragonranch merged commit f161ef6 into master Jul 9, 2026
3 checks passed
@atomicdragonranch atomicdragonranch deleted the feat/94-predelegation-gate branch July 9, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(agent): explicit pre-delegation gate before spawning the Report agent

1 participant