dazzling-truck-32153
08/30/2025, 9:38 PM@function_tool
async def verify_code(self, ctx: RunContext[InsuranceSessionInfo], spoken_verification_code: str) -> str:
"""Use this tool verify code, covert user input to alphan-umeric characters. If it matches call discover_questions function"""
await self.update_frontend()
ctx.session.say("OK, can I get the code please?")
result = await verify_spoken_code(spoken_verification_code)
if result == True:
return f"Say: Thanks for providing the verification code! then call discovery_questions function"
else:
return ctx.session.say("Sorry I cant I get that code again please...")tall-airline-16756
08/30/2025, 9:38 PMtall-airline-16756
08/30/2025, 9:39 PMgenerate_reply() method in AgentSession is great for handling what the user says and crafting responses.
• Trigger Function Tools: Create tools with the @function_tool decorator. These tools can kick in based on what the user says, run specific tasks, and send back results.
• Progress to the Next Step: Once you’ve processed the input, you can call another function or switch to a new agent. For example, returning a new agent instance inside a tool function helps keep your workflow modular and smooth.
Here’s a simple example of how this flow works:
class GreetingAgent(Agent):
async def on_enter(self):
self.session.say("Hello! What's your name?")
@function_tool
async def collect_name(self, name: str):
await self.session.say(f"Nice to meet you, {name}! What's your favorite color?")
return ColorAgent(name=name) # Proceeds to next agent
This setup helps keep the conversation natural and easy to follow. If you want me to walk you through any part or have questions, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/agent_activity.py | examples/src/restaurant_agent.ts | Testing and evaluation | LiveKit Docs | flows/simple_flow.pydazzling-truck-32153
08/30/2025, 9:42 PMtall-airline-16756
08/30/2025, 9:43 PM@function_tool decorator to create a tool that handles user input and carries out the logic you want.
• Update State or Context: Use session.state for straightforward state tracking or session.userdata if you need to manage more detailed session-wide data. This helps the agent remember what it needs for the next step.
• Generate the Next Step: Once the tool runs, the agent can automatically create the next response with generate_reply() or keep the conversation going based on the updated context.
• Handle Errors Gracefully: Make sure your tools can deal with invalid inputs or missing info smoothly, so everything runs without a hitch.
Here’s an example to illustrate:
class DataCollectorAgent(BaseAgent):
async def on_enter(self):
await self.session.say("Please provide the code.")
@function_tool
async def verify_code(self, code: str):
if code == "1234":
await self.session.say("Code verified! Proceeding to the next step.")
else:
await self.session.say("Invalid code. Please try again.")
This way, the flow stays inside the same agent, making your multi-step interaction feel smooth and natural. If you want me to walk you through any part or have questions, just let me know—I’m here to help!
Sources: complex-agents/drive-thru/test_agent.py | examples/drive-thru/test_agent.py | examples/src/restaurant_agent.tsdazzling-truck-32153
08/30/2025, 9:45 PM