tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Agentic AI > LangGraph > LangGraph Tool Calling Agent

LangGraph Tool Calling Agent

Author: Venkata Sudhakar

A tool-calling agent in LangGraph uses the LLM itself to decide when to call a tool and which arguments to pass. The graph has two nodes: an agent node that runs the LLM and either produces a final answer or emits a tool call, and a tools node that executes whichever tool the LLM requested. A conditional edge routes back to the agent after the tool result, or exits to END when the LLM produces a plain text answer with no tool calls. This loop continues until the agent is satisfied.

LangGraph provides ToolNode as a built-in node that automatically executes any tool decorated with @tool when the LLM requests it. You bind your tools to the LLM with llm.bind_tools(tools), and LangGraph handles the routing. The tools_condition helper returns "tools" if the last message has tool calls, or END if it does not - this is the conditional edge function used in nearly every tool-calling LangGraph agent.

The below example builds a complete tool-calling agent for a migration status checker that queries row counts and CDC lag using two custom tools.


Wiring the agent and tools nodes with conditional routing,


It gives the following output showing the full agent loop,

[HumanMessage] Check if orders table is fully migrated...
[AIMessage] [tool_call: count_rows(table="orders", database="source")]
[ToolMessage] orders in source: 890000 rows
[AIMessage] [tool_call: count_rows(table="orders", database="target")]
[ToolMessage] orders in target: 889997 rows
[AIMessage] [tool_call: check_cdc_lag(consumer_group="migration-cdc")]
[ToolMessage] migration-cdc: lag=3s, pending_messages=42
[AIMessage] The orders table has a discrepancy: source has 890,000 rows but
target only has 889,997 (3 rows missing). CDC lag is 3 seconds with 42
pending messages - still catching up. Do not cut over yet.

# Agent made 3 tool calls autonomously, then synthesised the final answer

The agent loop exits automatically when the LLM returns a message with no tool calls - tools_condition returns END in that case. To add safety, set a max iterations limit by counting loops in the state and routing to END after N steps. To add human-in-the-loop, compile with interrupt_before=["tools"] so the agent pauses before each tool execution for human review. These patterns all build on the same Conditional edges plus ToolNode foundation shown here.


 
  


  
bl  br