Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Practical Tool Exercise
Build a set of three tools for a customer support agent: one to look up an order, one to issue a refund, and one to send a confirmation email.
Exercise Instructions
Build three tools for a Customer Support Agent:
1. get_order(order_id: str) -> dict
- Validates that the order ID follows the format 'ORD-XXXXXX'
- Returns order details (status, items, total, purchase_date)
- Returns an error if the order is not found
2. issue_refund(order_id: str, amount: float, reason: str) -> dict
- Validates that amount is positive and less than 1000
- Validates that reason is not empty
- Returns a refund confirmation with reference number
3. send_confirmation(customer_email: str, message: str) -> dict
- Validates the email format
- Returns 'sent' status with timestamp
For each tool, write:
- The function with input validation
- An error response for invalid inputs
- A success response with realistic data
- A print statement testing the tool with a valid call