Menu
CoddyTech

Support Escalation

Part of the Tools and Agents section of Coddy's AI Engineering journey. Lesson 22 of 22.

challenge icon

Challenge

Hard

Build 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.

  1. Define two tools. track_order: description Track a customer's order by its order number, one required integer property order_number described as The order number. escalate: description Hand the case to a human support agent, one required string property reason described as Why the customer wants help.
  2. track_order returns Order <number>: <status>, or raises ValueError("No order with number <number>"). escalate appends the reason to TICKETS and returns Ticket T<count> opened for a human: <reason>, where the count is the length of TICKETS.
  3. Run the agent loop (model="claude-opus-5-5", max_tokens=500, at most 4 rounds), printing a Tool: line for each call and sending a ValueError back as its message with "is_error": True.
  4. Print Agent: and the reply text.
  5. If a tool raised an error or the loop hit its limit, and no ticket was opened, call escalate yourself with the whole request and print Escalated: and what it returns.
  6. 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: 1

Try 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