Search⌘ K
AI Features

Minimal Shared State and Structured Inter-Agent Handoffs

Learn how to build reliable multi-agent workflows with minimal shared state and structured handoffs. You will define four state keys, enforce fixed formats for clues and responses, offload large outputs to disk, validate worker contracts, and test state growth and isolation.

We'll cover the following...

In the previous lesson, we split the incident review across isolated workers, and the coordinator stayed small because each worker returned only a short result. But we didn’t say what that result should look like. Each worker returned whatever shape was convenient, and nothing said where the current plan lives or where the record of handoffs is kept.

In this lesson, we’ll see how mismatched shapes break the coordinator. Then we’ll build one shared state with four keys, fixed formats for facts and for handoffs, and checks that prove the state stays small and that every worker follows the format.

Three shapes, three failures

Suppose three workers finish their turns, and each returns its result in the shape that felt natural. The planner writes a sentence. The analyst returns a dictionary with its own key names. The reporter returns a title and a markdown body. Now the coordinator tries to read one value, the minutes over the SLO, the same way from each.

mixed_shapes.py · Python 3.14.0
RESULTS = { # each worker returned whatever shape felt natural
"planner": "First collect evidence, then compute the impact, then check it and write the review.",
"analyst": {"slow_minutes": 7, "requests_during_spike": 8015},
"reporter": {"title": "Incident review", "body": "## Impact\n| minutes | requests |\n| 7 | 8015 |"},
}
if __name__ == "__main__":
for role, result in RESULTS.items():
try:
print(f"{role:<8}| minutes over SLO = {result['minutes_over_slo']}")
except (TypeError, KeyError) as error:
print(f"{role:<8}| {type(error).__name__}: {error}")

In the code above:

  • Lines 1–5: We store the three results in the shapes the workers chose.

  • Lines 8–12: We try to read minutes_over_slo from each one and print the error if it fails.

All three reads fail:

planner | TypeError: string indices must be integers, not 'str'
analyst | KeyError: 'minutes_over_slo'
reporter| KeyError: 'minutes_over_slo'
One line of coordinator code fails three times, even though the analyst has the right number

The analyst computed the right answer, 7 minutes, but called it slow_minutes. The coordinator can’t use a result it can’t read.

We could agree on one dictionary shape for this task. That fixes the crashes, but it leaves two questions open. Where does the current plan live, so the validator can read it without asking the planner again? And where is the record of who returned what, so an auditor can check the whole chain later? We need one structure that answers all of these.

Four keys, two formats

The shared state is one dictionary with exactly four keys. Every role reads and writes it the same way:

  • messages: The task and one ...