🎯 By the end of this module, you will:
Running Your First Pre-Built Agent
A pre-built agent abstracts the entire ReAct state machine into a single function call — giving you a production-grade reasoning loop in 4 lines of Python.
# Phase 1: Agent receives user input
agent = create_react_agent(model=model, tools=[calculate, get_weather])
# Invoke starts the ReAct loop
result = agent.invoke({
"messages": [("user", "What is 42 * 17?")]
})
# LLM reads the input and decides: "I need calculate tool"📚 Mental Model: Library → Master Chef
You send a message, get a response. Like asking a librarian to guess a recipe — it will try, but it can't actually cook. No tools, no loop, no real actions.
A master chef who reads the order (perceive), plans the steps (reason), cooks each dish (act), and serves the result (synthesize). The full loop runs autonomously.
🔬 See It in Action: Pre-Built Agent Playground
Watch the full ReAct loop run live — inspect tool dispatch, observation injection, and final synthesis in real-time.
Pre-Built Agent Interactive SandboxLangGraph create_agent
Observe how model config, tool bindings, and user queries produce an automated ReAct execution trace
Under the hood, LangGraph coordinates the state graph: Model ➔ Tools ➔ Loop check.
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
model = ChatOpenAI(model="gpt-4o-mini", temperature=0.2)
tools = [get_weather, calculate]
agent = create_react_agent(model, tools)
response = agent.invoke({"messages": [("user", "What is the weather in Tokyo, and what is 45 * 18?")]})Common Pre-Built Agent Traps
Pre-built agents have no retry logic, rate limit handling, structured logging, or custom state. Shipping one to production without wrapping it in error handling is a 3am incident waiting to happen.
The LLM literally reads your docstring to know WHEN to use a tool. An empty or vague docstring causes the agent to either never call the tool, or call it with hallucinated arguments.
Key Takeaways
- 1.4 Lines to a Working Agent:
create_react_agentbuilds the full state machine — perceive, reason, act, synthesize — without any manual loop code. - 2.Docstrings Are the API Contract: The LLM only sees your function's name, type hints, and docstring — never the function body. Write them as LLM instructions, not for human readers.
- 3.Prototype Fast, Graduate to Custom: Pre-built agents are exceptional for proving a concept in 10 minutes. Production workloads need custom LangGraph state graphs with proper observability.
Structured Outputs with JSON & Pydantic
Enforce strict output schemas with Pydantic BaseModel so your agents always return well-formed, type-safe data — eliminating JSON parsing failures in production.