Skip to content

Commit 2420b92

Browse files
committed
fixes
1 parent b8eabc5 commit 2420b92

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

evals/test_agent.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ async def test_weather_tool() -> None:
4848
result = await session.run(user_input="What's the weather in Tokyo?")
4949

5050
# Test that the agent calls the weather tool with the correct arguments
51-
result.expect.next_event().is_function_call(name="lookup_weather", arguments={"location": "Tokyo"})
51+
result.expect.next_event().is_function_call(
52+
name="lookup_weather", arguments={"location": "Tokyo"}
53+
)
5254

5355
# Test that the tool invocation works and returns the correct output
5456
# To mock the tool output instead, see https://docs.livekit.io/agents/build/testing/#mock-tools
55-
result.expect.next_event().is_function_call_output(output="sunny with a temperature of 70 degrees.")
57+
result.expect.next_event().is_function_call_output(
58+
output="sunny with a temperature of 70 degrees."
59+
)
5660

5761
# Evaluate the agent's response for accurate weather information
5862
await (
@@ -89,7 +93,8 @@ async def test_weather_unavailable() -> None:
8993
)
9094
result.expect.next_event().is_function_call_output()
9195
await result.expect.next_event(type="message").judge(
92-
llm, intent="Should inform the user that an error occurred and/or the weather is is currently unavailable."
96+
llm,
97+
intent="Should inform the user that an error occurred and/or the weather is is currently unavailable.",
9398
)
9499

95100
# leaving this commented, some LLMs may occasionally try to retry.

src/agent.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import logging
23

34
from dotenv import load_dotenv
@@ -12,6 +13,7 @@
1213
WorkerOptions,
1314
cli,
1415
metrics,
16+
workflows,
1517
)
1618
from livekit.agents.llm import function_tool
1719
from livekit.agents.voice import MetricsCollectedEvent
@@ -48,6 +50,21 @@ async def lookup_weather(self, context: RunContext, location: str):
4850

4951
return "sunny with a temperature of 70 degrees."
5052

53+
@function_tool
54+
async def send_email(self, context: RunContext, subject: str, body: str):
55+
"""Use this tool to send an email on behalf of the user.
56+
57+
Args:
58+
subject: The subject of the email
59+
body: The body of the email
60+
"""
61+
62+
email_result = await workflows.GetEmailAgent(chat_ctx=self.chat_ctx)
63+
send_to_email_address = email_result.email_address
64+
65+
await asyncio.sleep(1) # simulate sending the email
66+
return "Email sent to " + send_to_email_address
67+
5168

5269
def prewarm(proc: JobProcess):
5370
proc.userdata["vad"] = silero.VAD.load()

0 commit comments

Comments
 (0)