Home / Class/ NatBotChain Class — langchain Architecture

NatBotChain Class — langchain Architecture

Architecture documentation for the NatBotChain class in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  9171cff6_74d4_b785_eb4e_31a83af8c002["NatBotChain"]
  f3cef70e_11b0_61c9_7ec0_7308f4b45056["Chain"]
  9171cff6_74d4_b785_eb4e_31a83af8c002 -->|extends| f3cef70e_11b0_61c9_7ec0_7308f4b45056
  8439c834_66c2_081d_097c_a1945000c8b7["base.py"]
  9171cff6_74d4_b785_eb4e_31a83af8c002 -->|defined in| 8439c834_66c2_081d_097c_a1945000c8b7
  c241bd80_7275_1877_777c_af2c946ef70b["_raise_deprecation()"]
  9171cff6_74d4_b785_eb4e_31a83af8c002 -->|method| c241bd80_7275_1877_777c_af2c946ef70b
  f5dc12b9_763d_923e_5f22_bd38cf4d8fa7["from_default()"]
  9171cff6_74d4_b785_eb4e_31a83af8c002 -->|method| f5dc12b9_763d_923e_5f22_bd38cf4d8fa7
  c16575c9_7d3c_386e_2f1e_286d9846f11f["from_llm()"]
  9171cff6_74d4_b785_eb4e_31a83af8c002 -->|method| c16575c9_7d3c_386e_2f1e_286d9846f11f
  cb67b07d_a55a_dccd_2ded_c3147279f0da["input_keys()"]
  9171cff6_74d4_b785_eb4e_31a83af8c002 -->|method| cb67b07d_a55a_dccd_2ded_c3147279f0da
  705eec99_3ffc_95cf_2ef4_24fa7443481a["output_keys()"]
  9171cff6_74d4_b785_eb4e_31a83af8c002 -->|method| 705eec99_3ffc_95cf_2ef4_24fa7443481a
  2a6cded1_052c_4c8e_d2e6_a5e53382a416["_call()"]
  9171cff6_74d4_b785_eb4e_31a83af8c002 -->|method| 2a6cded1_052c_4c8e_d2e6_a5e53382a416
  f0c79b75_5b37_ef34_73c2_cae9dacbf226["execute()"]
  9171cff6_74d4_b785_eb4e_31a83af8c002 -->|method| f0c79b75_5b37_ef34_73c2_cae9dacbf226
  836b2466_f411_2682_09d2_41e38dab1e6a["_chain_type()"]
  9171cff6_74d4_b785_eb4e_31a83af8c002 -->|method| 836b2466_f411_2682_09d2_41e38dab1e6a

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/natbot/base.py lines 29–158

class NatBotChain(Chain):
    """Implement an LLM driven browser.

    **Security Note**: This toolkit provides code to control a web-browser.

        The web-browser can be used to navigate to:

        - Any URL (including any internal network URLs)
        - And local files

        Exercise care if exposing this chain to end-users. Control who is able to
        access and use this chain, and isolate the network access of the server
        that hosts this chain.

        See https://docs.langchain.com/oss/python/security-policy for more information.

    Example:
        ```python
        from langchain_classic.chains import NatBotChain

        natbot = NatBotChain.from_default("Buy me a new hat.")
        ```
    """

    llm_chain: Runnable
    objective: str
    """Objective that NatBot is tasked with completing."""
    llm: BaseLanguageModel | None = None
    """[Deprecated] LLM wrapper to use."""
    input_url_key: str = "url"
    input_browser_content_key: str = "browser_content"
    previous_command: str = ""
    output_key: str = "command"

    model_config = ConfigDict(
        arbitrary_types_allowed=True,
        extra="forbid",
    )

    @model_validator(mode="before")
    @classmethod
    def _raise_deprecation(cls, values: dict) -> Any:
        if "llm" in values:
            warnings.warn(
                "Directly instantiating an NatBotChain with an llm is deprecated. "
                "Please instantiate with llm_chain argument or using the from_llm "
                "class method.",
                stacklevel=5,
            )
            if "llm_chain" not in values and values["llm"] is not None:
                values["llm_chain"] = PROMPT | values["llm"] | StrOutputParser()
        return values

    @classmethod
    def from_default(cls, objective: str, **kwargs: Any) -> NatBotChain:
        """Load with default LLMChain."""
        msg = (
            "This method is no longer implemented. Please use from_llm."
            "model = OpenAI(temperature=0.5, best_of=10, n=3, max_tokens=50)"
            "For example, NatBotChain.from_llm(model, objective)"
        )
        raise NotImplementedError(msg)

    @classmethod
    def from_llm(
        cls,
        llm: BaseLanguageModel,
        objective: str,
        **kwargs: Any,
    ) -> NatBotChain:
        """Load from LLM."""
        llm_chain = PROMPT | llm | StrOutputParser()
        return cls(llm_chain=llm_chain, objective=objective, **kwargs)

    @property
    def input_keys(self) -> list[str]:
        """Expect url and browser content."""
        return [self.input_url_key, self.input_browser_content_key]

    @property
    def output_keys(self) -> list[str]:

Extends

Frequently Asked Questions

What is the NatBotChain class?
NatBotChain is a class in the langchain codebase, defined in libs/langchain/langchain_classic/chains/natbot/base.py.
Where is NatBotChain defined?
NatBotChain is defined in libs/langchain/langchain_classic/chains/natbot/base.py at line 29.
What does NatBotChain extend?
NatBotChain extends Chain.

Analyze Your Own Codebase

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

Try Supermodel Free