LangChain/Agents
★ OverviewIntermediate9 min

create_agent

create_agent builds a graph-based agent runtime on top of LangGraph. Give it a model and tools — it handles the reasoning loop, tool dispatch, and stopping conditions.

Quick Reference

  • from langchain.agents import create_agent
  • Returns a CompiledStateGraph — supports .invoke(), .stream(), checkpointing
  • Agent loop: model reasons → calls tools → observes results → repeats until done
  • Stops when model emits final text (end_turn) or max iterations is reached
  • Pass string model ID: create_agent('anthropic:claude-sonnet-4-20250514', tools=[...])

What create_agent Builds

create_agent compiles a full agent runtime into a CompiledStateGraph backed by LangGraph. It is not a simple chain or a runnable — it is a stateful graph that alternates between a model node (which calls the LLM) and a tools node (which executes tool calls). Because it returns a CompiledStateGraph, you automatically get .invoke(), .stream(), checkpointing, middleware hooks, and human-in-the-loop support — none of which require additional wiring.

User Input"What's new in AI this week?"LLM Reasoning"I need to search for recent AI news..."Decides next action dynamicallytool callTool Executionweb_search()calculator()api_call()Returns result → agent observesObservationloop repeatsfinal answerResponseDelivered to user

The loop runs until the LLM decides it has enough information to respond