Deep Expertise Track · Lesson 3

LangChain Agents

What LangChain does for you vs what you now know how to do yourself

LangChain Agents: Framework Abstractions

Lesson 3 — what LangChain does for you vs what you now know how to do yourself

What you'll learn
  1. What LangChain's @tool decorator actually does under the hood
  2. How AgentExecutor maps to the ReAct loop you built in Lesson 2
  3. The 3 LangChain components every agent needs (LLM, Tools, Prompt)
  4. When to use LangChain vs building from scratch

From Scratch vs LangChain: Side by Side

FROM SCRATCH (Lesson 2): LANGCHAIN (your scaffolded agents): ┌────────────────────┐ ┌────────────────────┐ │ TOOLS = { │ │ @tool │ │ "get_price": fn, │ │ def get_price(): │ │ "get_fin": fn, │ │ """description"""│ │ } │ │ # auto-registered │ └────────────────────┘ └────────────────────┘ ▼ ▼ ┌────────────────────┐ ┌────────────────────┐ │ Manual parsing: │ │ create_react_agent│ │ if "Action:" in │ │ (llm, tools, │ │ output: extract │ │ prompt) │ │ tool name + input │ │ # handles parsing │ └────────────────────┘ └────────────────────┘ ▼ ▼ ┌────────────────────┐ ┌────────────────────┐ │ Manual loop: │ │ AgentExecutor( │ │ for i in range(N): │ │ agent=agent, │ │ call LLM │ │ tools=tools, │ │ parse output │ │ verbose=True, │ │ call tool │ │ max_iter=10, │ │ feed back │ │ handle_parsing │ │ │ │ _errors=True) │ └────────────────────┘ └────────────────────┘ ▼ ▼ ┌────────────────────┐ ┌────────────────────┐ │ Manual error │ │ Auto error │ │ handling: │ │ handling: │ │ if parse fails, │ │ built-in retry + │ │ send error back │ │ re-prompt │ └────────────────────┘ └────────────────────┘ Same loop. LangChain just wraps it in abstractions.

The 3 LangChain Components

ComponentWhat it doesYour code
LLMThe brain. Wraps the API call.ChatOpenAI(model="deepseek-chat", ...)
ToolsFunctions the agent can call. Each tool has a name, description, and schema.@tool def read_jira(...):
PromptSystem instructions telling the LLM how to reason and which tools exist.ChatPromptTemplate.from_messages([...])

What @tool Does Under the Hood

When you write:

@tool
def get_stock_price(ticker: str) -> str:
    """Get current stock price for a given ticker.
    Use this first to understand current valuation."""
    return f"{ticker} at ₹1,054"

LangChain automatically:

  1. Extracts the function name → "get_stock_price"
  2. Extracts the docstring → becomes the tool description the LLM sees
  3. Inspects the type hints → generates a JSON schema for the parameters
  4. Wraps the function in a Tool object that the AgentExecutor can call

The LLM sees something like this in its context:

{
  "name": "get_stock_price",
  "description": "Get current stock price for a given ticker. Use this first to understand current valuation.",
  "parameters": {
    "type": "object",
    "properties": {
      "ticker": {"type": "string"}
    },
    "required": ["ticker"]
  }
}

This is why the docstring matters so much. It's not just documentation — it's what the LLM reads to decide whether to call your tool. We'll cover this in depth in Lesson 4.

When to Use LangChain vs From Scratch

Decision Framework
Use from scratchUse LangChain
Learning how agents workProduction agents that need reliability
1-2 simple tools5+ tools with complex schemas
Want full control of parsingNeed error handling, async, streaming
Teaching/ interviewingShipping to users
Solo developer who understands the loopTeam project where others need to understand the code

Source: Anthropic — "If you do use a framework, ensure you understand the underlying code. Incorrect assumptions about what's under the hood are a common source of customer error."

The LangChain Ecosystem: What's What

┌─────────────────────────────────────────────────────────┐ │ LANGCHAIN ECOSYSTEM MAP │ │ │ │ LangChain ← core framework (tools, chains, agents) │ │ ▼ │ │ LangGraph ← stateful multi-agent orchestration │ │ ▼ (loops, human-in-loop, persistence) │ │ Deep Agents ← long-running workflow harness │ │ │ │ LangSmith ← observability + evaluation platform │ │ (tracing, evals, debugging) │ │ │ │ You are here: LangChain (single agent with tools) │ │ Next: LangGraph (multi-agent with state) │ └─────────────────────────────────────────────────────────┘

Source: LangChain — Best AI Agent Frameworks 2026

Your scaffolded agents use LangChain (the core framework). When you build multi-agent systems (Lessons 5-9), you'll use LangGraph for stateful orchestration. And LangSmith is what you'd use in production for tracing and evaluation (Lesson 10).

The one-sentence summary

LangChain doesn't change what your agent does — it wraps the ReAct loop in abstractions (tool decorator, AgentExecutor, prompt template) that handle parsing errors, schemas, and async for you, so you can focus on tool design and prompts instead of loop mechanics.

Practice Drill

  1. Open your ba-work-agent/main.py and read each line
  2. Map each LangChain abstraction to what you built from scratch in Lesson 2:
    • ChatOpenAI → which part of your scratch code?
    • @tool → which part?
    • create_react_agent → which part?
    • AgentExecutor → which part?
  3. Now run your from-scratch agent and your LangChain agent with the same goal. Compare the output quality and the verbose logs.
⚡ Quick Check
Q1: What does handle_parsing_errors=True do in AgentExecutor?
Show answer

When the LLM's output doesn't follow the Thought/Action/Action Input format, instead of crashing, AgentExecutor sends a message back to the LLM saying "please follow the correct format" and retries. This is the same as your manual if "Action:" not in output: ... continue in the from-scratch version.

Q2: Why does the @tool docstring matter more than a regular Python docstring?
Show answer

Because the LLM reads the docstring to decide whether to call the tool. A regular docstring is for human developers. A tool docstring is for the LLM. It needs to describe when to use the tool, not just what it does. "Use this first to get the current price" is better than "Returns stock price."

Where to Go Deeper

Want to see these patterns in action?

Explore the live apps built with these agent architectures.

Explore the Lab →

← Back to Deep Expertise Track