Home / Function/ from_llm_and_tools() — langchain Function Reference

from_llm_and_tools() — langchain Function Reference

Architecture documentation for the from_llm_and_tools() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  792d39b0_6cc6_56c1_0b6c_cc11d6f11d45["from_llm_and_tools()"]
  37dfdb3a_fc75_8e43_a082_e000915175c2["ConversationalChatAgent"]
  792d39b0_6cc6_56c1_0b6c_cc11d6f11d45 -->|defined in| 37dfdb3a_fc75_8e43_a082_e000915175c2
  37ebc42f_11ae_0dcf_a66a_08e26fb475df["_validate_tools()"]
  792d39b0_6cc6_56c1_0b6c_cc11d6f11d45 -->|calls| 37ebc42f_11ae_0dcf_a66a_08e26fb475df
  5e0d227f_9765_818c_3c02_743fc1bc0c86["_get_default_output_parser()"]
  792d39b0_6cc6_56c1_0b6c_cc11d6f11d45 -->|calls| 5e0d227f_9765_818c_3c02_743fc1bc0c86
  a6206bc9_89e6_ac37_3164_590e3974b4f6["create_prompt()"]
  792d39b0_6cc6_56c1_0b6c_cc11d6f11d45 -->|calls| a6206bc9_89e6_ac37_3164_590e3974b4f6
  style 792d39b0_6cc6_56c1_0b6c_cc11d6f11d45 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/conversational_chat/base.py lines 135–181

    def from_llm_and_tools(
        cls,
        llm: BaseLanguageModel,
        tools: Sequence[BaseTool],
        callback_manager: BaseCallbackManager | None = None,
        output_parser: AgentOutputParser | None = None,
        system_message: str = PREFIX,
        human_message: str = SUFFIX,
        input_variables: list[str] | None = None,
        **kwargs: Any,
    ) -> Agent:
        """Construct an agent from an LLM and tools.

        Args:
            llm: The language model to use.
            tools: A list of tools to use.
            callback_manager: The callback manager to use.
            output_parser: The output parser to use.
            system_message: The `SystemMessage` to use.
            human_message: The `HumanMessage` to use.
            input_variables: The input variables to use.
            **kwargs: Any additional arguments.

        Returns:
            An agent.
        """
        cls._validate_tools(tools)
        _output_parser = output_parser or cls._get_default_output_parser()
        prompt = cls.create_prompt(
            tools,
            system_message=system_message,
            human_message=human_message,
            input_variables=input_variables,
            output_parser=_output_parser,
        )
        llm_chain = LLMChain(
            llm=llm,
            prompt=prompt,
            callback_manager=callback_manager,
        )
        tool_names = [tool.name for tool in tools]
        return cls(
            llm_chain=llm_chain,
            allowed_tools=tool_names,
            output_parser=_output_parser,
            **kwargs,
        )

Subdomains

Frequently Asked Questions

What does from_llm_and_tools() do?
from_llm_and_tools() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/conversational_chat/base.py.
Where is from_llm_and_tools() defined?
from_llm_and_tools() is defined in libs/langchain/langchain_classic/agents/conversational_chat/base.py at line 135.
What does from_llm_and_tools() call?
from_llm_and_tools() calls 3 function(s): _get_default_output_parser, _validate_tools, create_prompt.

Analyze Your Own Codebase

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

Try Supermodel Free