Home / File/ loading.py — langchain Source File

loading.py — langchain Source File

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

File python AgentOrchestration ClassicChains 11 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  d9d11983_4e03_a879_46b9_4ceabb6795a1["loading.py"]
  9d14ea65_8b2e_6721_a947_acc89905651f["json"]
  d9d11983_4e03_a879_46b9_4ceabb6795a1 --> 9d14ea65_8b2e_6721_a947_acc89905651f
  e27da29f_a1f7_49f3_84d5_6be4cb4125c8["logging"]
  d9d11983_4e03_a879_46b9_4ceabb6795a1 --> e27da29f_a1f7_49f3_84d5_6be4cb4125c8
  927570d8_11a6_5c17_0f0d_80baae0c733e["pathlib"]
  d9d11983_4e03_a879_46b9_4ceabb6795a1 --> 927570d8_11a6_5c17_0f0d_80baae0c733e
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  d9d11983_4e03_a879_46b9_4ceabb6795a1 --> feec1ec4_6917_867b_d228_b134d0ff8099
  a869785a_d507_1688_0b32_0ec94043975a["yaml"]
  d9d11983_4e03_a879_46b9_4ceabb6795a1 --> a869785a_d507_1688_0b32_0ec94043975a
  2485b66a_3839_d0b6_ad9c_a4ff40457dc6["langchain_core._api"]
  d9d11983_4e03_a879_46b9_4ceabb6795a1 --> 2485b66a_3839_d0b6_ad9c_a4ff40457dc6
  e929cf21_6ab8_6ff3_3765_0d35a099a053["langchain_core.language_models"]
  d9d11983_4e03_a879_46b9_4ceabb6795a1 --> e929cf21_6ab8_6ff3_3765_0d35a099a053
  121262a1_0bd6_d637_bce3_307ab6b3ecd4["langchain_core.tools"]
  d9d11983_4e03_a879_46b9_4ceabb6795a1 --> 121262a1_0bd6_d637_bce3_307ab6b3ecd4
  496466eb_d5c8_fece_1b1f_31541c641cdd["langchain_classic.agents.agent"]
  d9d11983_4e03_a879_46b9_4ceabb6795a1 --> 496466eb_d5c8_fece_1b1f_31541c641cdd
  32dc9588_b1fb_eb64_8d02_07eeee85c3d6["langchain_classic.agents.types"]
  d9d11983_4e03_a879_46b9_4ceabb6795a1 --> 32dc9588_b1fb_eb64_8d02_07eeee85c3d6
  ab4cf587_1c33_d7f6_a420_8f5e421fbb3b["langchain_classic.chains.loading"]
  d9d11983_4e03_a879_46b9_4ceabb6795a1 --> ab4cf587_1c33_d7f6_a420_8f5e421fbb3b
  style d9d11983_4e03_a879_46b9_4ceabb6795a1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Functionality for loading agents."""

import json
import logging
from pathlib import Path
from typing import Any

import yaml
from langchain_core._api import deprecated
from langchain_core.language_models import BaseLanguageModel
from langchain_core.tools import Tool

from langchain_classic.agents.agent import BaseMultiActionAgent, BaseSingleActionAgent
from langchain_classic.agents.types import AGENT_TO_CLASS
from langchain_classic.chains.loading import load_chain, load_chain_from_config

logger = logging.getLogger(__name__)

URL_BASE = "https://raw.githubusercontent.com/hwchase17/langchain-hub/master/agents/"


def _load_agent_from_tools(
    config: dict,
    llm: BaseLanguageModel,
    tools: list[Tool],
    **kwargs: Any,
) -> BaseSingleActionAgent | BaseMultiActionAgent:
    config_type = config.pop("_type")
    if config_type not in AGENT_TO_CLASS:
        msg = f"Loading {config_type} agent not supported"
        raise ValueError(msg)

    agent_cls = AGENT_TO_CLASS[config_type]
    combined_config = {**config, **kwargs}
    return agent_cls.from_llm_and_tools(llm, tools, **combined_config)


@deprecated("0.1.0", removal="1.0")
def load_agent_from_config(
    config: dict,
    llm: BaseLanguageModel | None = None,
    tools: list[Tool] | None = None,
    **kwargs: Any,
) -> BaseSingleActionAgent | BaseMultiActionAgent:
    """Load agent from Config Dict.

    Args:
        config: Config dict to load agent from.
        llm: Language model to use as the agent.
        tools: List of tools this agent has access to.
        kwargs: Additional keyword arguments passed to the agent executor.

    Returns:
        An agent executor.

    Raises:
        ValueError: If agent type is not specified in the config.
    """
    if "_type" not in config:
        msg = "Must specify an agent Type in config"
// ... (89 more lines)

Subdomains

Dependencies

  • json
  • langchain_classic.agents.agent
  • langchain_classic.agents.types
  • langchain_classic.chains.loading
  • langchain_core._api
  • langchain_core.language_models
  • langchain_core.tools
  • logging
  • pathlib
  • typing
  • yaml

Frequently Asked Questions

What does loading.py do?
loading.py is a source file in the langchain codebase, written in python. It belongs to the AgentOrchestration domain, ClassicChains subdomain.
What functions are defined in loading.py?
loading.py defines 4 function(s): _load_agent_from_file, _load_agent_from_tools, load_agent, load_agent_from_config.
What does loading.py depend on?
loading.py imports 11 module(s): json, langchain_classic.agents.agent, langchain_classic.agents.types, langchain_classic.chains.loading, langchain_core._api, langchain_core.language_models, langchain_core.tools, logging, and 3 more.
Where is loading.py in the architecture?
loading.py is located at libs/langchain/langchain_classic/agents/loading.py (domain: AgentOrchestration, subdomain: ClassicChains, directory: libs/langchain/langchain_classic/agents).

Analyze Your Own Codebase

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

Try Supermodel Free