CalcSnippets Search
AI Frameworks 3 min read

Your First LangGraph Agent That Actually Uses Tools Instead of Pretending to Be Magic

A practical LangGraph quickstart that shows how to wire up a simple tool-calling agent in Python and think about agent loops, tool execution, and boundaries without drowning in hype.

Why LangGraph matters: once you move beyond one prompt and one reply, plain LLM code gets messy fast. LangGraph is useful because it gives you an explicit way to structure steps, loops, tools, and state instead of improvising them in random Python functions.

What LangGraph is good at

LangGraph is an orchestration framework for long-running, stateful agent workflows. That sounds abstract until you hit the first real agent problem:

  • the model wants to call a tool
  • then it needs the tool result
  • then it may want another tool
  • then it needs to stop at the right time

Without structure, that logic gets ugly quickly.

Install the basics

In a Python project:

pip install langgraph langchain

Depending on the model provider you use, you may also need the relevant integration package.

The simple agent pattern

The LangGraph quickstart shows a useful pattern:

  1. define tools
  2. define the model node
  3. define the tool node
  4. define the loop that keeps calling tools until the model is done

That is much better than pretending the model is some free-floating “autonomous” intelligence.

A compact example

from langchain.tools import tool
from langchain.chat_models import init_chat_model
from langgraph.graph import add_messages
from langgraph.func import entrypoint, task
from langchain.messages import SystemMessage, HumanMessage, ToolCall
from langchain_core.messages import BaseMessage

model = init_chat_model("gpt-4.1-mini", temperature=0)

@tool
def add(a: int, b: int) -> int:
    return a + b

tools = [add]
tools_by_name = {tool.name: tool for tool in tools}
model_with_tools = model.bind_tools(tools)

@task
def call_llm(messages: list[BaseMessage]):
    return model_with_tools.invoke(
        [SystemMessage(content="You are a helpful math assistant.")] + messages
    )

@task
def call_tool(tool_call: ToolCall):
    tool = tools_by_name[tool_call["name"]]
    return tool.invoke(tool_call)

@entrypoint()
def agent(messages: list[BaseMessage]):
    model_response = call_llm(messages).result()

    while True:
        if not model_response.tool_calls:
            break

        tool_results = [call_tool(tc).result() for tc in model_response.tool_calls]
        messages = add_messages(messages, [model_response, *tool_results])
        model_response = call_llm(messages).result()

    return add_messages(messages, model_response)

result = agent.invoke([HumanMessage(content="Add 3 and 4")])
print(result)

Why this is a good first project

Because it teaches the actual moving parts:

  • tool definitions
  • model-tool binding
  • repeated execution loop
  • stopping condition

Those are the pieces people usually hand-wave in “build an agent in 5 minutes” tutorials.

Where beginners go wrong

They give the agent vague tools

Good tools are narrow and well-defined. Bad tools are giant escape hatches with messy input and output contracts.

They do not define when the loop should end

That is how agent demos become infinite weirdness instead of useful workflows.

They confuse orchestration with intelligence

LangGraph does not magically make the model smarter. It makes the workflow easier to express and control.

What to build next

After the arithmetic demo, the next sane projects are:

  1. a docs lookup agent
  2. a log triage helper
  3. a deployment checklist assistant
  4. a code review explainer

These are much more useful than “build an autonomous startup founder.”

What to test before you trust the workflow

A tool-calling demo feels impressive very quickly, but the useful questions are operational:

  1. does the model call the right tool
  2. does it stop after the answer is available
  3. does bad tool input fail clearly
  4. can you inspect state after each step

If you cannot answer those questions, you do not really have an agent yet. You have a hopeful demo.

Final recommendation

If you want to learn agents honestly, LangGraph is a strong tool because it forces you to model the workflow instead of hiding everything inside a clever prompt. That is exactly why serious teams use orchestration frameworks: structure beats vibes.

Sources

Keep reading

Related guides