|
|
Claude Tool Use - Function Calling with Claude
Author: Venkata Sudhakar
Tool use (function calling) lets Claude invoke external functions to fetch real data rather than relying on training knowledge alone. For ShopMax India, tool use powers agents that look up live order status, check inventory, and retrieve product pricing from backend systems. Claude decides which tool to call based on the user query, sends back a structured tool_use block, and the application executes the function and returns the result to complete the response.
The tool use flow has three steps: (1) send the user message along with a tools list defining each function name, description, and input schema; (2) Claude responds with a tool_use content block containing the tool name and input arguments; (3) the application calls the actual function and sends back a tool_result block. Claude then generates the final natural language response using the returned data. The stop_reason tool_use signals that Claude wants to call a function before finishing.
The following example builds a ShopMax India order status agent. Claude uses the get_order_status tool to look up live order data and returns a customer-friendly reply:
It gives the following output,
Great news! Your order ORD-MUM-4421 is out for delivery in Mumbai and is expected
to arrive today by 5 PM. Keep your phone handy for the delivery agent's call!
Yes, your order ORD-DEL-1234 has been successfully delivered in Delhi on May 5.
If you have not received it or have any issues, please contact ShopMax India support.
In ShopMax India production agents, always validate tool inputs before executing them - check that order_id matches the expected format before hitting the database. Add a max loop counter (e.g. max 5 iterations) to the while loop to prevent infinite tool call chains if Claude gets stuck. Log every tool call with its inputs and outputs for debugging; tool calls are the most common source of latency in Claude agent pipelines. For tools that mutate state (placing orders, processing refunds), add a confirmation step before execution - send the tool result back to Claude with a note asking it to confirm with the user before finalizing.
|
|