Can you show me example of how to do handoff betwe...
# ask-ai
f
Can you show me example of how to do handoff between nodes in a workflow using a realtime model like aws nova sonic?
t
Thanks for reaching out, Muthana. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To implement handoff between nodes in a workflow using a real-time model like AWS Nova Sonic with LiveKit, follow these steps: 1. *Install the AWS plugin with realtime support:*`pip install "livekit-agents-aws[realtime]~=1.0"` 2. *Define your agents, ensuring handoff passes the
chat_ctx
to preserve context:*`class ConsentCollector(Agent): def __init__(self): super().__init__( instructions="""You are a voice AI agent with the singular task to collect positive recording consent from the user. If consent is not given, you must end the call.""" ) @function_tool async def on_consent_given(self): """Use this tool to indicate that consent has been given and the call may proceed.""" # Pass the chat context during handoff return HelpfulAssistant(chat_ctx=self.session.chat_ctx) class HelpfulAssistant(Agent): def __init__(self, chat_ctx: ChatContext): super().__init__( instructions="You are a helpful voice AI assistant.", chat_ctx=chat_ctx )` 3. *Initialize your session with Nova Sonic:*`session = AgentSession( llm=aws.realtime.RealtimeModel(), )` • Nova Sonic provides built-in VAD-based turn detection. • The full conversation history is always in
session.history
. • Pass
chat_ctx
from the previous agent to the next to maintain smooth context through each workflow transition. For more detailed integration or edge cases, see the referenced code structures and session initialization methods. Sources: AWS AI and LiveKit | LiveKit Docs | Workflows | LiveKit Docs | Amazon Nova Sonic integration guide | LiveKit Docs
f
Getting this whenever I return another agent as a response of a function call: 230127 voice-agent INFO [TOOLS] handle_order args={"summary":"Customer wants to place a new order"} out= 2025-07-10 230127,892 - INFO voice-agent - [TOOLS] handle_order args={"summary":"Customer wants to place a new order"} out= {"session_id": "AJ_wMGL3wxyo3dp", "pid": 26547, "job_id": "AJ_wMGL3wxyo3dp"} 230127 livekit.plugins.aws DEBUG function call output: id='item_795c9cd6f238' name='handle_order' type='function_call_output' call_id='03674bd7-01c5-422d-b928-eec8b775f85b' output='' is_error=False created_at=1752210087.8926961 2025-07-10 230127,892 - DEBUG livekit.plugins.aws - function call output: id='item_795c9cd6f238' name='handle_order' type='function_call_output' call_id='03674bd7-01c5-422d-b928-eec8b775f85b' output='' is_error=False created_at=1752210087.8926961 {"session_id": "AJ_wMGL3wxyo3dp", "pid": 26547, "job_id": "AJ_wMGL3wxyo3dp"} 230127 voice-agent INFO [STATE] agent state changed: thinking 230127 voice-agent INFO [STATE] agent state changed: thinking 2025-07-10 230127,893 - INFO voice-agent - [STATE] agent state changed: thinking {"session_id": "AJ_wMGL3wxyo3dp", "pid": 26547, "job_id": "AJ_wMGL3wxyo3dp"} 230127 livekit.plugins.aws DEBUG Sending tool result: 230127 livekit.plugins.aws DEBUG Sending tool result: 2025-07-10 230127,930 - DEBUG livekit.plugins.aws - Sending tool result: {"session_id": "AJ_wMGL3wxyo3dp", "pid": 26547, "job_id": "AJ_wMGL3wxyo3dp"} 230133 livekit.plugins.aws ERROR Validation error: RequestId=932b6ad0-14c9-4588-974f-0baba9408679 : Tool Response parsing error 230133 voice-agent ERROR Fatal error: type='realtime_model_error' timestamp=24793.854093081 label='livekit.plugins.aws.experimental.realtime.realtime_model.RealtimeModel' error=APIStatusError('RequestId=932b6ad0-14c9-4588-974f-0baba9408679 : Tool Response parsing error') recoverable=False 230133 livekit.agents ERROR AgentSession is closing due to unrecoverable error livekit.agents._exceptions.APIStatusError: RequestId=932b6ad0-14c9-4588-974f-0baba9408679 : Tool Response parsing error (status_code=400, request_id=, body=RequestId=932b6ad0-14c9-4588-974f-0baba9408679 : Tool Response parsing error, retryable=False)
t
Hey there! Let's talk about that pesky Tool Response parsing error that might pop up when things aren't quite right with your tool function. Think of it like trying to hand off a relay race baton – you want to make sure you're passing it correctly!
Copy code
@function_tool()
async def my_tool(context: RunContext):
    return SomeAgent(), "Transferring the user to SomeAgent"
• Pro tip: Your tool result needs to be nicely structured, like a well-organized backpack. JSON-serializable is the way to go, and the framework's got your back on handling that
Agent
instance. • One agent handoff at a time is the golden rule – trying to juggle multiple agents is just asking for trouble! Just double-check that you're not accidentally returning any raw or wonky objects. Stick to the format we talked about, and you'll be smooth sailing. If you're still seeing this error after following these steps, don't worry – sometimes there might be a tricky behind-the-scenes issue that needs a closer look. Sources: Tool definition and use | LiveKit Docs | examples/voice_agents/multi_agent.py