方寸 Portal

AI Engineer Portal

Your personal operating system for career transition.

Private mode

Exercise

Multi-agent handoff protocol

Multi-Agent Handoff Protocol

As agent systems grow, a single monolithic agent becomes unwieldy. The multi-agent pattern splits work among specialist agents (e.g., a researcher, a coder, a reviewer) with a coordinator that routes tasks and aggregates results. The critical engineering challenge is the handoff protocol: how agents pass context to each other cleanly.

What you are building

Create a multi-agent handoff system with:

  1. Agent base class — each agent has a name, a description of its capabilities, and a handle(task) method.
  2. HandoffContext — a structured object that carries the task description, conversation history, intermediate results, and metadata between agents.
  3. Coordinator — routes tasks to the appropriate specialist based on task type, collects results, and handles failures (retry, skip, or escalate).
  4. Handoff protocol — when an agent cannot complete a task, it returns a HandoffRequest indicating which specialist should take over and what context to pass.
  5. Result aggregation — the coordinator collects results from multiple agents and produces a unified response.

Why this matters

Multi-agent architectures are how production AI systems handle complex workflows: customer support (triage agent -> specialist agent -> quality review agent), code generation (planner -> coder -> tester), research (search agent -> analysis agent -> writing agent). The handoff protocol is where most multi-agent systems break — context gets lost, errors cascade, and the coordinator loses track of state.

Constraints

  • Each agent must be independently testable with mock inputs.
  • The coordinator must handle agent failures without crashing the entire workflow.
  • HandoffContext must be serializable (to dict) for logging and debugging.
  • Support a maximum depth for handoff chains to prevent infinite delegation.

Agents / advanced / Step 6 of 8

Practice stage

Agent architecture patterns

Hint

Focus on explicit control surfaces — function schemas, state machines, and structured outputs. Agents are most useful when the task requires dynamic tool selection or multi-step reasoning. Start with the simplest pattern (single tool call) before reaching for ReAct loops.

Success criteria
  • - Tools return structured, typed responses
  • - Agent completes the task within a bounded number of steps
  • - All tool calls include error handling and retries
  • - Memory/state management prevents unbounded context growth
Review checklist
  • - Tool schemas validate inputs and handle errors gracefully
  • - Agent loop has explicit termination conditions
  • - State is serializable and inspectable between steps
  • - Cost and token usage are tracked per invocation
  • - Fallback behavior exists for tool call failures

Practice

Generate a variation

Generate a new exercise variation to deepen understanding or practice a related concept.

Attempt history

Recent submissions

Before you submit, decide what a strong answer should make obvious to the reviewer.

No attempts yet.