AI Hints
LangChain · Lesson 45 of 120

Several Tools

Choosing the right one.

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

Real assistants need several tools. Riverside Books' agent should check stock, look up the price, and find a book's author. The agent must pick the right tool, or tools, for each question.

Several Tools
From the video: Several Tools
  • Stock, price, author
  • Pick the right tool
  • Maybe more than one

Three tools

We give the agent three small tools, check stock, get price, and get author, which live in a helper file, written just like before. Then we ask one question that needs two of them, the price and the stock of The Hobbit. Run it. We list the tools the agent chose to call, and its final answer. It picked exactly the two it needed, and combined the results.

three_tools.pypython
from langchain.agents import create_agent
from shop_tools import check_stock, get_price, get_author   # three @tool functions

agent = create_agent("google_genai:gemini-flash-lite-latest",
                     tools=[check_stock, get_price, get_author])

question = "Price and stock of The Hobbit? One sentence."
out = agent.invoke({"messages": [{"role": "user", "content": question}]})

used = sorted(c["name"] for m in out["messages"] for c in getattr(m, "tool_calls", []))
print("tools used:", used)
print(out["messages"][-1].text)
Output
tools used: ['check_stock', 'get_price']
The Hobbit is priced at £8.99 and there are 7 copies in stock.
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")

Helping it choose

With many tools, choice gets harder. Keep each tool focused on one job. Make the descriptions clearly different from each other. Avoid two tools that do almost the same thing. And if you have dozens of tools, consider splitting them across several smaller agents.

keyvalue
Focusedone job each
Distinctclearly different docs
No overlapavoid near-duplicates
Many tools?split the agent

Summary

An agent with several tools picks the right ones for each question, and combines the results. Clear, distinct descriptions make that easier. Next, giving the agent a job description.

Key takeaways
  • Several focused tools
  • It picks what it needs
  • Distinct descriptions
Next up: Agent System Prompts — giving it a job