AI Hints
Home›LangGraph Tutorial›Tools in Graphs
LangGraph · Lesson 31 of 120

Tools in a Graph

Bind_tools.

⏱ 2 min read▶ Video at 32:45🎓 Free
Watch this lesson in the LangGraph courseWatch on YouTube ↗Full LangGraph course

To build an agent by hand, we first give the model some tools. Bind tools tells the model which tools exist. The model doesn't run them. It replies with tool calls, saying which tool to use, with which arguments.

Tools in a Graph
From the video: Tools in a Graph
  • Give the model tools
  • bind_tools
  • It asks, it doesn't run

Asking for tool calls

Our shop tools come from a helper file. Check stock, get price, and get author. Bind tools gives them to the model. We ask a question that needs two of them. Run it. The reply has no text answer yet. Instead it has two tool calls, each with a name, and arguments.

bind_tools.pypython
from langchain.chat_models import init_chat_model
from shop_tools import check_stock, get_price, get_author

model = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)
model_with_tools = model.bind_tools([check_stock, get_price, get_author])

reply = model_with_tools.invoke("Is Dune in stock, and how much is it?")
for call in reply.tool_calls:
    print(call["name"], call["args"])
Output
check_stock {'title': 'Dune'}
get_price {'title': 'Dune'}
Also uses shop_tools.py
from langchain.tools import tool

BOOKS = {
    "The Hobbit": {"stock": 7, "price": 8.99, "author": "J.R.R. Tolkien"},
    "Dune": {"stock": 3, "price": 9.99, "author": "Frank Herbert"},
    "Circe": {"stock": 0, "price": 10.99, "author": "Madeline Miller"},
}

@tool
def check_stock(title: str) -> int:
    """Copies of a book in stock at Riverside Books."""
    return BOOKS.get(title, {}).get("stock", 0)

@tool
def get_price(title: str) -> float:
    """Price of a book in pounds."""
    return BOOKS.get(title, {}).get("price", 0.0)

@tool
def get_author(title: str) -> str:
    """Author of a book."""
    return BOOKS.get(title, {}).get("author", "unknown")

Tool calls

A tool call has a name, the arguments, and an ID. The model chooses tools by reading their names and docstrings, so describe each tool clearly. Next, we need something to actually run the calls.

keyvalue
namewhich tool
argsthe inputs
idmatches the result
Docstringshow the model chooses

Summary

Bind tools tells the model about tools, and it replies with tool calls. Something else must run them. Next, the tool node.

Key takeaways
  • bind_tools([...])
  • reply.tool_calls
  • name, args, id
Next up: ToolNode — running tool calls