SproutStackSproutStack home

From Text Generation to Action

6 min readBeginner-friendlyFree to read

Read a little, play a little. No scary maths, and no rush.

Share:

Answers are nice; actions pay the bills

"What's my order status?" can't be answered from training data — it needs a live lookup. Tool calling (function calling) lets the model act: it emits a structured request like "call get_order with id 12847," your code runs it, and the result flows back into the conversation. Text generation becomes a control plane for real systems.

The schema is the UI (for the model)

The model never sees your code — only a JSON description. So the description is the interface: name it like a verb, describe exactly when to use it, and type every parameter:

{
  "name": "get_order",
  "description": "Fetch live order status. Use when the user gives an order id.",
  "parameters": {
    "type": "object",
    "properties": { "id": { "type": "string" } },
    "required": ["id"]
  }
}

Vague descriptions ("handles orders") produce vague behavior (calling it for returns, refunds, and weather). Precise descriptions produce precise calls.

The loop, step by step

  1. User asks something needing live data or action.
  2. Model replies with a tool call (not text).
  3. Your code executes it — real API, real database, real side effects.
  4. The observation goes back into context; the model composes the final answer.

Try /animations/tool-calling to watch it move.

One request, end to end

A user writes: "Where's my order 12847?"

  1. The model sees the get_order description and replies with a tool call: get_order(id="12847").
  2. Your code checks the arguments before running anything: is this a plausible order ID, and does it belong to this user? Then it queries the order system.
  3. The result, {"status": "shipped", "eta": "Oct 12"}, goes back to the model as a tool message.
  4. The model answers: "Your order has shipped and should arrive on October 12."

If the lookup fails, return the error as the tool result, for example {"error": "order not found"}, rather than crashing. The model can then explain the problem to the user or ask them to double-check the number.

Several calls at once

Models can request more than one tool call in a single turn, such as checking an order and a refund status together. Your code runs them, concurrently if they are independent, and returns every result before the model writes its answer.

Safety rails before side effects

Read-only tools (lookups, search) can run freely. Anything that changes the world — refunds, deletes, sends — needs rails: human approval above a threshold, idempotency keys so retries don't double-charge, least-privilege credentials per tool, and a full audit log of who called what with which arguments.

How many tools is too many?

Every tool's description is sent with every request, so tools cost input tokens even when unused. More importantly, a model choosing among fifty similar tools picks the wrong one more often than a model choosing among five. Keep tool names and descriptions clearly distinct, merge near-duplicates, and when you genuinely need many tools, route first: a quick classification decides which small group of tools this request can see.

Remember this

  • Describe tools like you'd brief a clever intern: when, with what, and what never.
  • Reads run free; writes need approval, idempotency, and logs.

Check your understanding

5 questions · first-try answers earn the most XP

1. A tool description says "handles orders". What problem does that cause?
2. Why do write operations need extra safeguards while read operations do not?
3. Why should each tool get least-privilege credentials rather than sharing one key?
4. What happens after the model emits a tool call, before it answers the user?
5. Why does the chapter compare briefing a tool to briefing a clever intern?

My notes

Saved in this browser. Highlight a line above and save it, or write it in your own words.

Nothing saved yet. Your highlights will live here.

References

Finished reading?

Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.

Practice this in an incident

Related chapters

Spotted a mistake or want a topic covered? Report an issue

📬 An occasional email when new lessons land

New lessons and showdowns, no more than a few times a month. No spam, unsubscribe anytime. We store your email only to send the newsletter.