Mod 2.1Running Your First Pre-Built Agent
Level 2›Module 2.1
Level 2: Core Implementation & WorkflowsModule 2.1

Running Your First Pre-Built Agent

First Pre-Built

Level 2 • Core Implementation & Workflows
Est. ~21 mins
5 Key Topics
🎁 Free Learner Perk

Unlock Verified Certificate & Daily Streak Tracker

Ready to master Running Your First Pre-Built Agent? Enable cloud sync to record your daily streak 🔥 and earn your Informational Completion Badge for your study milestones.

Day 1 Streak ActiveFree Completion BadgeSync Laptop & Phone

🎯 By the end of this module, you will:

Run a 4-line LangGraph pre-built ReAct agent end-to-end
Understand the 4-phase Perceive → Reason → Act → Synthesize loop
Define type-hinted Python @tool functions that the LLM can call
Identify the 3 limitations of pre-built agents vs custom LangGraph graphs
Core Implementation • ReAct Pattern

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.

1. Perceive: Read & UnderstandPhase 1
# 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

❌ Raw LLM Call

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.

✅ Pre-Built Agent

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

1. Agent Configuration
Temperature0.2
2. ReAct Execution TraceLive Loop Output
Click “Run create_agent” to execute the ReAct loop

Under the hood, LangGraph coordinates the state graph: Model ➔ Tools ➔ Loop check.

# LangGraph / LangChain Implementation:
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?")]})
✍️ Instructor Note: "The LLM never sees your Python function body — only the JSON Schema generated from your docstrings. Write perfect docstrings or the LLM will use the tool incorrectly!"
💡 Mental Model: Think of the ReAct loop as a GPS navigation system — it checks current position (perceive), calculates next step (reason), takes the turn (act), then recalculates based on the new road ahead (synthesize).
📌 Core Rule: Pre-built agents use a hardcoded message list as state. If you need custom fields (user ID, permissions, session data), you MUST build a custom StateGraph — pre-built won't cut it.
📝 Pro Tip: Always set temperature=0.0 for tool-calling agents. Non-zero temperature introduces random variation in tool selection, causing flaky non-deterministic test failures!

Common Pre-Built Agent Traps

TRAP #1: The Prototype-to-Production Illusion

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.

TRAP #2: Missing Docstrings in @tool Functions

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_agent builds 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.
Up Next • Module 2.2

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.

Continue to Module 2.2