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. See LangGraph documentation for more details: https://langchain-ai.github.io/langgraph/. Refer here for its pre-built ReAct agent: https://langchain-ai.github.io/langgraph/how-tos/create-react-agent/ It will be removed in None==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