Tutorials

LangChain Tutorial: Build AI Agents for Your Small Business

Turn a chatbot into an agent that does things with LangChain — install the framework, build your first agent with a tool, and test it on real questions.

Developer building AI agents with LangChain tutorial
Image: Pixabay / Pixabay Content License
Time Required
About 1 Hour
Difficulty
Intermediate (Python)
Tools Covered
LangChain + OpenAI / LangSmith

What You'll Learn (Key Takeaways)

  • LangChain is a free, open-source framework for building agents and LLM-powered applications — officially, "the agent engineering platform".
  • Install with uv add langchain or pip (with a provider extra), then set your provider API key as an environment variable.
  • Call a model with init_chat_model, build your first agent with create_agent and a tool, then swap the demo tool for a real business tool.
  • Bottom line: the practical way for a small business with a developer to turn a chatbot into an agent — trace with LangSmith and test on real questions before shipping.

Chatbots answer questions, but most small businesses need AI that does things: look up an order, draft a reply from real policy text, or summarize a document. LangChain is the open-source framework developers use to build those agents and LLM-powered applications. This tutorial shows you how to install it and build your first working agent.

What It Is

LangChain is a framework for building agents and LLM-powered applications. It helps developers chain together interoperable components and third-party integrations to simplify AI application development. The project is published under the MIT License and, as checked on October 17, 2026, has 147,982 stars on GitHub (github.com/langchain-ai/langchain). Its official description is: “The agent engineering platform.” In plain terms, LangChain gives your code a standard way to talk to language models, give them tools, and run multi-step tasks. It works with Python and, through a separate library called LangChain.js, with JavaScript and TypeScript.

Who It’s For / SMB Use Case

LangChain is a developer tool. It fits small businesses that have a developer or an agency and want custom AI features instead of another generic chatbot. Practical uses include:

  • Support agent: An agent that reads your FAQ or policy documents and drafts accurate replies for a human to approve.
  • Internal helper: An agent that searches company documents and answers staff questions with sources, instead of guessing.
  • Lead and order tasks: An agent that looks up information from your own systems through tools you define, then drafts a follow-up message.
  • Model flexibility: Swap one model provider for another without rewriting your whole app, because LangChain provides a standard interface for models, embeddings, and vector stores.

LangChain is not a no-code product. If nobody on your team writes code, a hosted chatbot builder will be faster. LangChain earns its place when you need custom logic, your own data, and control over how the agent behaves.

Installation

LangChain needs Python and a model provider API key, such as an OpenAI key, unless you connect a local model. The README quickstart uses uv:

uv add langchain

The official docs overview shows the equivalent pip install with a provider extra:

pip install -qU langchain "langchain[openai]"

Set your provider API key as an environment variable. The exact variable name depends on the provider; for OpenAI-based examples, the docs use OPENAI_API_KEY. If you want a higher-level starting point with built-in planning, subagents, and file system use, the README points to Deep Agents. If you need fine-grained control over multi-step workflows, check LangGraph, the framework’s orchestration companion. For anything the README does not state clearly, check the official docs at docs.langchain.com.

How to Use LangChain

Step 1: Call a model with a few lines of code

This quickstart from the README creates a chat model and sends it a message:

from langchain.chat_models import init_chat_model

model = init_chat_model("openai:gpt-5.5")

result = model.invoke("Hello, world!")

The init_chat_model helper picks the right integration from the "provider:model" string. If this runs, your install and API key work.

Step 2: Build your first agent with a tool

An agent is a model plus tools it can call. This example comes from the official LangChain docs overview. It defines a simple tool, builds an agent around it, and runs it:

# pip install -qU langchain "langchain[openai]"
from langchain.agents import create_agent

def get_weather(city: str) -> str:
    """Get weather for a given city."""
    return f"It's always sunny in {city}!"

agent = create_agent(
    model="openai:gpt-5.5",
    tools=[get_weather],
    system_prompt="You are a helpful assistant",
)

result = agent.invoke(
    {"messages": [{"role": "user", "content": "What's the weather in San Francisco?"}]}
)

print(result["messages"][-1].content_blocks)

The agent decides when to call get_weather and then answers in plain language. The tool itself is just a Python function with a docstring.

Step 3: Replace the demo tool with a real business tool

Swap the weather function for a function that reads your own data, for example a function that looks up a shipping policy from a text file or returns a product price from a spreadsheet. Keep the function small, give it a clear docstring, and add it to the tools list. The agent will call it when a user asks a matching question. Always have the agent return drafts for human approval when money, bookings, or customer promises are involved.

Step 4: Add tracing and debugging with LangSmith

When an agent misbehaves, you need to see what it actually did. The docs recommend LangSmith for tracing requests, debugging agent behavior, and evaluating outputs. Set LANGSMITH_TRACING=true and your API key to get started, as described in the official docs. Check the official LangSmith docs for current setup steps and pricing before turning tracing on in production.

Step 5: Test on real questions before shipping

Write a short list of real customer or staff questions, run them through the agent, and check every answer against your source documents. Add the failures to your test list, fix the tool or the system prompt, and re-run. Ship only after the agent answers your test list correctly and consistently.

Pricing / Limitations

LangChain itself is free and open source under the MIT License. Your real costs are model API usage, charged by your provider per token, plus developer time. LangSmith, the tracing and evaluation companion, is a separate product with its own plans; check the official pricing before relying on it. The main limitations are that LangChain needs a developer, that agents can call the wrong tool or invent details if your tools and prompts are sloppy, and that the ecosystem moves fast, so expect to update code as APIs change. Never let an agent send messages, change bookings, or issue refunds without a human approval step.

Bottom Line for SMB

LangChain is the practical way for a small business with a developer to turn a chatbot into an agent that uses real company data and tools. Start with the quickstart, build one small agent with one real tool, and test it hard before giving it customer-facing work. For the business case behind agents, read our guide to AI agents explained for small business and our roundup of the best AI customer support tools.

Frequently Asked Questions

Do I need to know how to code to use LangChain?

Yes. LangChain is a developer framework in Python or JavaScript/TypeScript. Non-technical teams should use a hosted chatbot or agent builder instead, or hire a developer.

Is LangChain free?

The LangChain framework is free and open source under the MIT License. You still pay your model provider for API usage, and LangSmith has its own plans.

What is the difference between LangChain, LangGraph, and Deep Agents?

According to the official docs, Deep Agents is a higher-level, batteries-included package built on LangChain. LangChain’s create_agent is a customizable harness. LangGraph is the low-level orchestration framework for advanced, controllable workflows.

Frequently Asked Questions

Do I need to know how to code to use LangChain?

Yes. LangChain is a developer framework in Python or JavaScript/TypeScript. Non-technical teams should use a hosted chatbot builder instead.

Is LangChain free?

The LangChain framework is free and open source under the MIT License. You still pay your model provider for API usage.

What is the difference between LangChain, LangGraph, and Deep Agents?

According to the official docs, Deep Agents is a higher-level, batteries-included package built on LangGraph, and LangGraph is the low-level orchestration framework for advanced, controllable agents.

WebGool Tech Senior AI & Small Business Editor
Verified Contributor

Keep Reading

More in Tutorials

Explore all

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top