@@ -148,14 +148,11 @@ async def pre_transferring_to_human_agent(action: dict, flow_manager: FlowManage
148
148
}
149
149
)
150
150
151
- async def queue_post_transferring_to_human_agent (action : dict , flow_manager : FlowManager ):
152
- task = flow_manager .task
153
- await task .queue_frame (PostTransferringToHumanAgentFrame ())
154
-
155
151
# NOTE: this isn't a "real" post-action because it needs to run after the "transferring you to a
156
152
# human agent" speech is actually spoken, not just after sending the LLM the instruction to do so.
157
- async def post_transferring_to_human_agent (transport : DailyTransport ):
153
+ async def post_transferring_to_human_agent (action : dict , flow_manager : FlowManager ):
158
154
"""Post-action after starting transferring to the human agent."""
155
+ transport : DailyTransport = flow_manager .transport
159
156
customer_participant_id = get_customer_participant_id (transport = transport )
160
157
161
158
# Update the customer:
@@ -178,15 +175,12 @@ async def post_transferring_to_human_agent(transport: DailyTransport):
178
175
}
179
176
)
180
177
181
- async def queue_post_end_human_agent_conversation (action : dict , flow_manager : FlowManager ):
182
- task = flow_manager .task
183
- await task .queue_frame (PostEndHumanAgentConversationFrame ())
184
-
185
178
# NOTE: this isn't a "real" post-action because it needs to run after the "I'm patching you through
186
179
# to the customer" speech is actually spoken, not just after sending the LLM the instruction to do
187
180
# so.
188
- async def post_end_human_agent_conversation (transport : DailyTransport ):
181
+ async def post_end_human_agent_conversation (action : dict , flow_manager : FlowManager ):
189
182
"""Post-action after starting to end the conversation with the human agent, when the agent is being patched through to the customer."""
183
+ transport : DailyTransport = flow_manager .transport
190
184
customer_participant_id = get_customer_participant_id (transport = transport )
191
185
agent_participant_id = get_human_agent_participant_id (transport = transport )
192
186
@@ -368,15 +362,14 @@ def create_transferring_to_human_agent_node() -> NodeConfig:
368
362
functions = [],
369
363
pre_actions = [
370
364
ActionConfig (
371
- type = "pre_transferring_to_human_agent " ,
365
+ type = "function " ,
372
366
handler = pre_transferring_to_human_agent
373
- )
367
+ ),
374
368
],
375
369
post_actions = [
376
- # NOTE: "real" post action (post_transferring_to_human_agent) is triggered by CustomControlProcessor
377
370
ActionConfig (
378
- type = "queue_post_transferring_to_human_agent " ,
379
- handler = queue_post_transferring_to_human_agent
371
+ type = "function " ,
372
+ handler = post_transferring_to_human_agent
380
373
)
381
374
]
382
375
)
@@ -443,10 +436,9 @@ def create_end_human_agent_conversation_node() -> NodeConfig:
443
436
],
444
437
functions = [],
445
438
post_actions = [
446
- # NOTE: "real" post action (post_end_human_agent_conversation) is triggered by CustomControlProcessor
447
439
ActionConfig (
448
- type = "queue_post_end_human_agent_conversation " ,
449
- handler = queue_post_end_human_agent_conversation
440
+ type = "function " ,
441
+ handler = post_end_human_agent_conversation
450
442
),
451
443
ActionConfig (type = "end_conversation" )
452
444
]
@@ -543,35 +535,6 @@ async def get_token(user_id: str, permissions: dict, daily_rest_helper: DailyRES
543
535
))
544
536
)
545
537
546
- @dataclass
547
- class PostTransferringToHumanAgentFrame (ControlFrame ):
548
- """
549
- Indicates that the bot has finished speaking the "transferring you to human agent" speech.
550
- """
551
- pass
552
-
553
- @dataclass
554
- class PostEndHumanAgentConversationFrame (ControlFrame ):
555
- """
556
- Indicates that the bot has finished speaking the "I'm patching you through to the customer" speech.
557
- """
558
- pass
559
-
560
- class CustomControlProcessor (FrameProcessor ):
561
- def __init__ (self , transport : DailyTransport ):
562
- super ().__init__ ()
563
- self .__transport = transport
564
-
565
- async def process_frame (self , frame : Frame , direction : FrameDirection ):
566
- await super ().process_frame (frame , direction )
567
-
568
- if isinstance (frame , PostTransferringToHumanAgentFrame ):
569
- await post_transferring_to_human_agent (transport = self .__transport )
570
- elif isinstance (frame , PostEndHumanAgentConversationFrame ):
571
- await post_end_human_agent_conversation (transport = self .__transport )
572
-
573
- await self .push_frame (frame , direction )
574
-
575
538
async def main ():
576
539
"""Main function to set up and run the bot."""
577
540
@@ -596,7 +559,6 @@ async def main():
596
559
voice_id = "820a3788-2b37-4d21-847a-b65d8a68c99a" , # Salesman
597
560
)
598
561
llm = GoogleLLMService (api_key = os .getenv ("GOOGLE_API_KEY" ))
599
- custom_control_processor = CustomControlProcessor (transport = transport )
600
562
601
563
# Initialize context
602
564
context = OpenAILLMContext ()
@@ -611,8 +573,7 @@ async def main():
611
573
llm ,
612
574
tts ,
613
575
transport .output (),
614
- context_aggregator .assistant (),
615
- custom_control_processor
576
+ context_aggregator .assistant ()
616
577
]
617
578
)
618
579
task = PipelineTask (pipeline = pipeline , params = PipelineParams (allow_interruptions = True ))
0 commit comments