From 2420b92dc73c5eafa5ba3f1e675163706e597a23 Mon Sep 17 00:00:00 2001 From: Ben Cherry Date: Thu, 10 Jul 2025 17:26:30 -0700 Subject: [PATCH] fixes --- evals/test_agent.py | 11 ++++++++--- src/agent.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/evals/test_agent.py b/evals/test_agent.py index 4ec7a85..5111896 100644 --- a/evals/test_agent.py +++ b/evals/test_agent.py @@ -48,11 +48,15 @@ async def test_weather_tool() -> None: result = await session.run(user_input="What's the weather in Tokyo?") # Test that the agent calls the weather tool with the correct arguments - result.expect.next_event().is_function_call(name="lookup_weather", arguments={"location": "Tokyo"}) + result.expect.next_event().is_function_call( + name="lookup_weather", arguments={"location": "Tokyo"} + ) # Test that the tool invocation works and returns the correct output # To mock the tool output instead, see https://docs.livekit.io/agents/build/testing/#mock-tools - result.expect.next_event().is_function_call_output(output="sunny with a temperature of 70 degrees.") + result.expect.next_event().is_function_call_output( + output="sunny with a temperature of 70 degrees." + ) # Evaluate the agent's response for accurate weather information await ( @@ -89,7 +93,8 @@ async def test_weather_unavailable() -> None: ) result.expect.next_event().is_function_call_output() await result.expect.next_event(type="message").judge( - llm, intent="Should inform the user that an error occurred and/or the weather is is currently unavailable." + llm, + intent="Should inform the user that an error occurred and/or the weather is is currently unavailable.", ) # leaving this commented, some LLMs may occasionally try to retry. diff --git a/src/agent.py b/src/agent.py index 99039ad..45a2826 100644 --- a/src/agent.py +++ b/src/agent.py @@ -1,3 +1,4 @@ +import asyncio import logging from dotenv import load_dotenv @@ -12,6 +13,7 @@ from livekit.agents import ( WorkerOptions, cli, metrics, + workflows, ) from livekit.agents.llm import function_tool from livekit.agents.voice import MetricsCollectedEvent @@ -48,6 +50,21 @@ class Assistant(Agent): return "sunny with a temperature of 70 degrees." + @function_tool + async def send_email(self, context: RunContext, subject: str, body: str): + """Use this tool to send an email on behalf of the user. + + Args: + subject: The subject of the email + body: The body of the email + """ + + email_result = await workflows.GetEmailAgent(chat_ctx=self.chat_ctx) + send_to_email_address = email_result.email_address + + await asyncio.sleep(1) # simulate sending the email + return "Email sent to " + send_to_email_address + def prewarm(proc: JobProcess): proc.userdata["vad"] = silero.VAD.load()