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 4036bc45_ce9e_61e8_00e6_622f409e339f["from_llm_and_tools()"] 826e6477_6abe_d406_5d34_9df3fbec8707["StructuredChatAgent"] 4036bc45_ce9e_61e8_00e6_622f409e339f -->|defined in| 826e6477_6abe_d406_5d34_9df3fbec8707 81ebad27_b83f_0f42_afc8_372e9551a3bf["_validate_tools()"] 4036bc45_ce9e_61e8_00e6_622f409e339f -->|calls| 81ebad27_b83f_0f42_afc8_372e9551a3bf 54ba14c3_66dc_1c53_97a4_c6a0c1b24dbd["create_prompt()"] 4036bc45_ce9e_61e8_00e6_622f409e339f -->|calls| 54ba14c3_66dc_1c53_97a4_c6a0c1b24dbd 9b0d5ae0_54f8_f509_bed8_ff75b67abd77["_get_default_output_parser()"] 4036bc45_ce9e_61e8_00e6_622f409e339f -->|calls| 9b0d5ae0_54f8_f509_bed8_ff75b67abd77 style 4036bc45_ce9e_61e8_00e6_622f409e339f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/structured_chat/base.py lines 122–159
def from_llm_and_tools(
cls,
llm: BaseLanguageModel,
tools: Sequence[BaseTool],
callback_manager: BaseCallbackManager | None = None,
output_parser: AgentOutputParser | None = None,
prefix: str = PREFIX,
suffix: str = SUFFIX,
human_message_template: str = HUMAN_MESSAGE_TEMPLATE,
format_instructions: str = FORMAT_INSTRUCTIONS,
input_variables: list[str] | None = None,
memory_prompts: list[BasePromptTemplate] | None = None,
**kwargs: Any,
) -> Agent:
"""Construct an agent from an LLM and tools."""
cls._validate_tools(tools)
prompt = cls.create_prompt(
tools,
prefix=prefix,
suffix=suffix,
human_message_template=human_message_template,
format_instructions=format_instructions,
input_variables=input_variables,
memory_prompts=memory_prompts,
)
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(llm=llm)
return cls(
llm_chain=llm_chain,
allowed_tools=tool_names,
output_parser=_output_parser,
**kwargs,
)
Domain
Subdomains
Source
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/structured_chat/base.py.
Where is from_llm_and_tools() defined?
from_llm_and_tools() is defined in libs/langchain/langchain_classic/agents/structured_chat/base.py at line 122.
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