๐Ÿ› ๏ธ AI Engineering

Tools & Agents in LangChain โ€” Let the LLM Take Actions

๐Ÿ“… Aug 5, 2026 โฑ 7 min read

So far the model only talks. An agent can act: it decides, on its own, to call a calculator, search the web, or hit your database โ€” then uses the result to answer. The mechanism behind it is tool calling, and it's simpler than it sounds.

Step 1: define a tool

A tool is just a Python function with the @tool decorator and a clear docstring โ€” the docstring is how the LLM knows when to use it.

from langchain_core.tools import tool

@tool
def cgpa_to_percentage(cgpa: float) -> float:
    """Convert an Anna University CGPA (0-10) to a percentage."""
    return cgpa * 10          # Anna University formula

@tool
def word_count(text: str) -> int:
    """Count the number of words in a piece of text."""
    return len(text.split())

Step 2: how tool calling works

Bind the tools to the model. Now, instead of guessing an answer, the model can request a tool call โ€” it returns the tool name and arguments, and you run the function.

from langchain.chat_models import init_chat_model

model = init_chat_model("claude-opus-5", model_provider="anthropic")
model_with_tools = model.bind_tools([cgpa_to_percentage, word_count])

reply = model_with_tools.invoke("My CGPA is 8.4 โ€” what percentage is that?")
print(reply.tool_calls)
# [{'name': 'cgpa_to_percentage', 'args': {'cgpa': 8.4}, 'id': '...'}]

Notice the model didn't compute anything โ€” it chose the tool and filled the arguments. Running the function and feeding the result back is the loop an agent automates.

Step 3: let an agent run the loop for you

Doing that loop by hand (call model โ†’ run tool โ†’ send result โ†’ repeat) is tedious. LangGraph's prebuilt agent does it in one line โ€” this is the modern, recommended way to build agents.

pip install langgraph
from langgraph.prebuilt import create_react_agent

agent = create_react_agent(model, tools=[cgpa_to_percentage, word_count])

result = agent.invoke({"messages": [
    {"role": "user", "content": "My CGPA is 8.4. What percentage, and how many words in this sentence?"}
]})
print(result["messages"][-1].content)

The agent looped automatically: called cgpa_to_percentage, called word_count, then wrote a final answer using both results. You wrote two functions; the agent orchestrated them.

What just happened (the ReAct pattern)

The agent followed ReAct โ€” Reason + Act: think about what's needed, act (call a tool), observe the result, repeat until it can answer. It's the core loop behind almost every LLM agent you've heard of.

Real tools worth adding

create_react_agent is great, but real agents need branching, loops, and control you can see and shape. That's exactly what LangGraph gives you โ€” the next post starts the LangGraph half of this series.

โ† All Articles