Hand this tutorial to your agent in one click

A key section of this article is locked, and an agent opening the link cannot see it either. Unlock it first, then copy the full text for your agent in one click.

Advanced: Agent Dev 04 Lets the Model Act Through Tool Calls

Developer advanced tutorial: how function calling lets large models use tools, the three things you need to prepare, and what to watch for with errors, state and security when using tools.

Machine translation. Read the original

Tool calling means: you tell the model which functions are available, the model picks one and gives its arguments, your code runs that function, and the result goes back to the model.

Keep these points in mind

  • A tool can be a simple function or a third-party API.
  • The model does not execute anything itself. It only says 'I want to call this function with these arguments'.
  • You need three things: a model that supports function calling, a description of each function (schema), and the real code for each function.
  • Handle errors, validate arguments, and keep track of state.

Going deeper

The flow. Take 'look up what time it is now in a city' as an example:

  1. Send the function description to the model: its name, its purpose, and what parameters it needs.
  2. The user asks 'what time is it in Tokyo now', and the model replies 'call get_time, with city=Tokyo'.
  3. Your code actually runs the function and gets the result.
  4. Send the result back to the model, which then answers you in plain language.

Where it applies. Looking up current data (weather, stock prices, databases); running code for calculations and reports; automated workflows (sending emails, scheduling calendars); customer service looking up tickets; content checks (grammar, summaries, safety).

Don't overlook these. Decide what happens when a tool fails, and have error handling. The model may pass wrong arguments, so validate them first. In multi-turn conversations, remember what was called earlier. And keep tool permissions as narrow as possible, so it cannot do more than it needs.

Full round trip of a function call

Image from the course repository.

Try it yourself

Write a minimal function, for example one that returns the current time. Then write a description telling the model its name, purpose and parameters, and try it with any model that supports function calling to see whether it picks the right one.

Let your agent teach you

Paste the text below into your agent (Claude Code, ChatGPT and Gemini all work), and it will guide you step by step like a mentor.

Sign in to unlock this key section

New accounts get 10 free credits, plus 1 more for each daily check-in. Spend 1 credit to unlock and it stays open for you.

References

Done with this one? Mark it to track your path.Sign in
Save it for laterSign in
Questions about this piece?Ask AI about this

Comments (0)

No comments yet. Start the conversation.

Sign in to join the discussion.Sign in