wooden-smartphone-55787
09/24/2025, 4:35 AMtall-airline-16756
09/24/2025, 4:35 AMtall-airline-16756
09/24/2025, 4:35 AM@session.on("function_tools_executed") event. It doesn’t directly give you access to agent custom properties, but no worries—you can use session.userdata to store and retrieve those custom properties while your tools are running, and then easily access them in the event handler.
Here’s a simple example to guide you:
from livekit.agents import Agent, RunContext, function_tool
class WeatherAgent(Agent):
def __init__(self):
super().__init__()
self.session.userdata["last_action"] = None
@function_tool()
async def get_weather(self, context: RunContext, location: str):
context.userdata["last_action"] = f"weather lookup for {location}"
return {"weather": "sunny", "temp": 75}
@session.on("function_tools_executed")
def on_tools_executed(ev):
last_action = session.userdata.get("last_action")
print(f"Last agent action: {last_action}")
if "weather" in last_action:
ev.cancel_tool_reply()
Using this approach lets you smoothly coordinate your custom properties across different tools and event handlers. If you have any questions or want to explore this further, feel free to ask—I’m here to help!
Sources: livekit-agents/livekit/agents/telemetry/trace_types.py | Tool definition and use | LiveKit Docs | Events and error handling | LiveKit Docs