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 LangChain's
@tooldecorator actually does under the hood - How
AgentExecutormaps to the ReAct loop you built in Lesson 2 - The 3 LangChain components every agent needs (LLM, Tools, Prompt)
- When to use LangChain vs building from scratch
From Scratch vs LangChain: Side by Side
The 3 LangChain Components
| Component | What it does | Your code |
|---|---|---|
| LLM | The brain. Wraps the API call. | ChatOpenAI(model="deepseek-chat", ...) |
| Tools | Functions the agent can call. Each tool has a name, description, and schema. | @tool def read_jira(...): |
| Prompt | System 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:
- Extracts the function name →
"get_stock_price" - Extracts the docstring → becomes the tool description the LLM sees
- Inspects the type hints → generates a JSON schema for the parameters
- Wraps the function in a
Toolobject that theAgentExecutorcan 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
| Use from scratch | Use LangChain |
|---|---|
| Learning how agents work | Production agents that need reliability |
| 1-2 simple tools | 5+ tools with complex schemas |
| Want full control of parsing | Need error handling, async, streaming |
| Teaching/ interviewing | Shipping to users |
| Solo developer who understands the loop | Team project where others need to understand the code |
The LangChain Ecosystem: What's What
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
- Open your
ba-work-agent/main.pyand read each line - 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?
- Now run your from-scratch agent and your LangChain agent with the same goal. Compare the output quality and the verbose logs.
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
- LangChain Python Docs — Official API reference for tools, agents, executors.
- LangChain Framework Comparison 2026 — How LangChain compares to CrewAI, OpenAI SDK, etc.
Want to see these patterns in action?
Explore the live apps built with these agent architectures.
Explore the Lab →