Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

LangChain

LangChain is an open-source framework for building LLM applications and agents from swappable models, tools, retrievers, and middleware.

LangChain is an open-source framework for building applications and AI agents on top of large language models (LLMs). It gives every model provider the same interface for messages, chat models, tools, and retrievers, so an application can switch from one provider's model to another's by changing a model name, and it supplies ready-made agent loops and hundreds of integrations with vector stores, document loaders, and APIs. Harrison Chase released LangChain as an open-source Python project in October 2022, weeks before ChatGPT launched, and it became one of the most widely used toolkits for chaining prompts, retrieval, and model calls into generative AI applications. LangChain 1.0 and LangGraph 1.0 shipped together on October 22, 2025, with a commitment to no breaking changes until version 2.0.

The LangChain Ecosystem#

The name now covers a family of packages, available in Python and JavaScript:

  • langchain: The agent framework, centered on create_agent, which takes a model, a list of tools, and a system prompt and returns a working agent.
  • langchain-core and integrations: Standard interfaces for chat models, messages, embeddings, retrievers, and tools, plus provider packages such as langchain-openai and langchain-anthropic that implement them.
  • LangGraph: The lower-level runtime that LangChain agents run on. It models a program as a graph of steps over shared state and can checkpoint that state after every step, so long tasks survive restarts and can pause for human approval.
  • LangSmith: A hosted platform for observability traces, agent evaluation on datasets, and agent deployment.

Classic LangChain apps were chains: a prompt template filled with the user's input, a model call, and an output parser, composed with a pipe syntax as in prompt chaining. The most common chain is retrieval-augmented generation (RAG), which loads documents, splits them into chunks, stores their embeddings in a vector database, and adds the chunks that best match each question to the model's context window.

How a LangChain Agent Runs#

An agent built with create_agent repeats a loop of model calls and tool calls, the same function calling loop every agent harness runs. Middleware hooks into each step to change what happens around the model: built-in middleware summarizes long histories, redacts personal data, and pauses for human approval before chosen tools run.

Giving a LangChain Agent Vision#

LangChain's @tool decorator turns a Python function into a tool, reading the argument types from its signature and the description from its docstring. Wrapping Ultralytics YOLO26 this way gives an agent object detection, with Results.summary() returning each detection's class name, confidence, and box as data the model can read:

from langchain_core.tools import tool
from langchain_core.utils.function_calling import convert_to_openai_tool
from ultralytics import YOLO

model = YOLO("yolo26n.pt")


@tool
def detect_objects(image_url: str) -> list[dict]:
    """Detect objects in an image and return each one's class name, confidence, and box."""
    results = model(image_url)
    return results[0].summary()


# The schema LangChain derives from the signature and docstring, as a model receives it
print(convert_to_openai_tool(detect_objects))

# An agent runs the tool with the arguments from the model's tool call
detections = detect_objects.invoke({"image_url": "https://ultralytics.com/images/bus.jpg"})
print(detections[0]["name"], detections[0]["confidence"])

The first print shows the function definition, with an image_url string parameter and the docstring as its description, that LangChain sends to the model; the second shows the first detection the tool returns. Passing tools=[detect_objects] to create_agent lets any supported chat model call the detector through predict mode.

  • Agentic workflows: The general design patterns, such as routing, tool use, and evaluator loops, that LangGraph graphs and LangChain agents implement.
  • Provider SDKs: Calling a model provider's API directly needs no framework and suits single-model apps. LangChain adds the shared interfaces, integrations, and agent loop that matter once an app spans several models, tools, or data sources.
  • DSPy: A framework that writes and optimizes the prompts of a multistep LLM program automatically, tuning them against a metric on example data.
  • LlamaIndex: A framework centered on ingesting, indexing, and querying private data for RAG. The two overlap, and applications often use LlamaIndex for retrieval inside a LangChain or LangGraph agent.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning