Skip to content

Commit a7567b6

Browse files
committed
allow direct phone number and output recording url
1 parent ec2ea1c commit a7567b6

File tree

1 file changed

+25
-2
lines changed
  • agent_telephony/twilio_livekit/agent_twilio/src/agents

1 file changed

+25
-2
lines changed

agent_telephony/twilio_livekit/agent_twilio/src/agents/agent.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
Message,
5252
llm_talk,
5353
)
54+
from src.functions.send_agent_event import (
55+
SendAgentEventInput,
56+
send_agent_event,
57+
)
5458

5559

5660
class MessagesEvent(BaseModel):
@@ -73,6 +77,8 @@ class PipelineMetricsEvent(BaseModel):
7377
metrics: Any
7478
latencies: str
7579

80+
class AgentTwilioInput(BaseModel):
81+
phone_number: str | None = None
7682

7783
class AgentTwilioOutput(BaseModel):
7884
recording_url: str
@@ -176,7 +182,7 @@ async def end(self, end: EndEvent) -> EndEvent:
176182
text="Thank you for calling restack. Goodbye!",
177183
),
178184
)
179-
await agent.sleep(3)
185+
await agent.sleep(8)
180186
await agent.step(function=livekit_delete_room)
181187

182188
self.end = True
@@ -199,7 +205,7 @@ async def pipeline_metrics(
199205
return pipeline_metrics
200206

201207
@agent.run
202-
async def run(self) -> None:
208+
async def run(self, agent_input: AgentTwilioInput) -> AgentTwilioOutput:
203209
try:
204210
room = await agent.step(function=livekit_create_room)
205211
self.room_id = room.name
@@ -222,6 +228,23 @@ async def run(self) -> None:
222228
),
223229
)
224230

231+
if agent_input.phone_number:
232+
233+
agent_id = agent_info().workflow_id
234+
run_id = agent_info().run_id
235+
236+
await agent.step(
237+
function=send_agent_event,
238+
function_input=SendAgentEventInput(
239+
event_name="call",
240+
agent_id=agent_id,
241+
run_id=run_id,
242+
event_input={
243+
"phone_number": agent_input.phone_number,
244+
},
245+
),
246+
)
247+
225248
except Exception as e:
226249
error_message = f"Error during agent run: {e}"
227250
raise NonRetryableError(error_message) from e

0 commit comments

Comments
 (0)