AI Hints
Home›LangChain Tutorial›Tool Calls by Hand
LangChain · Lesson 41 of 120

Reading Tool Calls

What the model asked for.

⏱ 2 min read▶ Video at 44:53🎓 Free
Watch this lesson in the LangChain courseWatch on YouTube ↗Full LangChain course

When the model wants a tool, its reply has a list called tool calls. Each one says which tool, with which arguments, plus an ID to match the result later.

Reading Tool Calls
From the video: Reading Tool Calls
  • reply.tool_calls
  • Which tool, which args
  • An ID to match

Several calls at once

A model can ask for several tools in one reply. Here we ask about two books, so it asks to check stock twice, with different titles. Run it. We print each call's name and arguments. The IDs are random, but they matter, because each result must be sent back with its matching ID.

tool_calls.pypython
from langchain.tools import tool
from langchain.chat_models import init_chat_model

@tool
def check_stock(title: str) -> int:
    """Return how many copies of a book Riverside Books has in stock."""
    return {"Dune": 3, "Circe": 0}.get(title, 0)

model = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)
reply = model.bind_tools([check_stock]).invoke("Do you have Dune and Circe in stock?")

for call in reply.tool_calls:
    print(call["name"], call["args"], "id:", call["id"][:12] + "...")
Output
check_stock {'title': 'Dune'} id: call_1097344...
check_stock {'title': 'Circe'} id: call_1097344...

Inside a tool call

Each tool call is a small dictionary. Name is the tool to run. Args is a dictionary of arguments, already parsed from the model's output. ID links the request to its result. And type is always tool call.

KeyExample
namecheck_stock
args{'title': 'Dune'}
idcall_8121…
typetool_call

Summary

Tool calls list the tool name, arguments, and an ID. A model can request several at once. Next, running them and sending the results back.

Key takeaways
  • name
  • args
  • id
Next up: Running Tools Yourself — ToolMessage