Hello! Welcome back to our module, "Architecting Agentic Systems."
In our last lesson, we focused on the escalation flow. You learned how to define triggers for handoffs and diagram the architectural path that allows an AI agent to gracefully escalate a task to a human. We established that a robust system doesn't just pause; it halts, saves its state, and resumes later.
Today, we're diving into the heart of that handoff: the context. Your learning outcome is to specify the critical context that must be preserved during an agent-to-human handoff.
When an AI passes the baton to a person, what information must go with it? If the context is incomplete, the human agent is forced to do detective work, and the end-user has to repeat themselves—a recipe for frustration and inefficiency. For you as a UI/UX designer, defining this context is about designing a seamless and intelligent collaboration between the human and the AI.
The Problem: The High Cost of Lost Context
Imagine being transferred to a human support agent and hearing the dreaded words, "I'm sorry, I don't have your information. Could you please explain the issue from the beginning?" This experience immediately breaks trust and wastes everyone's time.
This failure is known as "incomplete context transfer." Let's read a short article that outlines the minimum data payload required to prevent this.
AI Agent Software: How Intelligent Handoff to Human ... - Dialzara
The article 'AI Agent Software: How Intelligent Handoff to Human...' from Dialzara clearly lists the components of what it calls an 'Essential Context Package.'
Please read the two short sections: 'Essential Context Package' and 'Incomplete Context Transfer'. As you read, notice how the list of items is not just about the conversation but also includes metadata and history.
The Solution: The "Context Package"
As the article highlights, a successful handoff isn't just a notification; it's a transfer of a complete "Context Package." This is the structured set of data that gives the human agent instant, comprehensive insight into the task.
Let's refine our definition of what this package must contain, drawing from best practices.
AI Agent Handoff Protocol: Best Practices for Human-in-the-Loop ...
The 'AI Agent Handoff Protocol' article from Fast.io provides another perspective on this, emphasizing the preservation of the 'state of the work.'
Read the section titled 'How Do You Structure a Handoff Between Agent and Human?'. Focus on the description under 'The Context Package'.
By combining these sources, we can create a comprehensive list of what a context package should contain:
-
Identity & History:
userID: A unique identifier for the customer.conversationID: An ID for the current interaction.conversationHistory: The complete, timestamped transcript of the user-agent interaction.crmProfile: Relevant historical data about the user (e.g., past purchases, previous support tickets).
-
Current State & Intent:
transferReason: The specific trigger that initiated the handoff (e.g., "low_confidence_score", "user_request", "policy_exception").agentActions: A log of actions the agent has already attempted (e.g.,api_call:check_order_status,result:failed).pendingAction: The action the agent was about to take before escalating.collectedData: Any information gathered from the user during the current session (e.g., order number, new shipping address).
-
Artifacts & Metadata:
generatedFiles: Links to any files or documents the agent created (e.g., a draft report, a generated image).errorLogs: Any technical errors the agent encountered.agentMetadata: The agent's internal state, such as intent classifications and confidence scores for its last few predictions.
A High-Stakes Analogy: The Medical Handoff
Losing context in a customer support chat is frustrating. In other fields, it can be life-threatening. Your engineering background gives you an appreciation for structured, safety-critical processes. Let's look at one of the most critical handoffs of all: transferring a patient from the operating room to the intensive care unit (ICU).
.pdf/page1-1200px-OR_to_ICU_Handoff_Checklist_&_Process_Infographic_(1).pdf.jpg)
Take a moment to study this checklist. Can you see the parallels to our AI agent's context package?
- Patient Identifiers are like
userIDandcrmProfile. - Surgical Course (what was done) is like
agentActions. - Post-Op Management Plan (what needs to happen next) is like
pendingAction. - Anticipatory Guidance (what to watch out for) is like
transferReasonanderrorLogs.
This structured protocol ensures the ICU team can act immediately and effectively. Our goal in designing an agent handoff is the same: empower the human to act, not to investigate.
Durability: Making Sure Context Survives Failure
What if the system crashes right after the agent triggers the handoff but before the human can respond? If the context package only exists in the agent's temporary memory, it's lost forever.
This is why context must be durable. As we touched on in the last lesson, the moment an escalation is triggered, the context package must be serialized and saved to a persistent state store (like a database).
This concept is at the heart of durable execution frameworks. Let's watch a video that demonstrates this principle in a powerful way.
Human-in-the-Loop (HITL) for AI Agents: Patterns and Best Practices
The talk 'Human-in-the-Loop (HITL) for AI Agents' from Temporal explains how a durable execution service works. It ensures that the logical flow and state of an application are preserved, even when the underlying processes fail.
Watch two segments: Durable Execution Explained (26:00 - 29:00): This explains the core concept of separating the logical application flow from the physical processes that run it. Killing the Worker Demo (37:29 - 40:58): This is the key part. You will see the presenter kill the actual process running the agent's workflow. The workflow's logical state (including the need for human input) persists. When the process is restarted, it seamlessly picks up exactly where it left off, having lost no context. This is durability in action.
The key takeaway is that preserving context is not just about collecting the right data; it's about architecting the system to guarantee that data survives failures. The state must be written to a persistent location before notifying the human, ensuring the handoff can always be completed.
Your Turn: Specify a Context Package
Let's apply this. You are designing the handoff for an e-commerce returns bot. A user wants to return an item they bought 45 days ago, but the standard return window is 30 days. The bot's policy is to escalate these exceptions to a human agent who can make a goodwill decision.
Your Task:
Based on what you've learned, specify the contents of the context package for this handoff. List the essential key-value pairs that the human agent would need to see in their workspace to resolve the issue quickly and without asking the user to repeat anything.
Click to see an example specification
Here is a sample context package for the scenario, formatted as a JSON object:
{
"handoffID": "hof_1a2b3c4d",
"userID": "usr_5e6f7g8h",
"conversationID": "conv_9i0j1k2l",
"transferReason": "policy_exception_return_window_exceeded",
"context": {
"customerInfo": {
"name": "Alex Ray",
"loyaltyStatus": "Gold",
"pastReturns": 3
},
"orderInfo": {
"orderID": "ord_3m4n5o6p",
"productName": "Pro Blender 5000",
"purchaseDate": "2024-08-15T10:00:00Z",
"daysSincePurchase": 45
},
"agentSummary": {
"actionsTaken": [
"Verified user identity.",
"Retrieved order details.",
"Calculated days since purchase.",
"Identified return window policy violation."
],
"pendingAction": "process_return_approval"
},
"conversationHistory": [
{ "speaker": "user", "text": "Hi, I'd like to return an item.", "timestamp": "..."},
{ "speaker": "agent", "text": "Sure, can you provide the order number?", "timestamp": "..."},
{ "speaker": "user", "text": "It's ord_3m4n5o6p.", "timestamp": "..."},
{ "speaker": "agent", "text": "I see you purchased the Pro Blender 5000 on August 15th. Our return policy is 30 days. I'll connect you with a team member who can look into this for you.", "timestamp": "..."}
]
}
}
This package gives the human agent everything they need: who the user is, their history, the specific order in question, why it was escalated, and the full chat log. The agent can immediately start with, "Hi Alex, I see you're looking to return the Pro Blender from 45 days ago. Let me see what I can do for you."
Conclusion
Today you've moved from the flow of a handoff to its substance. A well-designed system doesn't just pass control; it passes knowledge. By meticulously specifying and durably preserving the context package, you transform a potentially jarring interruption into a smooth and intelligent collaboration.
Key Takeaways:
- The Context Package is Essential: A successful agent-to-human handoff relies on a complete package of information, including user data, conversation history, agent actions, and the reason for the transfer.
- Prevent "Archaeology": The goal is to design a workspace for action, not investigation. The human agent should be able to understand the situation at a glance.
- Context Must Be Durable: The context package must be saved to a persistent state store before the handoff occurs to ensure it survives system crashes or delays.
- It's a UX Problem: Defining and presenting this context is a core UI/UX design challenge that directly impacts both the human agent's efficiency and the end-user's satisfaction.
Next Lesson Preview
We've now examined how an agent discovers tools, defines their use, and hands off tasks it can't complete. In our next lesson, we will zoom out to see how an agent manages a full sequence of operations. You will learn to create an interaction flow diagram for a multi-step agent orchestration workflow, tying together tool use, decision-making, and potential handoffs into a coherent process.