Careeroza
Real World Example
Order Support with the Tool Runner
Swiggy, Zomato and Razorpay support assistants look up orders, payments and refunds through tools, and only humans approve risky actions. The ShopEase version with the SDK's tool runner, which runs the tool loop for you:
import json
import anthropic
from anthropic import beta_tool
client = anthropic.Anthropic()
@beta_tool
def get_order_status(order_id: str) -> str:
"""Get the live status of a ShopEase order. Call this whenever the customer asks about an order.
Args:
order_id: Order ID like SE-10423.
"""
return json.dumps(db.get_order(order_id) or {"error": "not found"})
@beta_tool
def search_products(query: str, max_price: int = 100000) -> str:
"""Search the ShopEase catalogue. Call this when the customer wants product suggestions.
Args:
query: What the customer is looking for.
max_price: Maximum price in rupees.
"""
return json.dumps(product_search(query, max_price))
runner = client.beta.messages.tool_runner(
model="claude-sonnet-5-5",
max_tokens=2000,
system="You are the ShopEase support assistant. Use tools for any order or product facts.",
tools=[get_order_status, search_products],
messages=[{"role": "user", "content": "Has SE-10423 shipped? Also suggest socks under 300 to go with the shoes."}],
)
for message in runner: # one message per model turn; tools run in between
final = message
print(next(b.text for b in final.content if b.type == "text"))Run it
python support_tools.pyExample output
Yes! Order SE-10423 shipped yesterday and is out for delivery today. Socks under Rs 300 that go well with running shoes: - ShopEase DryFit ankle socks, pack of 3 - Rs 249 - CushionRun low-cut sports socks - Rs 199
Exercise
Exercise: Add a cancel_order tool, but the model must never cancel without the customer saying "yes". Where do you enforce this?
Show answer
Enforce it in code, not only in the prompt:
- The cancel_order tool does NOT cancel. It returns
{"needs_confirmation": true, "summary": "Cancel SE-10423 (Rs 2,499)?"}.
- The UI shows Yes/No buttons. Only a real "Yes" click calls the
backend's cancel endpoint (with the user's auth), outside the model.
- Log every tool call with the user id for audit.