Build AI agents in Python or JavaScript with LangChain’s model integrations, typed tools, middleware, memory and human review controls.
LangChain
Explore features, practical uses and pricing below.
LangChain is an open-source framework for building AI agents and applications in Python and JavaScript. Developers combine a model, tools, instructions and middleware into an agent that can gather information or take defined actions. Its integrations connect the application to model providers and data sources, while its configurable agent harness controls the loop around the model.
The current LangChain product page describes an MIT-licensed library that is free to use. The Python overview and JavaScript overview explain the framework's role. LangChain is suitable for developers who want to define application behavior in code and maintain the surrounding integrations, permissions and deployment.
The central agent constructor assembles a model with its tools and prompt. The agent guide describes a model making tool calls in a loop until it finishes the task. Middleware can shape behavior around that loop. This provides a starting architecture while allowing the developer to choose which capabilities are present.
An agent is useful when the required next step depends on the information encountered. An internal assistant might search policy documents, inspect a related record and ask a follow-up question. A fixed transformation, such as converting every date to the same format, may be better implemented directly in ordinary application code.
Start with a narrow task and a small tool set. A useful first agent might retrieve a known document and produce a cited summary. Adding database writes, broad browsing and file execution at the beginning creates more behavior to explain and test. The framework enables those tools when implemented; it does not require exposing every available capability.
The model and harness have separate roles. The model proposes what to do, while the application's tools and controls determine what can happen. An instruction to act carefully is useful context, but permission checks and validation belong in the executable application as well.
LangChain provides common interfaces for models and related components across providers. That can reduce the amount of application code tied to a particular service. The overviews show using model identifiers or initialized model instances, and integrations provide provider-specific configuration.
A common interface does not make every model interchangeable in practice. Tool calling, structured output, supported inputs and context limits vary. A replacement model may follow instructions differently or use a different representation for tool results. Evaluate the application after a change instead of assuming identical behavior because the constructor still accepts the configuration.
Choose a model around the workload. A short classification task, a document-grounded answer and a multi-step tool workflow have different requirements. Compare outputs on the same representative cases and include exceptions. Also check availability, usage limits and provider access terms for the environment where the application will run.
Keep provider configuration separate from user input. API credentials, environment settings and model selection are deployment concerns. A user's request should not determine arbitrary endpoints or credentials. This separation helps the team change providers without exposing sensitive configuration in prompts or generated responses.
LangChain tools are callable functions with defined inputs and outputs. In Python, type hints describe input schemas and a function's documentation helps explain its purpose to the model. Tools can retrieve information, query systems or carry out actions that the developer implements.
A clear tool description explains when it is appropriate and what it returns. For example, an order lookup should identify whether it searches by order number, customer identifier or another field. A tool named search with an unspecified scope gives the model less guidance than a documented lookup with explicit constraints.
Return enough information for the next step without dumping unnecessary records into the model context. A lookup can return the requested status and relevant identifiers rather than an entire customer profile. A failed lookup should return an understandable failure state so the agent can ask for clarification instead of inferring a result.
Keep authorization inside the tool implementation. If a user can view only their own records, enforce that rule with authenticated application context. A model-generated customer identifier is not authorization. Validate arguments and distinguish read-only tools from tools that send messages, change records or execute code.
The middleware guide describes hooks around model and tool execution. Middleware can transform prompts or tool selection, add retry and fallback behavior, record diagnostic information or terminate a run early. These controls make the harness adaptable without replacing the entire agent loop.
Context selection is a practical use. An application can provide the right instructions or available tools for a user's role and current task. A support lookup and an administrative operation should not automatically expose the same actions. Make that selection from trusted application state, and retain enforcement within the tools themselves.
Retries need a purpose and a limit. A temporary provider error may justify another attempt; a denied permission should not lead to repeated attempts to bypass the restriction. Record the reason for a failure and use a clear stopping condition when recovery is not appropriate.
Middleware order can affect behavior. If one hook modifies a prompt and another summarizes context, check what actually reaches the model. A set of independently useful controls can interact in unexpected ways. Keep the configuration understandable and test the combined path with the same scrutiny as the tool implementations.
Short-term memory preserves information within a conversation thread. LangChain agents use state and a configured checkpointer to save and resume that thread. An in-memory example is convenient for development; a production application needs storage appropriate to its persistence and operational requirements.
Assign thread identifiers deliberately. Reusing one identifier for unrelated users can mix conversation history. Creating a new identifier for every turn loses the continuity the user expects. The application's session and authentication design should determine which thread is resumed.
Long-term memory uses stores for information across conversations. This is distinct from simply retaining every chat message. A team can decide which user preferences or application facts should persist and how they are retrieved, corrected or removed.
Conversation history can also grow beyond useful context. Trimming or summarizing may help manage it, but a summary can omit details that later matter. Preserve required source records separately and test how the application handles a user correcting an earlier statement. Storage and recall are design choices, not guarantees that every relevant fact will be remembered accurately.
Human-in-the-loop middleware can pause configured tool calls and request a decision. The saved graph state allows the run to resume later. Depending on the configured policy, a reviewer can approve, edit or reject an action, or supply a response for a question-style tool.
Use review at an action boundary where the proposed arguments are concrete. If an agent drafts an update to a customer record, show the record, fields and proposed values. A general request to approve whatever the agent will do next gives the reviewer little useful evidence.
Define what happens after rejection. The application can return feedback explaining which requirement was not met, and the agent can respond accordingly. Repeatedly resubmitting the same rejected action would make the review interface frustrating and potentially dangerous. Check that a declined action never executes as a side effect of error recovery.
Pause-and-resume support also requires the surrounding product to handle waiting states. A user may return after a delay or another reviewer may act first. The application should display whether an action is pending, completed or canceled and should avoid duplicate execution when a request is retried.
Structured output lets an agent return a specified schema rather than requiring the application to parse prose. The framework supports provider-native and tool-based strategies and validates the returned structure. This can suit extraction, classification or producing a result that another application consumes.
A valid structure does not establish a correct fact. An extracted invoice amount can be a properly typed number and still be wrong. Define how uncertain or missing values should be represented, check business rules separately and keep the original evidence available for consequential outputs.
The streaming guide describes agent progress, generated tokens and custom updates. These events can make a waiting interface more informative. A user can see that the application is retrieving a document or awaiting review rather than receiving only a final response after the whole run.
Choose which events to display. Internal tool arguments, private data or diagnostic details may not be appropriate for the end user. A partial answer is also provisional until the run finishes. Make completion and failure states explicit so the interface does not present an unfinished fragment as a completed result.
The official retrieval documentation describes using LangChain document loaders, embeddings and vector stores to build a searchable knowledge base. Existing databases or documentation systems can also be connected as tools or queried to provide context. Developers can choose a fixed retrieval step or let an agent decide when to search.
Preserve source identifiers with retrieved passages. An answer that cites a document title without the relevant section is harder to review. Check whether the retrieved text is current, whether a newer version supersedes it and whether the user is allowed to access it.
Retrieval quality depends on ingestion and search design. Broken extraction, missing pages or poor chunk boundaries can make a relevant answer unavailable. Test retrieval separately from answer generation so the team can distinguish a missing source from a model failing to use an available one.
Define behavior for insufficient evidence. A useful assistant can say the connected sources do not establish an answer or ask for a more precise question. Adding a retriever does not ensure every question has an answer, and fluent text should not conceal that gap.
Suppose a developer is building an assistant for an engineering handbook. The goal is to answer questions with relevant passages and optionally create a draft documentation task when a gap is found. Begin with a read-only version before adding the action tool.
Keep a small evaluation set with expected sources and known failures. After changing the model, retrieval configuration or middleware, replay those cases and inspect tool activity. A correct final answer is useful, but the path should also respect permissions and avoid unnecessary actions.
LangChain itself is free under the MIT license. Running an application can still incur model-provider, hosting, database and connected-service costs. Optional LangSmith services for observability, evaluation or deployment have their own pricing and access. Confirm those separately from the library license.
LangChain agents run on LangGraph's underlying runtime. LangGraph offers lower-level orchestration for more explicit workflow control, while Deep Agents assembles additional capabilities on top of LangChain. Those related products should be chosen according to the application design rather than assumed to be features automatically included in a minimal LangChain agent.
The framework fits developers comfortable with application code, integrations and operational ownership. It requires maintenance as dependencies and provider capabilities change. Pin appropriate versions, use matching language documentation and test upgrades. LangChain does not by itself supply a finished user interface, permission model, source corpus or deployment policy.
No. It is a framework that connects a selected model to tools, context and execution controls. Model access is configured separately.
Yes. Official JavaScript documentation covers the framework. Use the guide for the language and version in the application.
No. Developers implement authorization, validation and appropriate review policies around the tools. The framework provides building blocks for those controls.
The library is available independently. LangSmith is a related service that can support tracing, evaluation and deployment, with separate access and usage terms.