Skip to content

Commit 1bf926b

Browse files
tsutingtsuting.kaomoonbox3Copilot
authored
Python: Fix the example of multi-tier handoff workflow with specialist-to-specialist routing (#2332)
* Fix the example (1) to send only one initial message (2) to end conversation after trigger the last response as the comment describes * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * changed the hard-coded user query --------- Co-authored-by: tsuting.kao <[email protected]> Co-authored-by: Evan Mattson <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent d18ce24 commit 1bf926b

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

python/samples/getting_started/workflows/orchestration/handoff_specialist_to_specialist.py

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ async def main() -> None:
166166
.add_handoff(triage, [replacement, delivery, billing]) # Triage can route to any specialist
167167
.add_handoff(replacement, [delivery, billing]) # Replacement can delegate to delivery or billing
168168
.add_handoff(delivery, billing) # Delivery can escalate to billing
169-
# Termination condition: Stop when more than 4 user messages exist.
170-
# This allows agents to respond to the 4th user message before the 5th triggers termination.
171-
# In this sample: initial message + 3 scripted responses = 4 messages, then 5th message ends workflow.
172-
.with_termination_condition(lambda conv: sum(1 for msg in conv if msg.role.value == "user") > 4)
169+
# Termination condition: Stop when more than 3 user messages exist.
170+
# This allows agents to respond to the 3rd user message before the 4th triggers termination.
171+
# In this sample: initial message + 3 scripted responses = 4 messages, then workflow ends.
172+
.with_termination_condition(lambda conv: sum(1 for msg in conv if msg.role.value == "user") > 3)
173173
.build()
174174
)
175175

@@ -192,14 +192,12 @@ async def main() -> None:
192192
print("=" * 80 + "\n")
193193

194194
# Start workflow with initial message
195-
print("[User]: I need help with order 12345. I want a replacement and need to know when it will arrive.\n")
196-
events = await _drain(
197-
workflow.run_stream("I need help with order 12345. I want a replacement and need to know when it will arrive.")
198-
)
195+
print(f"[User]: {scripted_responses[0]}\n")
196+
events = await _drain(workflow.run_stream(scripted_responses[0]))
199197
pending_requests = _handle_events(events)
200198

201199
# Process scripted responses
202-
response_index = 0
200+
response_index = 1
203201
while pending_requests and response_index < len(scripted_responses):
204202
user_response = scripted_responses[response_index]
205203
print(f"\n[User]: {user_response}\n")
@@ -227,56 +225,56 @@ async def main() -> None:
227225
=== User Input Requested ===
228226
Last 5 messages in conversation:
229227
user: I need help with order 12345. I want a replacement and need to know when it will arrive.
230-
triage_agent: I'm connecting you to our replacement team to assist with your request, and to our delivery team for...
231-
replacement_agent: To assist with your replacement for order 12345 and provide tracking details for delivery, I've reac...
232-
delivery_agent: I'm handing over your request for a replacement of order 12345, as well as your inquiry about estima...
233-
billing_agent: I handle billing and payment questions. For replacement and delivery details for order 12345, please...
228+
triage_agent: I am connecting you to our replacement agent to assist with your replacement request and to our deli...
229+
replacement_agent: I have connected you to our agents who will assist with your replacement request for order 12345 and...
230+
delivery_agent: For your replacement request and delivery details regarding order 12345, I'll connect you to the app...
231+
billing_agent: I don’t have access to order details. Please contact the seller or customer service directly for rep...
234232
============================
235233
[status] IDLE_WITH_PENDING_REQUESTS
236234
237-
[User]: I need help with order 12345. I want a replacement and need to know when it will arrive.
235+
[User]: The item arrived damaged. I'd like a replacement shipped to the same address.
238236
239237
240238
=== User Input Requested ===
241-
Last 7 messages in conversation:
242-
replacement_agent: To assist with your replacement for order 12345 and provide tracking details for delivery, I've reac...
243-
delivery_agent: I'm handing over your request for a replacement of order 12345, as well as your inquiry about estima...
244-
billing_agent: I handle billing and payment questions. For replacement and delivery details for order 12345, please...
245-
user: I need help with order 12345. I want a replacement and need to know when it will arrive.
246-
triage_agent: I'm connecting you with our replacement team to help with your request, and our delivery team for in...
239+
Last 8 messages in conversation:
240+
delivery_agent: For your replacement request and delivery details regarding order 12345, I'll connect you to the app...
241+
billing_agent: I don’t have access to order details. Please contact the seller or customer service directly for rep...
242+
user: The item arrived damaged. I'd like a replacement shipped to the same address.
243+
triage_agent: I'm connecting you to our replacement agent who will assist you with getting a replacement shipped t...
244+
replacement_agent: Thank you for the info. I'll start the replacement process for your damaged item on order 12345 and ...
247245
============================
248246
[status] IDLE_WITH_PENDING_REQUESTS
249247
250-
[User]: The item arrived damaged. I'd like a replacement shipped to the same address.
248+
[User]: Great! Can you confirm the shipping cost won't be charged again?
251249
252250
253251
=== User Input Requested ===
254-
Last 12 messages in conversation:
255-
user: The item arrived damaged. I'd like a replacement shipped to the same address.
256-
triage_agent: Thank you for letting us know your item from order 12345 arrived damaged. Im connecting you to our ...
257-
replacement_agent: Your replacement request for order 12345 (damaged item) will be processed, and shipped to your curre...
258-
delivery_agent: I've forwarded your request for a replacement of the damaged item from order 12345 to our team and a...
259-
billing_agent: Thank you for the information. I've forwarded your request to our support team to arrange a replacem...
252+
Last 11 messages in conversation:
253+
triage_agent: I'm connecting you to our replacement agent who will assist you with getting a replacement shipped t...
254+
replacement_agent: Thank you for the info. I'll start the replacement process for your damaged item on order 12345 and ...
255+
user: Great! Can you confirm the shipping cost won't be charged again?
256+
triage_agent: I'm connecting you to our billing agent who can confirm whether the shipping cost will be charged ag...
257+
billing_agent: Replacements for damaged items are typically shipped at no extra shipping cost. I recommend confirmi...
260258
============================
261259
[status] IDLE_WITH_PENDING_REQUESTS
262260
263-
[User]: Great! Can you confirm the shipping cost won't be charged again?
261+
[User]: Thank you!
264262
265263
266264
=== Final Conversation ===
267265
- user: I need help with order 12345. I want a replacement and need to know when it will arrive.
268-
- triage_agent: I'm connecting you to our replacement team to assist with your request, and to our delivery team for updates on when your replacement will arrive. They'll help you shortly!
269-
- replacement_agent: To assist with your replacement for order 12345 and provide tracking details for delivery, I've reached out to our teams. Can you please provide the reason for your replacement request? This will help to process things faster.
270-
- delivery_agent: I'm handing over your request for a replacement of order 12345, as well as your inquiry about estimated delivery timing, to the appropriate team. They'll assist you further with the replacement and delivery details very soon.
271-
- billing_agent: I handle billing and payment questions. For replacement and delivery details for order 12345, please contact our support team or the order department. Is there a billing or payment issue I can help you with?
272-
- user: I need help with order 12345. I want a replacement and need to know when it will arrive.
273-
- triage_agent: I'm connecting you with our replacement team to help with your request, and our delivery team for information about when your replacement will arrive. They'll assist you shortly!
266+
- triage_agent: I am connecting you to our replacement agent to assist with your replacement request and to our delivery agent who can provide information on the arrival of your replacement. They will help you shortly!
267+
- replacement_agent: I have connected you to our agents who will assist with your replacement request for order 12345 and provide shipping and delivery information. They will help you with the details shortly. If you have any other questions, feel free to ask!
268+
- delivery_agent: For your replacement request and delivery details regarding order 12345, I'll connect you to the appropriate agent who can assist with both billing and delivery concerns. They will provide you with the estimated arrival date and replacement process. Is there anything else you'd like to know meanwhile?
269+
- billing_agent: I don’t have access to order details. Please contact the seller or customer service directly for replacement and delivery info on order 12345. If you need help with billing, refunds, or payments, I can assist!
274270
- user: The item arrived damaged. I'd like a replacement shipped to the same address.
275-
- triage_agent: Thank you for letting us know your item from order 12345 arrived damaged. I'm connecting you to our replacement team to arrange a replacement shipped to your address, and to our delivery team to update you on the arrival date of your replacement. They'll assist you shortly!
276-
- replacement_agent: Your replacement request for order 12345 (damaged item) will be processed, and shipped to your current address. The delivery team will also provide tracking and estimated arrival details for your new item soon.
277-
- delivery_agent: I've forwarded your request for a replacement of the damaged item from order 12345 to our team and asked them to ship it to your current address. You'll also receive tracking information and an estimated delivery date for the replacement soon.
278-
- billing_agent: Thank you for the information. I've forwarded your request to our support team to arrange a replacement for the damaged item from order 12345. Your replacement will be shipped to the same address, and you'll receive delivery updates soon. If you need a refund instead or have any billing questions, please let me know.
271+
- triage_agent: I'm connecting you to our replacement agent who will assist you with getting a replacement shipped to the same address for the damaged item. They will help you shortly!
272+
- replacement_agent: Thank you for the info. I'll start the replacement process for your damaged item on order 12345 and arrange to ship it to the same address. Please hold on a moment while I proceed.
273+
Thank you for providing the reason. I will process a replacement for the damaged item from order 12345 and arrange the shipment to the same address. Please hold on a moment while I take care of this.
279274
- user: Great! Can you confirm the shipping cost won't be charged again?
275+
- triage_agent: I'm connecting you to our billing agent who can confirm whether the shipping cost will be charged again for the replacement of your damaged item. They will assist you shortly!
276+
- billing_agent: Replacements for damaged items are typically shipped at no extra shipping cost. I recommend confirming with the replacements or billing department to be sure. Let me know if you’d like me to connect you!
277+
- user: Thank you!
280278
==========================
281279
[status] IDLE
282280
""" # noqa: E501

0 commit comments

Comments
 (0)