feat: add handoff context summarization example#4951
Closed
Conversation
Demonstrates three strategies for passing context between agents: 1. Structured userdata with YAML serialization 2. Chat context copy/truncate for conversational continuity 3. LLM-powered summarization before handoff Co-Authored-By: kat <[email protected]>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
Author
|
Lol...I only meant to ask it a question, not create a PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: add handoff context summarization example
Summary
Adds a new example (
examples/voice_agents/handoff_context_summarization.py) demonstrating three strategies for passing context between agents during a handoff:ConversationDatadataclass serialized to YAML and injected as a system message on agent entry.BaseAgent.on_entermerges the previous agent's last ~3 turns (excluding instructions/handoff markers) into the new agent's context.TriageAgent.transfer_to_specialistcallschat_ctx._summarize()to compress older turns into a short paragraph, keeping token usage low.The flow is:
TriageAgentgathers name/email/topic/sentiment → summarizes context → hands off toSpecialistAgentwhich picks up with full context awareness.Review & Testing Checklist for Human
chat_ctx._summarize()(underscore-prefixed). Confirm this is acceptable to surface in an example, or whether there's a public-facing summarization API that should be used instead._prev_agent: The triage agent storesself.session._prev_agent = selfto pass itself to the next agent. Therestaurant_agent.pyexample storesprev_agenton the userdata instead, which is cleaner and uses only public API. Consider whether this example should follow the same pattern for consistency.make lintpasses) but not run end-to-end. Recommend runningpython handoff_context_summarization.py devwith a LiveKit server and verifying the triage → specialist handoff works, especially that the summarized context actually appears in the specialist's chat context.TriageAgentextendsBaseAgentbut overrideson_enterentirely — Since the triage agent is the first agent (no previous context to merge), it skipsBaseAgent.on_enter. Verify this inheritance is clear enough for readers or if a different structure would be less confusing.Notes
livekit/agents-jsin a separate PR.