Home / Function/ load_agent_from_config() — langchain Function Reference

load_agent_from_config() — langchain Function Reference

Architecture documentation for the load_agent_from_config() function in loading.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  d135c558_d211_f5bf_c272_7dfd2fe8cc5b["load_agent_from_config()"]
  7f3891e0_2de6_b9ba_e16e_a9b4c825778b["loading.py"]
  d135c558_d211_f5bf_c272_7dfd2fe8cc5b -->|defined in| 7f3891e0_2de6_b9ba_e16e_a9b4c825778b
  36f609ad_1082_989b_c5d3_f0de4c508863["_load_agent_from_file()"]
  36f609ad_1082_989b_c5d3_f0de4c508863 -->|calls| d135c558_d211_f5bf_c272_7dfd2fe8cc5b
  a7f404c6_2d6b_85c1_339c_5a71c7f94df7["_load_agent_from_tools()"]
  d135c558_d211_f5bf_c272_7dfd2fe8cc5b -->|calls| a7f404c6_2d6b_85c1_339c_5a71c7f94df7
  style d135c558_d211_f5bf_c272_7dfd2fe8cc5b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/loading.py lines 39–98

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"
        raise ValueError(msg)
    load_from_tools = config.pop("load_from_llm_and_tools", False)
    if load_from_tools:
        if llm is None:
            msg = (
                "If `load_from_llm_and_tools` is set to True, then LLM must be provided"
            )
            raise ValueError(msg)
        if tools is None:
            msg = (
                "If `load_from_llm_and_tools` is set to True, "
                "then tools must be provided"
            )
            raise ValueError(msg)
        return _load_agent_from_tools(config, llm, tools, **kwargs)
    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]
    if "llm_chain" in config:
        config["llm_chain"] = load_chain_from_config(config.pop("llm_chain"))
    elif "llm_chain_path" in config:
        config["llm_chain"] = load_chain(config.pop("llm_chain_path"))
    else:
        msg = "One of `llm_chain` and `llm_chain_path` should be specified."
        raise ValueError(msg)
    if "output_parser" in config:
        logger.warning(
            "Currently loading output parsers on agent is not supported, "
            "will just use the default one.",
        )
        del config["output_parser"]

    combined_config = {**config, **kwargs}
    return agent_cls(**combined_config)

Subdomains

Frequently Asked Questions

What does load_agent_from_config() do?
load_agent_from_config() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/loading.py.
Where is load_agent_from_config() defined?
load_agent_from_config() is defined in libs/langchain/langchain_classic/agents/loading.py at line 39.
What does load_agent_from_config() call?
load_agent_from_config() calls 1 function(s): _load_agent_from_tools.
What calls load_agent_from_config()?
load_agent_from_config() is called by 1 function(s): _load_agent_from_file.

Analyze Your Own Codebase

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

Try Supermodel Free