few-soccer-7112
07/11/2025, 4:53 AMtall-airline-16756
07/11/2025, 4:53 AMtall-airline-16756
07/11/2025, 4:57 AMchat_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 Docsfew-soccer-7112
07/11/2025, 5:02 AMtall-airline-16756
07/11/2025, 5:04 AM@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