Support Escalation
Part of the Tools and Agents section of Coddy's AI Engineering journey. Lesson 22 of 22.
Challenge
HardBuild a support agent that tracks orders and hands a case to a person when it cannot help. The starter holds ORDERS, an empty list TICKETS and reads the request.
- Define two tools.
track_order: descriptionTrack a customer's order by its order number, one required integer propertyorder_numberdescribed asThe order number.escalate: descriptionHand the case to a human support agent, one required string propertyreasondescribed asWhy the customer wants help. track_orderreturnsOrder <number>: <status>, or raisesValueError("No order with number <number>").escalateappends the reason toTICKETSand returnsTicket T<count> opened for a human: <reason>, where the count is the length ofTICKETS.- Run the agent loop (
model="claude-opus-5-5",max_tokens=500, at most 4 rounds), printing aTool:line for each call and sending aValueErrorback as its message with"is_error": True. - Print
Agent:and the reply text. - If a tool raised an error or the loop hit its limit, and no ticket was opened, call
escalateyourself with the whole request and printEscalated:and what it returns. - Print
Tickets:and the number of tickets.
For example, for the input Where is order 9999? the program prints:
Tool: track_order {'order_number': 9999}
Agent: Sorry, I could not finish: No order with number 9999
Escalated: Ticket T1 opened for a human: Where is order 9999?
Tickets: 1Try it yourself
import coddy_ai as anthropic # in production: import anthropic
client = anthropic.Anthropic()
ORDERS = {
1042: "shipped, arriving Friday",
2077: "delayed at the warehouse",
3155: "delivered on Monday",
}
TICKETS = []
request = input()
# Write your code below
All lessons in Tools and Agents
Practice on your own: Online Python compiler