Recent from talks
Nothing was collected or created yet.
LangChain
View on Wikipedia| LangChain | |
|---|---|
| Developer | Harrison Chase |
| Initial release | October 2022 |
| Stable release | 0.1.16[1]
/ 11 April 2024 |
| Repository | github.com/langchain-ai/langchain |
| Written in | Python and JavaScript |
| Type | Software framework for large language model application development |
| License | MIT License |
| Website | LangChain.com |
LangChain is a software framework that helps facilitate the integration of large language models (LLMs) into applications. As a language model integration framework, LangChain's use-cases largely overlap with those of language models in general, including document analysis and summarization, chatbots, and code analysis.[2]
History
[edit]LangChain was launched in October 2022 as an open source project by Harrison Chase, while working at machine learning startup Robust Intelligence. In April 2023, LangChain had incorporated and the new startup raised over $20 million in funding at a valuation of at least $200 million from venture firm Sequoia Capital, a week after announcing a $10 million seed investment from Benchmark.[3][4]
In the third quarter of 2023, the LangChain Expression Language (LCEL) was introduced, which provides a declarative way to define chains of actions.[5][6]
In October 2023 LangChain introduced LangServe, a deployment tool to host LCEL code as a production-ready API.[7]
In February 2024 LangChain released LangSmith, a closed-source observability and evaluation platform for LLM applications, and announced a US $25 million Series A led by Sequoia Capital.[8] On 14 May 2025 the company launched LangGraph Platform into general availability, providing managed infrastructure for deploying long-running, stateful AI agents.[9]
Capabilities
[edit]LangChain's developers highlight the framework's applicability to use-cases including chatbots,[10] retrieval-augmented generation,[11] document summarization,[12] and synthetic data generation.[13]
As of March 2023, LangChain included integrations with systems including Amazon, Google, and Microsoft Azure cloud storage;[14] API wrappers for news, movie information, and weather; Bash for summarization, syntax and semantics checking, and execution of shell scripts; multiple web scraping subsystems and templates; few-shot learning prompt generation support; finding and summarizing "todo" tasks in code; Google Drive documents, spreadsheets, and presentations summarization, extraction, and creation; Google Search and Microsoft Bing web search;[15] OpenAI, Anthropic, and Hugging Face language models; iFixit repair guides and wikis search and summarization; MapReduce for question answering, combining documents, and question generation; N-gram overlap scoring; PyPDF, pdfminer, fitz, and pymupdf for PDF file text extraction and manipulation; Python and JavaScript code generation, analysis, and debugging; Milvus vector database[16] to store and retrieve vector embeddings; Weaviate vector database[17] to cache embedding and data objects; Redis cache database storage; Python RequestsWrapper and other methods for API requests; SQL and NoSQL databases including JSON support; Streamlit, including for logging; text mapping for k-nearest neighbors search; time zone conversion and calendar operations; tracing and recording stack symbols in threaded and asynchronous subprocess runs; and the Wolfram Alpha website and SDK.[18] As of April 2023, it can read from more than 50 document types and data sources.[19]
LangChain tools
[edit]| Tool name | Account required? | API key required? | Licencing | Features | Documentation URL |
|---|---|---|---|---|---|
| Alpha Vantage | No | Yes | Proprietary | Financial data, analytics | https://python.langchain.com/docs/integrations/tools/alpha_vantage |
| Apify | No | Yes | Commercial | Web scraping, automation | https://python.langchain.com/docs/integrations/providers/apify/ |
| ArXiv | No | No | Open Source | Scientific papers, research | https://python.langchain.com/docs/integrations/tools/arxiv |
| AWS Lambda | Yes | Yes | Proprietary | Serverless computing | https://python.langchain.com/docs/integrations/tools/awslambda |
| Bash | No | No | Open source | Shell environment access | https://python.langchain.com/docs/integrations/tools/bash |
| Bearly Code Interpreter | No | Yes | Commercial | Remote Python code execution | https://python.langchain.com/docs/integrations/tools/bearly |
| Bing Search | No | Yes | Proprietary | Search engine | https://python.langchain.com/docs/integrations/tools/bing_search |
| Brave Search | No | No | Open source | Privacy-focused search | https://python.langchain.com/docs/integrations/tools/brave_search |
| ChatGPT Plugins | No | Yes | Proprietary | ChatGPT | https://python.langchain.com/docs/integrations/tools/chatgpt_plugins |
| Connery | No | Yes | Commercial | API actions | https://python.langchain.com/docs/integrations/tools/connery |
| Dall-E Image Generator | No | Yes | Proprietary | Text-to-image generation | https://python.langchain.com/docs/integrations/tools/dalle_image_generator |
| DataForSEO | No | Yes | Commercial | SEO data, analytics | https://python.langchain.com/docs/integrations/tools/dataforseo |
| DuckDuckGo Search | No | No | Open source | Privacy-focused search | https://python.langchain.com/docs/integrations/tools/ddg |
| E2B Data Analysis | No | No | Open source | Data analysis | https://python.langchain.com/docs/integrations/tools/e2b_data_analysis |
| Eden AI | No | Yes | Commercial | AI tools, APIs | https://python.langchain.com/docs/integrations/tools/edenai_tools |
| Eleven Labs Text2Speech | No | Yes | Commercial | Text-to-speech | https://python.langchain.com/docs/integrations/tools/eleven_labs_tts |
| Exa Search | No | Yes | Commercial | Web search | https://python.langchain.com/docs/integrations/tools/exa_search |
| File System | No | No | Open source | File system interaction | https://python.langchain.com/docs/integrations/tools/filesystem |
| Golden Query | No | Yes | Commercial | Natural language queries | https://python.langchain.com/docs/integrations/tools/golden_query |
| Google Cloud Text-to-Speech | Yes | Yes | Proprietary | Text-to-speech | https://python.langchain.com/docs/integrations/tools/google_cloud_texttospeech |
| Google Drive | Yes | Yes | Proprietary | Google Drive access | https://python.langchain.com/docs/integrations/tools/google_drive |
| Google Finance | Yes | Yes | Proprietary | Financial data | https://python.langchain.com/docs/integrations/tools/google_finance |
| Google Jobs | Yes | Yes | Proprietary | Job search | https://python.langchain.com/docs/integrations/tools/google_jobs |
| Google Lens | Yes | Yes | Proprietary | Visual search, recognition | https://python.langchain.com/docs/integrations/tools/google_lens |
| Google Places | Yes | Yes | Proprietary | Location-based services | https://python.langchain.com/docs/integrations/tools/google_places |
| Google Scholar | Yes | Yes | Proprietary | Scholarly article search | https://python.langchain.com/docs/integrations/tools/google_scholar |
| Google Search | Yes | Yes | Proprietary | Search engine | https://python.langchain.com/docs/integrations/tools/google_search |
| Google Serper | No | Yes | Commercial | SERP scraping | https://python.langchain.com/docs/integrations/tools/google_serper |
| Google Trends | Yes | Yes | Proprietary | Trend data | https://python.langchain.com/docs/integrations/tools/google_trends |
| Gradio | No | No | Open source | Machine learning UIs | https://python.langchain.com/docs/integrations/tools/gradio_tools |
| GraphQL | No | No | Open source | API queries | https://python.langchain.com/docs/integrations/tools/graphql |
| HuggingFace Hub | No | No | Open source | Hugging Face models, datasets | https://python.langchain.com/docs/integrations/tools/huggingface_tools |
| Human as a tool | No | No | N/A | Human input | https://python.langchain.com/docs/integrations/tools/human_tools |
| IFTTT WebHooks | No | Yes | Commercial | Web service automation | https://python.langchain.com/docs/integrations/tools/ifttt |
| Ionic Shopping | No | Yes | Commercial | Shopping | https://python.langchain.com/docs/integrations/tools/ionic_shopping |
| Lemon Agent | No | Yes | Commercial | Lemon AI interaction | https://python.langchain.com/docs/integrations/tools/lemonai |
| Memorize | No | No | Open source | Fine-tune LLM to memorize information using unsupervised learning | https://python.langchain.com/docs/integrations/tools/memorize |
| Nuclia | No | Yes | Commercial | Indexing of unstructured data | https://python.langchain.com/docs/integrations/tools/nuclia |
| OpenWeatherMap | No | Yes | Commercial | Weather data | https://python.langchain.com/docs/integrations/tools/openweathermap |
| Polygon Stock Market API | No | Yes | Commercial | Stock market data | https://python.langchain.com/docs/integrations/tools/polygon |
| PubMed | No | No | Open source | Biomedical literature | https://python.langchain.com/docs/integrations/tools/pubmed |
| Python REPL | No | No | Open source | Python shell | https://python.langchain.com/docs/integrations/tools/python |
| Reddit Search | No | No | Open source | Reddit search | https://python.langchain.com/docs/integrations/tools/reddit_search |
| Requests | No | No | Open source | HTTP requests | https://python.langchain.com/docs/integrations/tools/requests |
| SceneXplain | No | No | Open source | Model explanations | https://python.langchain.com/docs/integrations/tools/sceneXplain |
| Search | No | No | Open source | Query various search services | https://python.langchain.com/docs/integrations/tools/search_tools |
| SearchApi | No | Yes | Commercial | Query various search services | https://python.langchain.com/docs/integrations/tools/searchapi |
| SearxNG | No | No | Open source | Privacy-focused search | https://python.langchain.com/docs/integrations/tools/searx_search |
| Semantic Scholar API | No | No | Open source | Academic paper search | https://python.langchain.com/docs/integrations/tools/semanticscholar |
| SerpAPI | No | Yes | Commercial | Search engine results page scraping | https://python.langchain.com/docs/integrations/tools/serpapi |
| StackExchange | No | No | Open source | Stack Exchange access | https://python.langchain.com/docs/integrations/tools/stackexchange |
| Tavily Search | No | Yes | Commercial | Question answering | https://python.langchain.com/docs/integrations/tools/tavily_search |
| Twilio | No | Yes | Commercial | Communication APIs | https://python.langchain.com/docs/integrations/tools/twilio |
| Wikidata | No | No | Open source | Structured data access | https://python.langchain.com/docs/integrations/tools/wikidata |
| Wikipedia | No | No | Open source | Wikipedia access | https://python.langchain.com/docs/integrations/tools/wikipedia |
| Wolfram Alpha | No | Yes | Proprietary | Computational knowledge | https://python.langchain.com/docs/integrations/tools/wolfram_alpha |
| Yahoo Finance News | No | Yes | Commercial | Financial news | https://python.langchain.com/docs/integrations/tools/yahoo_finance_news |
| Youtube | No | Yes | Commercial | YouTube access | https://python.langchain.com/docs/integrations/tools/youtube |
| Zapier Natural Language Actions | No | Yes | Commercial | Workflow automation | https://python.langchain.com/docs/integrations/tools/zapier |
References
[edit]- ^ "Release 0.1.16". 11 April 2024. Retrieved 23 April 2024.
- ^ Buniatyan, Davit (2023). "Code Understanding Using LangChain". Activeloop.
- ^ Palazzolo, Stephanie (2023-04-13). "AI startup LangChain taps Sequoia to lead funding round at a valuation of at least $200 million". Business Insider. Archived from the original on 2023-04-18. Retrieved 2023-04-18.
- ^ Griffith, Erin; Metz, Cade (2023-03-14). "'Let 1,000 Flowers Bloom': A.I. Funding Frenzy Escalates". The New York Times. ISSN 0362-4331. Archived from the original on 2023-04-18. Retrieved 2023-04-18.
- ^ Mansurova, Mariya (2023-10-30). "Topic Modelling in production: Leveraging LangChain to move from ad-hoc Jupyter Notebooks to production modular service". towardsdatascience.com. Retrieved 2024-07-08.
- ^ "LangChain Expression Language". langchain.dev. 2023-08-01. Retrieved 2024-07-08.
- ^ "Introducing LangServe, the best way to deploy your LangChains". LangChain Blog. 2023-10-12. Retrieved 2023-10-17.
- ^ "Announcing the General Availability of LangSmith and Our Series A Led By Sequoia Capital". LangChain Blog. 2024-02-15. Retrieved 2025-08-03.
- ^ "LangGraph Platform is now Generally Available: Deploy & manage long-running, stateful Agents". LangChain Blog. 2025-05-14. Retrieved 2025-08-03.
- ^ "Chatbots | 🦜️🔗 Langchain". python.langchain.com. Archived from the original on 2024-03-14. Retrieved 2023-11-26.
- ^ "Retrieval-augmented generation (RAG) | 🦜️🔗 Langchain". python.langchain.com. Archived from the original on 2024-03-28. Retrieved 2023-11-26.
- ^ "Summarization | 🦜️🔗 Langchain". python.langchain.com. Archived from the original on 2024-01-06. Retrieved 2023-11-26.
- ^ "Synthetic data generation | 🦜️🔗 Langchain". python.langchain.com. Archived from the original on 2024-03-07. Retrieved 2023-11-26.
- ^ "Azure Cognitive Search and LangChain: A Seamless Integration for Enhanced Vector Search Capabilities". TECHCOMMUNITY.MICROSOFT.COM. Retrieved 2024-08-31.
- ^ "Best Alternative AI Content Strategies and LLM Frameworks". Medium. 2024-08-31. Retrieved 2024-08-31.
- ^ "Milvus — LangChain". python.langchain.com. Retrieved 2023-10-29.
- ^ "Weaviate". python.langchain.com. Retrieved 2024-01-17.
- ^ Hug, Daniel Patrick (2023-03-08). "Hierarchical topic tree of LangChain's integrations" (PDF). GitHub. Archived from the original on 2023-04-29. Retrieved 2023-04-18.
- ^ "Document Loaders — LangChain 0.0.142". python.langchain.com. Archived from the original on 2023-04-18. Retrieved 2023-04-18.
External links
[edit]- Official website
- Discord server support hub
- Langchain-ai on GitHub
LangChain
View on GrokipediaOverview
Definition and Purpose
LangChain is an open-source framework for building applications with large language models, providing abstractions for chains, agents, and retrieval-augmented generation. It is a modular framework implemented in Python and JavaScript, designed for orchestrating large language models (LLMs) within applications, and has become one of the most popular LLM orchestration frameworks. It enables developers to compose and integrate key components—such as prompts, models, memory, and output parsers—into cohesive systems that leverage LLMs for tasks like reasoning and context-aware processing.[8][9][3][7] The framework's core purpose is to streamline the development of LLM-powered applications, from rapid prototyping to scalable production deployment, by abstracting the intricacies of multi-step LLM interactions, external data integration, and state management. This abstraction reduces boilerplate code and promotes reusability, allowing developers to focus on application logic rather than low-level API handling.[8][3] LLM orchestration refers to frameworks and patterns for coordinating Large Language Model calls with other components like retrieval systems, tools, and external APIs to build complex AI applications. Orchestration handles the flow of data between components, manages conversation state, and implements patterns like chain-of-thought and multi-step reasoning.[10][11] Major orchestration frameworks include LangChain (a comprehensive toolkit in Python and JavaScript), LlamaIndex (Python-focused on data indexing and retrieval), Semantic Kernel (Microsoft .NET-focused), and Haystack (Python pipeline-oriented). These frameworks provide abstractions for common patterns including RAG pipelines, agent loops, and tool use, positioning LangChain as a versatile option within this ecosystem for building scalable LLM applications.[11] Emerging in 2022 amid the growing prominence of LLMs like GPT-3, LangChain addresses early adoption challenges, particularly the absence of standardized approaches for building reliable multi-step workflows that chain LLM calls effectively.[5][4][12] In a typical high-level workflow, user inputs are formatted into prompts that invoke LLMs, with subsequent output parsing to refine results and enable further processing.[8]Key Principles
LangChain's foundational design emphasizes modularity, enabling developers to construct applications by composing interchangeable components such as prompts, models, and retrievers in a flexible manner. This approach allows for seamless mixing and matching of elements without vendor lock-in, promoting reusability across different LLM ecosystems.[13] Extensibility is another core principle, rooted in LangChain's open-source architecture, which facilitates custom integrations and extensions by providing high-level abstractions for key elements like prompts, models, and retrievers. These abstractions accommodate a wide range of LLMs from various providers, empowering developers to tailor solutions to specific needs without starting from scratch.[3] To address the inherent non-determinism of LLMs, LangChain incorporates observability as a key focus, offering built-in support for tracing and evaluation mechanisms that allow debugging and monitoring of complex chains. This feature, integrated early through tools like LangSmith, enables detailed inspection of application behavior, iteration on performance, and identification of issues in production environments.[14] Interoperability is prioritized through standardized interfaces for tools, data sources, and external components, ensuring compatibility across diverse systems. In 2025, these principles evolved to better support multi-framework ecosystems, enhancing integration with emerging agentic and graph-based workflows.[15] For instance, retrieval-augmented generation (RAG) exemplifies modularity by combining retrieval modules with LLM chains to ground responses in external data.[1]History
Origins and Founding
LangChain was founded by Harrison Chase, a graduate of Harvard University with degrees in statistics and computer science, who had previously worked as a machine learning engineer at Kensho Technologies, a fintech startup focused on AI applications in finance.[16][17][18] In 2022, while employed at Robust Intelligence, Chase initiated LangChain as a personal side project to tackle the emerging challenges in building applications with large language models (LLMs).[4][19] The framework originated from Chase's recognition of the limitations in early LLM experimentation, where developers relied on custom, one-off scripts to handle prompt formatting, model invocations, and output parsing, lacking standardized tools for more complex, production-ready integrations.[20] The project's timing aligned closely with the explosive rise of generative AI, particularly following the public launch of ChatGPT by OpenAI on November 30, 2022, which sparked widespread interest in LLM-powered applications but highlighted the need for reusable patterns to streamline development.[5][21] LangChain addressed this by providing modular abstractions for chaining LLM calls with external data sources, memory management, and agentic behaviors, enabling developers to compose sophisticated workflows without reinventing core functionalities.[3] This focus on practicality emerged from Chase's hands-on experience in ML engineering, where he observed the ad-hoc nature of LLM interactions hindering scalable app building amid the post-ChatGPT hype.[22] Chase open-sourced LangChain on GitHub in October 2022, just weeks before ChatGPT's debut, marking its debut as a lightweight Python library centered on prompt templating and basic LLM orchestration.[5][4] The repository quickly gained traction, amassing over 5,000 stars by February 2023 and tripling to 18,000 by April, reflecting the community's enthusiasm for a tool that simplified LLM app prototyping during the early generative AI boom.[4] At its inception, LangChain operated without a formal company structure, relying on community contributions and Chase's solo efforts to iterate on core utilities for LLM chaining and integration.[5] This grassroots approach laid the groundwork for its evolution into a structured organization in subsequent years.Development Milestones
LangChain Inc. was formally incorporated on January 31, 2023,[23] with Harrison Chase as CEO and Ankush Gola as co-founder, to support the ongoing development of the open-source project, enabling the founders to transition to full-time work on the framework. This move was followed shortly by a $10 million seed funding round in April 2023, led by Benchmark, which provided the resources to expand the team and accelerate feature development.[24] In February 2024, the company raised a $25 million Series A round led by Sequoia Capital, achieving a post-money valuation of $200 million. In October 2025, LangChain secured a $125 million Series B round also led by Sequoia Capital, reaching a $1.25 billion valuation and unicorn status.[25] In July 2023, LangChain released LangSmith, a platform designed to address key challenges in building LLM applications by offering tools for debugging, testing, evaluating, and monitoring chains and agents.[26] This launch filled a critical observability gap in the ecosystem, allowing developers to trace LLM interactions and iterate more effectively on production-grade systems. The following year, in January 2024, the team introduced LangGraph as an extension to the core framework, providing a library for constructing stateful, graph-based workflows that support cyclical processes and multi-actor agent interactions. LangChain achieved significant version stability with the release of v1.0 in October 2025, marking a milestone for both the core library and LangGraph. The LangChain v1.0 update introduced a standardized core agent loop integrated with middleware for enhanced extensibility, while LangGraph v1.0 added support for stateful persistence, improving reliability for long-running applications.[27] These releases emphasized production readiness, with a focus on interoperability across models, tools, and deployment environments to facilitate scalable agentic AI systems. By 2025, the project had grown substantially in the developer community, surpassing 100,000 GitHub stars and contributing to emerging standards in multi-agent orchestration through open-source collaborations.[4]Core Components
LangChain's core components provide abstractions essential for building applications with large language models, including document loaders for ingesting data from various sources into structured documents, text splitters for implementing chunking strategies to divide large texts into manageable pieces, embeddings for generating vector representations of text to capture semantic meaning, vector stores for integrating with databases to store and query these vectors for similarity searches, retrievers for abstracting search mechanisms to fetch relevant information based on queries, and chains for creating composable workflows that sequence LLM interactions and other components. Document loaders are foundational components in Retrieval-Augmented Generation (RAG) systems that extract text and metadata from various file formats and data sources for indexing. Supported formats typically include PDF, Word documents, PowerPoint, HTML, Markdown, plain text, CSV, and JSON.[28] Data sources include local files, cloud storage such as S3, Google Drive, and Azure Blob, databases, web scraping, and SaaS applications like Notion, Confluence, and Slack. Quality document loading is crucial, as errors or omissions at this stage propagate through the entire pipeline; PDFs, in particular, require careful handling due to layout complexity.[29] LangChain provides an extensive collection of loaders, comparable to those in LlamaIndex, while for production systems, dedicated parsing services like Unstructured.io often provide better quality than basic loaders.[30][31][28][32][33][34][35][36]Chains and Prompts
In LangChain, the foundational mechanism for orchestrating interactions with language models and other components is the LangChain Expression Language (LCEL), a declarative syntax for composing chains using the Runnable interface. LCEL enables modular, composable workflows by sequencing elements such as prompts, model invocations, and output parsers with the pipe operator (|), e.g.,chain = prompt | model | parser. This approach supports linear execution for tasks like text generation or data extraction, promoting reusability and avoiding custom coding for integrations. Legacy chain classes, such as LLMChain and SequentialChain, are deprecated since version 0.1.17 and should be replaced with LCEL for new development.[36][37]
LCEL chains emphasize deterministic execution, where components are invoked sequentially, with outputs from one feeding into the next, facilitating multi-stage reasoning or transformations. All LCEL components implement the Runnable interface, allowing standardized invocation, streaming, batching, and async support. LangChain supports several key orchestration patterns through LCEL, including sequential chains for fixed step sequences, router chains for dynamic path selection based on inputs, agent loops for LLM-driven tool selection, and parallel execution for concurrent operations across multiple components.[38][39][40][41]
Prompts serve as the input structuring layer within chains, using the PromptTemplate class to define reusable string formats that incorporate dynamic placeholders, such as {user_input} or {context}, via Python's f-string syntax or partial formatting methods. This templating ensures consistent guidance for the LLM, improving response reliability across invocations; for example, a prompt might specify "Summarize the following text in three bullet points: {text}" to direct concise output. PromptTemplate objects are directly integrable into LCEL chains, where they are populated with runtime variables before model execution.[42][43]
Output parsers handle the post-processing of LLM responses to enforce structure, transforming unstructured text into parseable formats like dictionaries or objects. The PydanticOutputParser, for instance, leverages Pydantic models to define and validate JSON schemas, rejecting invalid outputs and retrying if needed, which is particularly useful for extracting fields like "summary" or "key_points" from free-form generations. In an LCEL chain, the parser follows the model step, ensuring downstream components receive clean, typed data.[44][45]
A representative workflow is the construction of a summarization chain using LCEL, where a PromptTemplate instructs the LLM to condense input text—e.g., "Write a concise summary of the following: {input_text}"—followed by model invocation and parsing via PydanticOutputParser to yield a structured JSON object with attributes like "main_idea" and "supporting_points". This can be assembled as chain = prompt | llm | parser for single-document handling or extended with document loaders and splitters for multi-document scenarios, using a "stuff" approach that aggregates content into a single prompt for efficient processing of moderate-length texts. Such LCEL chains exemplify linear LLM interactions, scalable to extensions like agents for non-linear decision-making.[36]
Models and Outputs
LangChain provides abstractions for integrating with large language models (LLMs) through standardized interfaces, enabling seamless interaction with various providers. TheChatOpenAI class, for instance, facilitates access to OpenAI's chat models such as GPT-3.5-turbo or GPT-4, handling API calls via the OpenAI API key and supporting parameters like temperature, max tokens for output length limits, and frequency penalties to control generation.[46] Similarly, the HuggingFaceHub integration allows invocation of open-source models hosted on Hugging Face, requiring an API token and supporting tasks like text generation and summarization through the Inference API.[47] These abstractions implement the Runnable interface, which manages underlying API requests, error handling, and response formatting, while also enabling streaming outputs for real-time applications by yielding tokens incrementally during generation.[48]
Beyond chat models, LangChain supports non-generative models for tasks like embeddings, which convert text into vector representations for similarity searches. The HuggingFaceEmbeddings class leverages sentence-transformer models, such as the default "sentence-transformers/all-mpnet-base-v2," to produce dense embeddings locally or via the Hugging Face hub, integrating with libraries like transformers for efficient computation without external API dependencies.[49] This abstraction handles batch embedding of multiple texts and normalizes vectors as needed, making it suitable for downstream applications like retrieval-augmented generation (RAG) pipelines where embeddings facilitate document ranking.
Output handling in LangChain transforms raw, unstructured LLM responses into usable formats through dedicated parsers, mitigating issues like inconsistent or erroneous outputs. Classes such as JsonOutputParser and PydanticOutputParser extract structured data, converting free-form text into JSON objects or validated Pydantic models, respectively, by defining schemas that guide parsing.[45] For reliability, the RetryOutputParser wraps other parsers and employs an LLM to iteratively fix parsing failures, such as malformed JSON due to hallucinations, by prompting the model to correct errors up to a configurable retry limit.[50] This approach ensures robust post-processing, with parsers implementing the Runnable interface for chaining with models.
To optimize for production environments, LangChain's model invocations support efficient patterns like batch processing and asynchronous execution. The batch method processes multiple inputs in parallel using thread pools, reducing latency for high-volume tasks, while abatch and ainvoke enable concurrent async operations via asyncio, ideal for scalable deployments handling numerous requests.[48] These features, combined with token management and streaming, allow developers to build responsive applications without custom orchestration code.
Advanced Features
Agents and Tools
In LangChain, agents are autonomous systems powered by large language models (LLMs) that dynamically decide on sequences of actions to accomplish tasks, rather than following predefined chains of operations. These agents leverage the LLM as a reasoning engine to select appropriate tools, execute them, and iterate based on observations until reaching a resolution. This approach enables more flexible and adaptive interactions with external environments, such as querying databases or performing computations, by interleaving thought processes with actionable steps.[51] A prominent agent type in LangChain is the ReAct agent, which implements the ReAct paradigm of synergizing reasoning and acting, as introduced in the seminal work on ReAct.[52] As of LangChain v1.0 (October 2025), legacy functions likecreate_react_agent have been deprecated; the recommended way to create ReAct agents is via create_agent in langchain.agents, which integrates an LLM, a prompt template, and a list of tools. For more advanced agent workflows, including stateful and multi-actor applications, see the LangGraph section.[53]
Tools in LangChain serve as the interfaces that allow agents to interact with external systems or perform computations beyond the LLM's inherent capabilities. Each tool is defined with a name, description, and schema for inputs and outputs, enabling the agent to select and invoke it based on the task context. Pre-built tools include integrations like SerpAPI for web search, which enables real-time information retrieval, and mathematical utilities such as a calculator for arithmetic operations. LangChain also provides toolkits, such as the official GitHub Toolkit, which offers capabilities including fetching and listing issues, commenting on issues and pull requests, creating and updating files, opening pull requests, and searching repositories.[54] Custom tools can be created by wrapping Python functions with the @tool decorator, which automatically generates the necessary schema from function signatures and docstrings; for example, a function to fetch weather data could be decorated and bound to an agent for location-based queries. These tools are passed as a list to the agent during initialization, allowing the LLM to reference their descriptions in its decision-making process.
The legacy AgentExecutor class, deprecated in LangChain v1.0 (October 2025), previously managed the runtime loop for agent execution by handling cycles of observation, reasoning, action, and feedback until task completion, with safeguards like maximum iterations to prevent infinite loops. Current agent execution uses LCEL runnables or LangGraph for more robust handling, supporting asynchronous execution and callbacks for monitoring progress. For example, in a ReAct setup, the system would parse the LLM's output for tool calls, run the selected tool, and append the result to the conversation history for subsequent reasoning steps.[53]
As of LangChain v1.0 (October 2025), basic multi-agent configurations in core LangChain—where a central agent coordinates specialized sub-agents for divided tasks—are deprecated. Recommended multi-agent systems, including supervisor-worker hierarchies, are built using LangGraph's graph-based orchestration (see the LangGraph section). Legacy core setups used simple prompting and execution loops for collaborative problem-solving, such as one agent handling data retrieval while another performs analysis.[27]
Both LangChain and Dify support agent types and strategies including ReAct, tool calling, and multi-agent collaboration. LangChain offers built-in agents such as Plan-and-Execute via LangGraph, which enables custom state machines with loops and human-in-the-loop capabilities for advanced workflows. In comparison, Dify provides Agent nodes that integrate strategies like reflection and planning within visual workflows, facilitating easier design of autonomous agents.[55][56][57]
Memory and Retrieval
LangChain incorporates memory mechanisms to manage state across interactions, enabling large language model (LLM) applications to retain and utilize context from previous exchanges. This state management is crucial for conversational agents and chains that require awareness of prior inputs and outputs. As of LangChain v1.0 (October 2025), many legacy memory types have been deprecated in favor of LCEL-compatible runnables and LangGraph checkpointers for persistence. Memory types are designed to handle short-term chat history or extract and store key information for longer-term recall, preventing the need to reprocess full histories in each LLM call.[58] A fundamental memory type is ConversationBufferMemory, which maintains a simple buffer of the entire conversation history as a list of messages or a formatted string. It appends new human and AI messages to this buffer after each interaction and returns the full history when prompted, making it suitable for short-term retention in straightforward chat applications. For instance, in a conversational chain, this memory ensures the LLM receives the cumulative dialogue as context, though it may become inefficient for extended sessions due to token limits. For production use, integrate with LangGraph'sInMemorySaver or database-backed checkpointers for thread-level persistence.[59][60][61]
The legacy ConversationEntityMemory, deprecated since LangChain v0.3.4 and removed in v1.0.0, previously extracted named entities—such as people, places, or concepts—from recent chat history using an LLM and generated concise summaries for each, stored in an entity store for retrieval across sessions. Current alternatives include custom entity extraction via LLM tools or LangGraph state management with custom schemas to track entities.[62]
Retrieval capabilities in LangChain augment LLM context by integrating external knowledge sources through semantic search, addressing limitations in models' parametric knowledge. Vector stores, such as FAISS (Facebook AI Similarity Search), index high-dimensional embeddings of documents to enable fast approximate nearest-neighbor searches based on query similarity. Embeddings, generated by models like those from OpenAI or Hugging Face, represent text chunks as vectors capturing semantic meaning, allowing retrieval of contextually relevant passages even for paraphrased queries. For instance, to perform a filtered similarity search in a FAISS vectorstore, use: vectorstore.similarity_search(query, k=10, filter={'document_type': {'$eq': 'tiendas_fisicas'}}). This filters results to chunks matching the metadata condition, reducing noise from irrelevant documents.[63][64]
Building effective retrieval indexes involves document loaders, text splitters, and embedders to create searchable corpora from raw data. Document loaders provide a standard interface for ingesting data from diverse sources into LangChain's Document format, which includes text and metadata. Quality document loading is foundational for RAG systems—errors or omissions at this stage can propagate through the entire pipeline. Supported formats typically include PDF, Word documents, PowerPoint, HTML, Markdown, plain text, CSV, and JSON. Data sources encompass local files, cloud storage such as S3, Google Drive, and Azure Blob, databases, web scraping, and SaaS applications like Notion, Confluence, and Slack. Document loader quality varies significantly by format and library, with PDFs particularly requiring careful handling due to layout complexity. LangChain and LlamaIndex offer extensive collections of loaders, while for production systems, dedicated parsing services like Unstructured.io often provide superior quality compared to basic loaders.[28][65] Text splitters then partition these documents into overlapping chunks—typically by character count, tokens, or semantic boundaries—to fit LLM context windows while preserving meaning. Embedders subsequently transform these chunks into vectors, which are persisted in the vector store for querying via retrievers that return the top-k most similar documents. This pipeline enables scalable knowledge bases for RAG applications.
To extend memory beyond ephemeral sessions, LangChain supports long-term persistence through integrations with databases, facilitating episodic (event-based) or procedural (step-based) recall. For entity tracking, use custom state in LangGraph with stores like Redis or SQLite. Chat message histories can persist full conversation buffers in databases such as PostgreSQL, Azure CosmosDB, or Xata, allowing retrieval of past interactions for multi-session continuity via checkpointers. These persistent stores ensure memory survives application restarts, supporting production-scale applications where context spans user sessions or evolves over time. In agent loops, such retrieval can briefly provide historical context to inform tool selection or action planning.[66][67][61]
LangGraph
Graph-Based Architecture
The core design philosophy of LangGraph is graph-based; it models workflows as state machines with nodes for agents/tools and edges for conditional transitions; it supports explicit state, branching, loops, and persistence.[57] LangGraph employs a graph-based architecture to model complex, stateful workflows, where the core elements consist of nodes, edges, and a shared state mechanism. Nodes represent individual units of computation, such as function calls or invocations of large language models (LLMs), which process and update the graph's state. Edges define the flow between nodes, including fixed transitions that proceed to a predetermined next node or conditional edges that dynamically route execution based on the current state, enabling branching logic. The shared state serves as a persistent data structure—typically defined using a TypedDict, Pydantic model, or the built-in MessagesState for conversational contexts—that is passed and modified across all nodes and edges, ensuring continuity throughout the workflow.[68][57] Graphs in LangGraph are constructed using the StateGraph class, which requires specifying a state schema to initialize the structure. Developers add nodes via the .add_node method, associating each with a callable function, and connect them using .add_edge for direct links or .add_conditional_edges for logic-driven paths, where a routing function evaluates the state to select the next node. To enable persistence, the graph is compiled with a checkpointer, such as MemorySaver for in-memory storage or database-backed options like PostgresSaver, which captures state snapshots at each step and associates them with thread identifiers. This allows workflows to resume from interruptions, maintaining thread-specific state without restarting from the beginning.[69][70] This architecture excels in handling cyclical processes that require iteration or external input, such as iterative refinement where an agent repeatedly evaluates and improves its outputs until meeting predefined criteria, or human-in-the-loop approvals that pause execution for manual review before proceeding. For instance, to implement a human-in-the-loop workflow, developers can add a special node or tool that triggers human review, such as via an API call or by using an interrupt mechanism. After human approval, the state can be modified using .update_state() to incorporate the feedback. The graph is then compiled with options like interrupt_before=["human_review_node"] to pause execution at the specified node, ensuring controllability in sensitive domains like finance or healthcare.[71][72] A research agent might loop through search, analysis, and validation nodes, using conditional edges to decide whether to refine results based on quality checks.[57][27] With the October 2025 release of LangChain 1.0, which uses LangGraph as its underlying runtime, native support for middleware was introduced within agent loops. This allows developers to insert custom hooks at key points such as before or after model calls, enhancing flexibility for features like automated summarization, privacy redaction, or seamless integration of human oversight. This middleware system builds on the core graph primitives to facilitate custom persistence strategies, enabling more robust handling of long-running, interruptible workflows without altering the underlying state management.[27][73]Example: Building a Core Workflow for a Gmail AI Agent
LangGraph's graph-based architecture is particularly suited for building AI agents that interact with external services, such as a Gmail AI agent for tasks like reading, composing, or managing emails. The following outlines the core steps to construct such a workflow, adapted from official tutorials for agentic applications.[74][75] First, define theAgentState using TypedDict to manage the workflow's state, typically including a sequence of messages that accumulates over iterations:
from typing import Annotated, Sequence
import operator
from langchain_core.messages import BaseMessage
from typing_extensions import TypedDict
class AgentState(TypedDict):
messages: Annotated[Sequence[BaseMessage], operator.add]
from typing import Annotated, Sequence
import operator
from langchain_core.messages import BaseMessage
from typing_extensions import TypedDict
class AgentState(TypedDict):
messages: Annotated[Sequence[BaseMessage], operator.add]
MessagesPlaceholder to insert the conversation history:
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
system_prompt = "You are a helpful assistant that can interact with Gmail to read, send, or manage emails."
prompt = ChatPromptTemplate.from_messages([
("system", system_prompt),
MessagesPlaceholder(variable_name="messages"),
])
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
system_prompt = "You are a helpful assistant that can interact with Gmail to read, send, or manage emails."
prompt = ChatPromptTemplate.from_messages([
("system", system_prompt),
MessagesPlaceholder(variable_name="messages"),
])
from langchain_core.tools import tool
from langchain_core.tools import tool
Example Gmail tool (implementation depends on Gmail API integration)
@tool def read_gmail_emails(query: str): """Read emails from Gmail based on a query.""" # Implementation here pass @tool def send_gmail_email(to: str, subject: str, body: str): """Send an email via Gmail.""" # Implementation here pass llm_with_tools = llm.bind_tools([read_gmail_emails, send_gmail_email])
Define the `agent_node` function to invoke the LLM with the current state and return an `AIMessage`:
```python
from langchain_core.messages import AIMessage
def agent_node(state: AgentState):
messages = prompt.format_messages(**state)
response = llm_with_tools.invoke(messages)
return {"messages": [response]}
Define the `agent_node` function to invoke the LLM with the current state and return an `AIMessage`:
```python
from langchain_core.messages import AIMessage
def agent_node(state: AgentState):
messages = prompt.format_messages(**state)
response = llm_with_tools.invoke(messages)
return {"messages": [response]}
def router(state: AgentState):
last_message = state["messages"][-1]
if isinstance(last_message, AIMessage) and last_message.tool_calls:
return "tools"
return "end"
def router(state: AgentState):
last_message = state["messages"][-1]
if isinstance(last_message, AIMessage) and last_message.tool_calls:
return "tools"
return "end"
StateGraph, add nodes for the agent and tools, and define edges: from the start to the agent, a conditional edge from the agent to tools or end, and from tools back to the agent:
from langgraph.graph import StateGraph, END
workflow = StateGraph(state_schema=AgentState)
workflow.add_node("agent", agent_node)
workflow.add_node("tools", tool_node) # Define tool_node to call tools and append results
workflow.set_entry_point("agent")
workflow.add_conditional_edges("agent", router, {"tools": "tools", "end": END})
workflow.add_edge("tools", "agent")
from langgraph.graph import StateGraph, END
workflow = StateGraph(state_schema=AgentState)
workflow.add_node("agent", agent_node)
workflow.add_node("tools", tool_node) # Define tool_node to call tools and append results
workflow.set_entry_point("agent")
workflow.add_conditional_edges("agent", router, {"tools": "tools", "end": END})
workflow.add_edge("tools", "agent")
from langgraph.checkpoint.memory import MemorySaver
app = workflow.compile(checkpointer=MemorySaver())
from langgraph.checkpoint.memory import MemorySaver
app = workflow.compile(checkpointer=MemorySaver())
