Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
When agents share state, one agent's mistakes, hallucinations, or half-formed reasoning can contaminate another's context — the second agent treats the first's speculation as fact. This compounds: errors propagate and amplify across the pipeline. Preventing contamination means marking the provenance and confidence of shared context (this is a verified fact vs. this is agent-2's hypothesis) so downstream agents weight it appropriately, and isolating speculative reasoning so it doesn't leak as ground truth. It's the multi-agent version of trust boundaries.
The demo tags every shared item with provenance and status (verified/hypothesis/raw) so a downstream agent can be instructed to act only on verified items and treat hypotheses as tentative — stopping error propagation.
Use these three in order. Each builds on the one before.
What is context contamination in multi-agent systems, and how does one agent's error spread to others?
Explain how provenance and status tagging (verified vs. hypothesis vs. raw) on shared context prevents downstream agents from treating speculation as fact.
Design an anti-contamination scheme for a multi-agent research pipeline: provenance tracking, confidence propagation, isolating speculative reasoning, and how I'd detect which agent introduced an error.
When the model call fails. Read the error and decide: fix the request, retry, or fall back.
400/422(bad params, context-length exceeded),401/403(auth / no access to that model),404(wrong model id) are fatal — fix and don't retry.429,500/502/503, Anthropic529(overloaded), and timeouts are transient — retry with backoff. Watch for non-HTTP failures too:finish_reason: "length"truncation (raisemax_tokensor continue), safety , malformed JSON / failed tool-call parsing (validate against a schema and repair-retry), and mid-stream disconnects. Always log the provider with the error so you can trace it later.
shared = [
{"text": "Q2 revenue was $4.1M", "by": "data-agent", "status": "verified"},
{"text": "Churn is probably seasonal", "by": "analyst-agent", "status": "hypothesis"},
]
def context_for_decider(shared):
lines = []
for item in shared:
tag = "[VERIFIED]" if item["status"] == "verified" else "[HYPOTHESIS — do not treat as fact]"
lines.append(f"{tag} {item['text']} (from {item['by']})")
return "\n".join(lines)
print(context_for_decider(shared))
# Decider is instructed: base conclusions only on [VERIFIED]; flag if relying on [HYPOTHESIS].python3 main.py