Home / File/ base.py — langchain Source File

base.py — langchain Source File

Architecture documentation for base.py, a python file in the langchain codebase. 17 imports, 0 dependents.

File python AgentOrchestration ToolInterface 17 imports 1 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  9ccefa56_209b_c990_304c_d902563c789e["base.py"]
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  9ccefa56_209b_c990_304c_d902563c789e --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  9ccefa56_209b_c990_304c_d902563c789e --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  b19a8b7e_fbee_95b1_65b8_509a1ed3cad7["langchain_core._api"]
  9ccefa56_209b_c990_304c_d902563c789e --> b19a8b7e_fbee_95b1_65b8_509a1ed3cad7
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  9ccefa56_209b_c990_304c_d902563c789e --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  ba43b74d_3099_7e1c_aac3_cf594720469e["langchain_core.language_models"]
  9ccefa56_209b_c990_304c_d902563c789e --> ba43b74d_3099_7e1c_aac3_cf594720469e
  e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"]
  9ccefa56_209b_c990_304c_d902563c789e --> e6b4f61e_7b98_6666_3641_26b069517d4a
  43d88577_548b_2248_b01b_7987bae85dcc["langchain_core.tools"]
  9ccefa56_209b_c990_304c_d902563c789e --> 43d88577_548b_2248_b01b_7987bae85dcc
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  9ccefa56_209b_c990_304c_d902563c789e --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  9ccefa56_209b_c990_304c_d902563c789e --> 91721f45_4909_e489_8c1f_084f8bd87145
  0569002b_723c_e521_6645_d02d74dd6913["langchain_classic._api.deprecation"]
  9ccefa56_209b_c990_304c_d902563c789e --> 0569002b_723c_e521_6645_d02d74dd6913
  e160f068_75de_4342_6673_9969b919de85["langchain_classic.agents.agent"]
  9ccefa56_209b_c990_304c_d902563c789e --> e160f068_75de_4342_6673_9969b919de85
  8bc2eee7_b040_0edd_0172_48295cb3fb89["langchain_classic.agents.agent_types"]
  9ccefa56_209b_c990_304c_d902563c789e --> 8bc2eee7_b040_0edd_0172_48295cb3fb89
  ff06b770_3aa7_8efa_55ca_a93e9e7338fb["langchain_classic.agents.react.output_parser"]
  9ccefa56_209b_c990_304c_d902563c789e --> ff06b770_3aa7_8efa_55ca_a93e9e7338fb
  2d3aff76_df6e_5d03_ab0b_43eb35e08ec2["langchain_classic.agents.react.textworld_prompt"]
  9ccefa56_209b_c990_304c_d902563c789e --> 2d3aff76_df6e_5d03_ab0b_43eb35e08ec2
  style 9ccefa56_209b_c990_304c_d902563c789e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Chain that implements the ReAct paper from https://arxiv.org/pdf/2210.03629.pdf."""

from __future__ import annotations

from collections.abc import Sequence
from typing import TYPE_CHECKING, Any

from langchain_core._api import deprecated
from langchain_core.documents import Document
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts import BasePromptTemplate
from langchain_core.tools import BaseTool, Tool
from pydantic import Field
from typing_extensions import override

from langchain_classic._api.deprecation import AGENT_DEPRECATION_WARNING
from langchain_classic.agents.agent import Agent, AgentExecutor, AgentOutputParser
from langchain_classic.agents.agent_types import AgentType
from langchain_classic.agents.react.output_parser import ReActOutputParser
from langchain_classic.agents.react.textworld_prompt import TEXTWORLD_PROMPT
from langchain_classic.agents.react.wiki_prompt import WIKI_PROMPT
from langchain_classic.agents.utils import validate_tools_single_input

if TYPE_CHECKING:
    from langchain_community.docstore.base import Docstore


_LOOKUP_AND_SEARCH_TOOLS = {"Lookup", "Search"}


@deprecated(
    "0.1.0",
    message=AGENT_DEPRECATION_WARNING,
    removal="1.0",
)
class ReActDocstoreAgent(Agent):
    """Agent for the ReAct chain."""

    output_parser: AgentOutputParser = Field(default_factory=ReActOutputParser)

    @classmethod
    @override
    def _get_default_output_parser(cls, **kwargs: Any) -> AgentOutputParser:
        return ReActOutputParser()

    @property
    def _agent_type(self) -> str:
        """Return Identifier of an agent type."""
        return AgentType.REACT_DOCSTORE

    @classmethod
    @override
    def create_prompt(cls, tools: Sequence[BaseTool]) -> BasePromptTemplate:
        """Return default prompt."""
        return WIKI_PROMPT

    @classmethod
    def _validate_tools(cls, tools: Sequence[BaseTool]) -> None:
        validate_tools_single_input(cls.__name__, tools)
        super()._validate_tools(tools)
// ... (130 more lines)

Subdomains

Dependencies

  • collections.abc
  • langchain_classic._api.deprecation
  • langchain_classic.agents.agent
  • langchain_classic.agents.agent_types
  • langchain_classic.agents.react.output_parser
  • langchain_classic.agents.react.textworld_prompt
  • langchain_classic.agents.react.wiki_prompt
  • langchain_classic.agents.utils
  • langchain_community.docstore.base
  • langchain_core._api
  • langchain_core.documents
  • langchain_core.language_models
  • langchain_core.prompts
  • langchain_core.tools
  • pydantic
  • typing
  • typing_extensions

Frequently Asked Questions

What does base.py do?
base.py is a source file in the langchain codebase, written in python. It belongs to the AgentOrchestration domain, ToolInterface subdomain.
What functions are defined in base.py?
base.py defines 1 function(s): langchain_community.
What does base.py depend on?
base.py imports 17 module(s): collections.abc, langchain_classic._api.deprecation, langchain_classic.agents.agent, langchain_classic.agents.agent_types, langchain_classic.agents.react.output_parser, langchain_classic.agents.react.textworld_prompt, langchain_classic.agents.react.wiki_prompt, langchain_classic.agents.utils, and 9 more.
Where is base.py in the architecture?
base.py is located at libs/langchain/langchain_classic/agents/react/base.py (domain: AgentOrchestration, subdomain: ToolInterface, directory: libs/langchain/langchain_classic/agents/react).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free