Elffuss BraidHub

kikocis/Based-Agent public

96fe88dcefb1 · 1.4 KiBRawPermalink
1from swarm import Agent
2
3
4def 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
10def apply_discount():
11 """Apply a discount to the user's cart."""
12 print("[mock] Applying discount...")
13 return "Applied discount of 11%"
14
15
16triage_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)
20sales_agent = Agent(
21 name="Sales Agent",
22 instructions="Be super enthusiastic about selling bees.",
23)
24refunds_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
31def 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
36def transfer_to_sales():
37 return sales_agent
38
39
40def transfer_to_refunds():
41 return refunds_agent
42
43
44triage_agent.functions = [transfer_to_sales, transfer_to_refunds]
45sales_agent.functions.append(transfer_back_to_triage)
46refunds_agent.functions.append(transfer_back_to_triage)