Module 5 · Lesson 5 · 16 min read
Task handoffs and shared state
Handoffs and Shared State
Introduction
In many systems a single agent does not stay responsible for the conversation until the end; it hands it over to a more specialized agent. This lesson explains the concept of a handoff, what must travel with the handoff, and how to design a shared state that agents read from and write to without spoiling each other's work.
Learning objectives
- Define the handoff and distinguish it from calling an agent as a tool
- Identify the information that must travel with the handoff
- Design a shared state with clear ownership rules for the fields
- Detect write conflicts in the shared state and handle them
What is a handoff?
A handoff means that one agent transfers responsibility for the conversation or task to another agent, so that the second one follows up the work and replies to the user. The classic example is customer service: a triage agent receives the question, and if it is about billing it hands it to the billing agent, and if it is about a technical problem it hands it to the technical support agent.
The OpenAI Agents SDK supports the handoff as a core concept (Handoffs) alongside using agents as tools (according to the official documentation, reviewed 18 November 2026). The difference between them is fundamental:
| Handoff | Agent as tool | |
|---|---|---|
| Who owns the conversation afterwards? | The receiving agent | The calling agent stays responsible |
| What comes back? | Usually nothing; the receiver carries on | A result that the caller uses |
| Example | Transferring the customer to the billing department | Asking a translation expert about a sentence and then carrying on |
What travels with the handoff?
The worst experience for the user is being asked to explain their problem again after every transfer. So a good handoff carries a context package that includes:
- The reason for the handoff: why this particular agent was chosen.
- A summary of what happened: instead of copying the whole conversation, a short summary with the important points.
- The extracted data: such as the order number or the course name.
- What has not been done yet: the open question the receiver must answer.
Shared state
Shared state is a single store that represents the "current truth" of the task: what has been done, the intermediate results, and who is working on what. Problems arise when two agents write to the same field at the same time, so one erases the other's work. Three rules reduce this:
- Field ownership: each field has a single agent allowed to write to it, and the rest only read.
- A version number: whoever writes states the version number they read, and if it changed in the meantime the write is rejected and they read again.
- An append-only log: every change is added to a log from which nothing is deleted, so what happened can be traced and rebuilt.
These same ideas lie behind frameworks such as LangGraph, which build agents around an explicit state that passes through the nodes of the graph.
A practical example: a student services office
A student writes: "I paid the semester fees and the payment hasn't shown up, and the receipt number is R-5521." The triage agent detects that the matter is financial, so it hands the task to the fees agent with a context package, and both write to a shared state with ownership rules and a version number. The agents are deterministic functions for teaching:
class SharedState:
def __init__(self, owners):
self.data, self.version, self.log = {}, 0, []
self.owners = owners
def write(self, agent, key, value, seen_version):
if self.owners.get(key) != agent:
raise PermissionError(f"{agent} does not own the field {key}")
if seen_version != self.version:
return False # conflict: the state has changed since it was read
self.data[key] = value
self.version += 1
self.log.append((self.version, agent, key))
return True
state = SharedState({"category": "triage", "handoff": "triage", "resolution": "fees"})
def triage(message):
v = state.version
category = "fees" if "fees" in message or "paid" in message else "general"
state.write("triage", "category", category, v)
package = {"reason": "A financial inquiry", "summary": message[:40],
"receipt": message.split()[-1], "open_question": "Why hasn't the payment shown up?"}
state.write("triage", "handoff", package, state.version)
return "fees_agent"
def fees_agent():
pkg = state.data["handoff"]
reply = f"We will review receipt {pkg['receipt']} and let you know the result."
state.write("fees", "resolution", reply, state.version)
return reply
next_agent = triage("I paid the semester fees and the payment hasn't shown up, and the receipt number is R-5521")
print("Handoff to:", next_agent)
print(fees_agent())
print("Expected conflict:", state.write("fees", "resolution", "Old text", 0) is False)
try:
state.write("fees", "category", "general", state.version)
except PermissionError as e:
print("Rejected:", e)
print(state.log)Notice that the fees agent did not ask the student for the receipt number again because it arrived in the context package, that the attempt to write with an old version number was rejected, and that the attempt to write to a field the agent does not own was rejected too.
Summary
A handoff transfers responsibility for the conversation to another agent, unlike calling an agent as a tool, where the caller stays responsible. The handoff must carry a concise context package that includes the reason, the summary, the extracted data and the open question, without extra data. Shared state is a single source of truth that needs field ownership, version numbers and a change log so that no agent erases another's work.
Terms
| Term | English | Definition |
|---|---|---|
| Handoff | Handoff | Transferring responsibility for the conversation or task from one agent to another |
| Agent as tool | Agent as Tool | Calling an agent to get a result while the caller stays responsible |
| Context package | Context Package | The concise information that travels with the handoff |
| Shared state | Shared State | A single store of what has been done and of the task's results, visible to the agents |
| Version check | Version Check | Rejecting a write if the state has changed since it was read |
| Append-only log | Append-only Log | A change log from which nothing is deleted |
Review questions
- What is the difference between a handoff and calling an agent as a tool? Give an example of each.
- What are the components of a good context package, and why don't we always transfer the whole conversation?
- How does a version number prevent lost updates in the shared state?
- Why do we assign a single owner to each field in the state?
References
- OpenAI Agents SDK openai.github.io Reviewed on 2026-11-18
- LangGraph overview docs.langchain.com Reviewed on 2026-11-18
