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
  b33ef912_f36b_c48c_f62d_fdb8762ff5d4["from_llm_and_tools()"]
  e7474b7d_7c6f_343d_99cb_0f111d536a66["ChatAgent"]
  b33ef912_f36b_c48c_f62d_fdb8762ff5d4 -->|defined in| e7474b7d_7c6f_343d_99cb_0f111d536a66
  ade3b771_d1c2_346a_2725_0ecd3515703f["_validate_tools()"]
  b33ef912_f36b_c48c_f62d_fdb8762ff5d4 -->|calls| ade3b771_d1c2_346a_2725_0ecd3515703f
  dd42c06c_77f0_b662_e83b_319540fa0e7e["create_prompt()"]
  b33ef912_f36b_c48c_f62d_fdb8762ff5d4 -->|calls| dd42c06c_77f0_b662_e83b_319540fa0e7e
  f1ae4f3c_c37e_e3b9_1325_f1c0533ba4be["_get_default_output_parser()"]
  b33ef912_f36b_c48c_f62d_fdb8762ff5d4 -->|calls| f1ae4f3c_c37e_e3b9_1325_f1c0533ba4be
  style b33ef912_f36b_c48c_f62d_fdb8762ff5d4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/chat/base.py lines 123–174

    def from_llm_and_tools(
        cls,
        llm: BaseLanguageModel,
        tools: Sequence[BaseTool],
        callback_manager: BaseCallbackManager | None = None,
        output_parser: AgentOutputParser | None = None,
        system_message_prefix: str = SYSTEM_MESSAGE_PREFIX,
        system_message_suffix: str = SYSTEM_MESSAGE_SUFFIX,
        human_message: str = HUMAN_MESSAGE,
        format_instructions: str = FORMAT_INSTRUCTIONS,
        input_variables: list[str] | None = None,
        **kwargs: Any,
    ) -> Agent:
        """Construct an agent from an LLM and tools.

        Args:
            llm: The language model.
            tools: A list of tools.
            callback_manager: The callback manager.
            output_parser: The output parser.
            system_message_prefix: The system message prefix.
            system_message_suffix: The system message suffix.
            human_message: The `HumanMessage`.
            format_instructions: The format instructions.
            input_variables: The input variables.
            kwargs: Additional keyword arguments.

        Returns:
            An agent.
        """
        cls._validate_tools(tools)
        prompt = cls.create_prompt(
            tools,
            system_message_prefix=system_message_prefix,
            system_message_suffix=system_message_suffix,
            human_message=human_message,
            format_instructions=format_instructions,
            input_variables=input_variables,
        )
        llm_chain = LLMChain(
            llm=llm,
            prompt=prompt,
            callback_manager=callback_manager,
        )
        tool_names = [tool.name for tool in tools]
        _output_parser = output_parser or cls._get_default_output_parser()
        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/chat/base.py.
Where is from_llm_and_tools() defined?
from_llm_and_tools() is defined in libs/langchain/langchain_classic/agents/chat/base.py at line 123.
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