51
51
Message ,
52
52
llm_talk ,
53
53
)
54
+ from src .functions .send_agent_event import (
55
+ SendAgentEventInput ,
56
+ send_agent_event ,
57
+ )
54
58
55
59
56
60
class MessagesEvent (BaseModel ):
@@ -73,6 +77,8 @@ class PipelineMetricsEvent(BaseModel):
73
77
metrics : Any
74
78
latencies : str
75
79
80
+ class AgentTwilioInput (BaseModel ):
81
+ phone_number : str | None = None
76
82
77
83
class AgentTwilioOutput (BaseModel ):
78
84
recording_url : str
@@ -176,7 +182,7 @@ async def end(self, end: EndEvent) -> EndEvent:
176
182
text = "Thank you for calling restack. Goodbye!" ,
177
183
),
178
184
)
179
- await agent .sleep (3 )
185
+ await agent .sleep (8 )
180
186
await agent .step (function = livekit_delete_room )
181
187
182
188
self .end = True
@@ -199,7 +205,7 @@ async def pipeline_metrics(
199
205
return pipeline_metrics
200
206
201
207
@agent .run
202
- async def run (self ) -> None :
208
+ async def run (self , agent_input : AgentTwilioInput ) -> AgentTwilioOutput :
203
209
try :
204
210
room = await agent .step (function = livekit_create_room )
205
211
self .room_id = room .name
@@ -222,6 +228,23 @@ async def run(self) -> None:
222
228
),
223
229
)
224
230
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
+
225
248
except Exception as e :
226
249
error_message = f"Error during agent run: { e } "
227
250
raise NonRetryableError (error_message ) from e
0 commit comments