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:

AgentExecutor

Examples using initialize_agent