Claude on WholeTech network
home/products/tool-use
Function calling

Tool Use shipping

Function calling. Define tools in JSON schema; Claude decides when to call them; you execute and return.

01 — What it is

The primitive under everything.

You give Claude a list of tools (a name, a description, a JSON schema for the inputs). Claude decides when to call them and returns the calls structurally. You execute them in your code and return the results. Loop until Claude returns plain text.

Agent SDK, MCP, Computer Use, Claude Code, your-own-agent — all built on this.

02 — What it's for

Three jobs.

Connect Claude to real systems

Database queries, API calls, web fetches, email sends. Anything you can wrap in a function.

Force structured output

Define a tool with a strict JSON schema. Claude responds in that shape — no parsing prose.

Build agents

The loop is: model returns a tool call → you run it → return the result → model decides what's next.

03 — First tool

Sketch one.

  1. Describe the tool in JSON schema — name, what it does, what parameters.
  2. Pass it in tools=[…] on the message create call.
  3. If Claude returns a tool_use block, run the tool and return a tool_result block in the next message.
  4. Loop until Claude returns plain text — that's the final answer.
tools = [{
  "name": "get_weather",
  "description": "Get the current weather for a city.",
  "input_schema": {
    "type": "object",
    "properties": {"city": {"type":"string"}},
    "required": ["city"]
  }
}]

msg = client.messages.create(
  model="claude-sonnet-4-6",
  max_tokens=1024,
  tools=tools,
  messages=[{"role":"user","content":"What's the weather in Hot Springs?"}],
)
04 — The loop

Until plain text comes back.

Tool-using conversations alternate: user → assistant (tool_use) → user (tool_result) → assistant (tool_use or text). When the assistant returns text, you're done. If you forget to return tool_results, the model can't continue.

05 — Patterns

Shapes you'll reach for.