| 1 | from swarm import Agent |
| 2 | |
| 3 | |
| 4 | def process_refund(item_id, reason="NOT SPECIFIED"): |
| 5 | """Refund an item. Refund an item. Make sure you have the item_id of the form item_... Ask for user confirmation before processing the refund.""" |
| 6 | print(f"[mock] Refunding item {item_id} because {reason}...") |
| 7 | return "Success!" |
| 8 | |
| 9 | |
| 10 | def apply_discount(): |
| 11 | """Apply a discount to the user's cart.""" |
| 12 | print("[mock] Applying discount...") |
| 13 | return "Applied discount of 11%" |
| 14 | |
| 15 | |
| 16 | triage_agent = Agent( |
| 17 | name="Triage Agent", |
| 18 | instructions="Determine which agent is best suited to handle the user's request, and transfer the conversation to that agent.", |
| 19 | ) |
| 20 | sales_agent = Agent( |
| 21 | name="Sales Agent", |
| 22 | instructions="Be super enthusiastic about selling bees.", |
| 23 | ) |
| 24 | refunds_agent = Agent( |
| 25 | name="Refunds Agent", |
| 26 | instructions="Help the user with a refund. If the reason is that it was too expensive, offer the user a refund code. If they insist, then process the refund.", |
| 27 | functions=[process_refund, apply_discount], |
| 28 | ) |
| 29 | |
| 30 | |
| 31 | def transfer_back_to_triage(): |
| 32 | """Call this function if a user is asking about a topic that is not handled by the current agent.""" |
| 33 | return triage_agent |
| 34 | |
| 35 | |
| 36 | def transfer_to_sales(): |
| 37 | return sales_agent |
| 38 | |
| 39 | |
| 40 | def transfer_to_refunds(): |
| 41 | return refunds_agent |
| 42 | |
| 43 | |
| 44 | triage_agent.functions = [transfer_to_sales, transfer_to_refunds] |
| 45 | sales_agent.functions.append(transfer_back_to_triage) |
| 46 | refunds_agent.functions.append(transfer_back_to_triage) |