Skip to content

< CollectionsEffective context engineering · 9 of 10 ·90 · Level 05, Agents

Hand Off Only What the Next Agent Needs

easy · implement · Agents

Agent A has spent twenty turns in a deploy channel and now hands the job to agent B, which has a small window. The current handoff is A's whole context: B raises ContextTooLarge before it reads a word. Implement handoff(context, task).

context is a list of entries, each {"kind": "message" | "tool_result", "text": ...}. task is {"text": ..., "keywords": [...]}.

  1. Return {"task": task["text"], "facts": [...]}.
  2. An entry is carried when its text contains any of the task's keywords, compared case-insensitively.
  3. An entry that matches SECRET_PATTERN is dropped even when it is relevant. Credentials do not travel between agents.
  4. An exact repeat (the same text after strip()) is carried once, the first time.
  5. Facts keep the order of the context, and each is the entry's text with surrounding whitespace removed.

agent_b(handoff) is provided. It answers the task when the facts it needs are in the handoff, says what is missing when they are not, and raises ContextTooLarge when the handoff is over its window. size(handoff) is how it measures.