initialize_agent#
- langchain.agents.initialize.initialize_agent(tools: Sequence[BaseTool], llm: BaseLanguageModel, agent: AgentType | None = None, callback_manager: BaseCallbackManager | None = None, agent_path: str | None = None, agent_kwargs: dict | None = None, *, tags: Sequence[str] | None = None, **kwargs: Any) AgentExecutor [source]#
Deprecated since version 0.1.0: LangChain agents will continue to be supported, but it is recommended for new use cases to be built with LangGraph. LangGraph offers a more flexible and full-featured framework for building agents, including support for tool-calling, persistence of state, and human-in-the-loop workflows. For details, refer to the LangGraph documentation as well as guides for Migrating from AgentExecutor and LangGraphβs Pre-built ReAct agent. It will not be removed until langchain==1.0.
Load an agent executor given tools and LLM.
- Parameters:
tools (Sequence[BaseTool]) β List of tools this agent has access to.
llm (BaseLanguageModel) β Language model to use as the agent.
agent (AgentType | None) β Agent type to use. If None and agent_path is also None, will default to AgentType.ZERO_SHOT_REACT_DESCRIPTION. Defaults to None.
callback_manager (BaseCallbackManager | None) β CallbackManager to use. Global callback manager is used if not provided. Defaults to None.
agent_path (str | None) β Path to serialized agent to use. If None and agent is also None, will default to AgentType.ZERO_SHOT_REACT_DESCRIPTION. Defaults to None.
agent_kwargs (dict | None) β Additional keyword arguments to pass to the underlying agent. Defaults to None.
tags (Sequence[str] | None) β Tags to apply to the traced runs. Defaults to None.
kwargs (Any) β Additional keyword arguments passed to the agent executor.
- Returns:
An agent executor.
- Raises:
ValueError β If both agent and agent_path are specified.
ValueError β If agent is not a valid agent type.
ValueError β If both agent and agent_path are None.
- Return type:
Examples using initialize_agent