|
|
Claude Tool Use - Function Calling
Author: Venkata Sudhakar
Claude tool use lets you give the model access to your own business functions - stock checkers, order systems, customer databases, pricing APIs - so it can look up real data before answering rather than guessing. You define each tool as a JSON schema describing its name, purpose, and parameters. Claude decides when to call a tool based on the conversation, returns a structured tool_use block with the arguments it wants to pass, your code executes the function and sends the result back, and Claude incorporates the real data into its final answer. This is the foundation of any Claude-powered business agent. The tool use flow has four steps: send messages with tools defined, receive a response where stop_reason is "tool_use", execute the requested tool locally, then send the tool result back in a new message with role "user" and type "tool_result". Claude then continues the conversation with the real data. A single response can request multiple tool calls simultaneously - Claude is smart enough to call stock_check for several items at once rather than one at a time, reducing round trips. The below example shows a retail assistant that can check stock levels and place orders. A customer asks about buying laptops for their office and Claude autonomously checks availability before recommending.
Running the tool use loop with a real customer conversation,
It gives the following output showing the tool call loop,
Customer: I need 6 Dell XPS 15 laptops for my office team. Are they available?
[Tool call] check_stock({"product_name": "Dell XPS 15", "warehouse": "main"})
[Tool result] {"product": "Dell XPS 15", "warehouse": "main", "quantity": 8, "available": True}
Claude: Great news! We have 8 Dell XPS 15 units in stock at our main warehouse,
so we can fulfil your order of 6 units comfortably. Would you like me to go
ahead and place the order? If so, I can confirm delivery in 3-5 business days.
# Claude checked stock BEFORE answering - grounded in real data, not a guess
# If you say "yes please order them", Claude calls place_order next
Tool design tips: write clear tool descriptions because Claude reads them to decide when and whether to call each tool. Include "only call this if..." phrases for consequential tools like place_order or send_email to prevent accidental execution. Define required vs optional parameters carefully - Claude will always provide required fields but may omit optional ones. For tools that modify data, log every tool call and result in your database before returning the result to Claude so you have a full audit trail of what the agent did and why.
|
|