liveBook · Manning

Tool usage

As explained in AI Agents and Applications

A tool call is a structured model response that requests invocation of a named tool with supplied arguments.

A travel assistant may need destination information, a weather forecast, or both. Tool usage lets the assistant choose a capability as the question unfolds instead of following a fixed sequence of API calls. A tool is an external function, service, or capability exposed to the model. A tool call is the model’s structured request to use a named tool with arguments; the application executes that request and returns the result. section 11.2.1 section 11.2.3

The basic loop has four parts:

  • Define a tool with a name, description, and parameter schema. A Python function decorated with @tool can expose those details to the model. section 11.2.2 section 11.2.3
  • Register the available tools. LangChain’s bind_tools(TOOLS) handles registration; the OpenAI API also accepts an explicit tool definition. section 11.2.3
  • Send the conversation to the model. Its response may contain a final answer or one or more entries in tool_calls, each naming a tool and supplying arguments. section 11.2.6 section 11.6.1
  • Route tool calls to an execution node, invoke the requested functions, and add their results as ToolMessages. Give those messages back to the model so it can answer or request another tool. section 11.6.1 section 11.4
   AIMessage(content=[],
...
tool_calls=[
{'name': 'search_travel_info', 'args': {'query': 'beach towns in Cornwall'}, 'id': 'call_L4PwmeyLkrkYX2PfC2gY6ri6', 'type': 'tool_call'},
{'name': 'search_travel_info', 'args': {'query': 'best beaches in Cornwall'}, 'id': 'call_XPNctNtyIKVetJa3ruM9z7d5', 'type': 'tool_call'},
{'name': 'search_travel_info', 'args': {'query': 'top seaside towns Cornwall'}, 'id': 'call_RAWMLwdFVALuIbJxWKfta5yp', 'type': 'tool_call'}],
...)

This response shows three requests for the same search tool with different query arguments. The assistant has not answered yet; these calls still need to be executed. section 11.6.1

Find beach towns with suitable weather

Register search_travel_info(query) and weather_forecast(town). For a request for two Cornwall beach towns with nice weather, the assistant can search for candidate towns, check forecasts for two candidates, and check others if the first forecasts are unsuitable. It then combines the tool results into an answer. Adding the weather tool does not require changing the graph’s structure. section 11.8.2 section 11.8

Tool availability alone does not ensure good tool selection. Clear descriptions should state inputs, expected outputs, and when to use a tool. A system instruction to get information—including town names—from tools can steer the assistant away from unsupported guesses. Test sample questions, inspect tool calls and results, and revise descriptions when selection goes wrong. Prefer structured results where possible so individual fields are easier to use; handle tool errors explicitly. section 11.8.2 section 11.10

How AI Agents and Applications covers it

How deep it goes
Works through registration, message routing, execution, and debugging, then identifies a built-in ReAct alternative to manual graph construction.
Examples
Traces Cornwall beach searches with multiple queries and extends the travel assistant to check weather forecasts.
What it assumes
Assumes basic Python functions and develops agent tool use incrementally from a simple script.
What you can do after
Build it from scratch with a tool-execution loop, then apply LangChain binding and LangGraph routing to a multi-tool agent.
How it connects
Connects tool calling to ReAct, LangGraph conditional routing, semantic search, and multi-agent supervision.

Also explained in

Compare how 13 books explain tool usage →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents and Applications. The section links point to the parts of the book it draws on.