agreeable-dream-41746
11/12/2025, 9:08 PMtall-airline-16756
11/12/2025, 9:08 PMtall-airline-16756
11/12/2025, 9:10 PMclass MyAgent(Agent):
@function_tool
async def my_tool(self) -> str:
# Perform the tool call
result = await some_tool_call()
# Check the result and respond accordingly
if result == "g; a":
await self.session.say("a")
return result
In this example, the tool call checks if the result is "g; a" and then uses session.say to say "a". If you’d like, I’m here to walk you through it further or provide more examples—just let me know!
Sources: Tool definition and use | LiveKit docs | Agent speech and audio | LiveKit docs | examples/src/basic_tool_call_agent.ts | agent.py | tests/test_agent_session.pyagreeable-dream-41746
11/12/2025, 9:26 PMtall-airline-16756
11/12/2025, 9:27 PMfrom livekit.agents import function_tool, Agent, RunContext
class MyAgent(Agent):
@function_tool()
async def lookup_weather(
self,
context: RunContext,
location: str,
) -> dict[str, Any]:
"""Look up weather information for a given location.
Args:
location: The location to look up weather information for.
"""
# Simulate weather lookup
result = {"weather": "sunny", "temperature_f": 5}
# Check the temperature and respond accordingly
if result["temperature_f"] == 5:
await context.session.say("It's 5 degrees")
else:
return result
return result
In this example, if the temperature is exactly 5 degrees, the agent will say "It's 5 degrees" using session.say. Otherwise, the tool result will be returned to the agent for further processing. Please feel free to reach out if you'd like any more tweaks or have questions—I'm here to help!
Sources: Agent speech and audio | LiveKit docs | examples/src/realtime_agent.ts | Tool definition and use | LiveKit docsagreeable-dream-41746
11/12/2025, 9:32 PMtall-airline-16756
11/12/2025, 9:32 PMfrom livekit.agents import function_tool, Agent, RunContext
class MyAgent(Agent):
@function_tool()
async def lookup_weather(
self,
context: RunContext,
location: str,
) -> dict[str, Any]:
"""Look up weather information for a given location.
Args:
location: The location to look up weather information for.
"""
# Simulate weather lookup
result = {"weather": "sunny", "temperature_f": 5}
# Check the temperature and respond accordingly
if result["temperature_f"] == 5:
await context.session.say("It's 5 degrees")
else:
return result
return result
# Initialize and run the agent
def main():
agent = MyAgent()
agent.run()
if __name__ == "__main__":
main()
This snippet includes the MyAgent class initialization along with the main function to launch the agent. If you have any questions or need help tweaking it, please feel free to ask—I’m here to help!agreeable-dream-41746
11/12/2025, 9:44 PMtall-airline-16756
11/12/2025, 9:45 PMfrom livekit.agents import function_tool, Agent, RunContext
class MyAgent(Agent):
def __init__(self):
super().__init__(instructions="You are a helpful assistant that provides weather information.")
@function_tool()
async def lookup_weather(
self,
context: RunContext,
location: str,
) -> dict[str, Any]:
"""Look up weather information for a given location.
Args:
location: The location to look up weather information for.
"""
# Simulate weather lookup
result = {"weather": "sunny", "temperature_f": 5}
# Check the temperature and respond accordingly
if result["temperature_f"] == 5:
await context.session.say("It's 5 degrees")
else:
return result
return result
# Initialize and run the agent
def main():
agent = MyAgent()
agent.run()
if __name__ == "__main__":
main()
The instructions parameter inside the MyAgent class constructor acts as the agent's prompt, gently guiding how it behaves and responds. If you’d like me to walk you through any part of this or help with further tweaks, just let me know—I’m here to help!