or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

agents-tools.mdcallbacks-monitoring.mdchains-workflows.mddocument-processing.mdindex.mdmemory-context.md
tile.json

tessl/pypi-langchain

Building applications with LLMs through composability

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/langchain@0.3.x

To install, run

npx @tessl/cli install tessl/pypi-langchain@0.3.0

index.mddocs/

LangChain

A comprehensive Python framework for building applications powered by Large Language Models (LLMs) through composable components. LangChain provides a standard interface for models, embeddings, vector stores, and external integrations, enabling developers to create sophisticated AI applications with real-time data augmentation, model interoperability, and advanced agent orchestration capabilities.

Package Information

  • Package Name: langchain
  • Language: Python
  • Installation: pip install langchain
  • Version: 0.3.27

Core Imports

import langchain

For specific functionality, import from module namespaces:

from langchain.agents import initialize_agent, AgentType
from langchain.chains import LLMChain, ConversationChain
from langchain.callbacks import StreamingStdOutCallbackHandler
from langchain.memory import ConversationBufferMemory

Note: Many LangChain components have migrated to specialized packages for better modularity:

# Core abstractions (recommended)
from langchain_core.prompts import PromptTemplate
from langchain_core.messages import HumanMessage, AIMessage
from langchain_core.tools import BaseTool, tool

# Provider-specific components
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from langchain_anthropic import ChatAnthropic
from langchain_community.vectorstores import FAISS

Basic Usage

from langchain.chains import LLMChain
from langchain_core.prompts import PromptTemplate
from langchain_openai import OpenAI

# Create a simple LLM chain
llm = OpenAI(temperature=0.7)
prompt = PromptTemplate(
    input_variables=["topic"],
    template="Write a short poem about {topic}."
)

chain = LLMChain(llm=llm, prompt=prompt)
result = chain.run("artificial intelligence")
print(result)

More complex example with agents:

from langchain.agents import initialize_agent, AgentType
from langchain_community.tools import DuckDuckGoSearchRun
from langchain_openai import OpenAI

# Create tools and agent
search = DuckDuckGoSearchRun()
tools = [search]

llm = OpenAI(temperature=0)
agent = initialize_agent(
    tools, 
    llm, 
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True
)

# Run the agent
response = agent.run("What is the latest news about AI?")

Architecture

LangChain follows a modular architecture built around composable components:

  • Models: LLMs, Chat Models, and Embeddings providing AI capabilities
  • Prompts: Templates and management for model inputs
  • Chains: Sequences of components for complex workflows
  • Agents: AI systems that can use tools and make decisions
  • Memory: State management for conversations and context
  • Retrievers: Components for fetching relevant information
  • Tools: External system integrations for agents
  • Callbacks: Event handling and monitoring

This design enables maximum reusability across AI applications, chatbots, document analysis systems, and any application requiring intelligent language processing, with built-in support for retrieval-augmented generation (RAG), agent workflows, and production deployment patterns.

Migration Note

Important: LangChain v0.3.x serves primarily as an orchestration layer and compatibility interface. Most concrete implementations have moved to specialized packages:

  • langchain_core: Core abstractions and base classes
  • langchain_community: Third-party integrations and implementations
  • Provider packages: langchain_openai, langchain_anthropic, etc.

The main langchain package provides backward compatibility with deprecation warnings guiding migration to appropriate packages.

Capabilities

Agents and Tools

AI agents that can reason about which tools to use and when to use them. Agents can interact with external APIs, databases, search engines, and other systems to accomplish complex tasks autonomously.

def initialize_agent(tools, llm, agent=None, **kwargs):
    """Initialize an agent with tools and LLM."""

class AgentExecutor:
    """Execute agent actions with tools."""
    def run(self, input: str) -> str: ...
    def invoke(self, input: dict) -> dict: ...

class AgentType:
    """Enumeration of available agent types."""
    ZERO_SHOT_REACT_DESCRIPTION: str
    CHAT_ZERO_SHOT_REACT_DESCRIPTION: str
    CONVERSATIONAL_REACT_DESCRIPTION: str

Agents and Tools

Chains and Workflows

Composable sequences of operations that combine models, retrievers, and processing steps. Chains enable complex workflows like question-answering, summarization, and document analysis.

class LLMChain:
    """Chain for single LLM calls with prompt templates."""
    def __init__(self, llm, prompt, **kwargs): ...
    def run(self, **kwargs) -> str: ...
    def invoke(self, input: dict) -> dict: ...

class ConversationChain:
    """Chain for conversational interactions with memory."""
    def __init__(self, llm, memory=None, **kwargs): ...

class RetrievalQA:
    """Chain for question-answering with document retrieval."""
    @classmethod
    def from_chain_type(cls, llm, chain_type: str, retriever, **kwargs): ...

Chains and Workflows

Document Processing and Retrieval

Tools for loading, processing, and retrieving documents to enable retrieval-augmented generation (RAG) workflows. Supports various document types and vector storage backends.

class BaseRetriever:
    """Base class for document retrievers."""
    def get_relevant_documents(self, query: str) -> list: ...
    def invoke(self, input: str) -> list: ...

class VectorStoreRetriever:
    """Retriever backed by vector store."""
    def __init__(self, vectorstore, search_kwargs=None): ...

def create_retrieval_chain(retriever, combine_docs_chain):
    """Create a retrieval chain combining retriever and processing."""

Document Processing

Memory and Context Management

State management for maintaining conversation history, context, and intermediate results across interactions. Essential for building conversational AI applications.

class ConversationBufferMemory:
    """Buffer memory storing conversation history."""
    def __init__(self, memory_key: str = "history"): ...
    def save_context(self, inputs: dict, outputs: dict): ...
    def load_memory_variables(self, inputs: dict) -> dict: ...

class ConversationSummaryMemory:
    """Memory that summarizes conversation history."""
    def __init__(self, llm, memory_key: str = "history"): ...

class ConversationBufferWindowMemory:
    """Windowed buffer memory keeping recent messages."""
    def __init__(self, k: int = 5): ...

Memory and Context

Callbacks and Monitoring

Event handling system for monitoring, logging, and debugging LangChain operations. Supports streaming outputs, usage tracking, and integration with observability platforms.

class BaseCallbackHandler:
    """Base callback handler for LangChain events."""
    def on_llm_start(self, serialized: dict, prompts: list, **kwargs): ...
    def on_llm_end(self, response, **kwargs): ...
    def on_chain_start(self, serialized: dict, inputs: dict, **kwargs): ...

class StreamingStdOutCallbackHandler:
    """Stream LLM outputs to stdout."""

def tracing_enabled() -> bool:
    """Check if LangSmith tracing is enabled."""

Callbacks and Monitoring

Types

from typing import Any, Dict, List, Optional, Union
from langchain_core.messages import BaseMessage, HumanMessage, AIMessage, SystemMessage
from langchain_core.documents import Document
from langchain_core.prompts import BasePromptTemplate, PromptTemplate
from langchain_core.language_models import BaseLanguageModel, BaseLLM

class Document:
    """Document with content and metadata."""
    def __init__(self, page_content: str, metadata: dict = None): ...
    page_content: str
    metadata: dict

class BaseMessage:
    """Base message class for chat interactions."""
    content: str
    additional_kwargs: dict

class HumanMessage(BaseMessage):
    """Message from human user."""

class AIMessage(BaseMessage):
    """Message from AI assistant."""

class SystemMessage(BaseMessage):
    """System message for instructions."""