create_agent
create_agent, visit the Agents docs.
The language model for the agent.Can be a string identifier (e.g.,
"openai:gpt-4") or a direct chat model instance (e.g., ChatOpenAI or other LangChain chat model).For a full list of supported model strings, see init_chat_model.A list of tools,
dict, or Callable.If None or an empty list, the agent will consist of a model node without a tool calling loop.See the Tools docs for more information.An optional system prompt for the LLM.Can be a
str (which will be converted to a SystemMessage) or a SystemMessage instance directly. The system message is added to the beginning of the message list when calling the model.A sequence of middleware instances to apply to the agent.Middleware can intercept and modify agent behavior at various stages.See the Middleware docs for more information.
An optional configuration for structured responses.Can be a
ToolStrategy, ProviderStrategy, or a Pydantic model class.If provided, the agent will handle structured output during the conversation flow.Raw schemas will be wrapped in an appropriate strategy based on model capabilities.See the Structured output docs for more information.An optional
TypedDict schema that extends AgentState.When provided, this schema is used instead of AgentState as the base schema for merging with middleware state schemas. This allows users to add custom state fields without needing to create custom middleware.Generally, itβs recommended to use state_schema extensions via middleware to keep relevant extensions scoped to corresponding hooks / tools.An optional schema for runtime context.
An optional checkpoint saver object.Used for persisting the state of the graph (e.g., as chat memory) for a single thread (e.g., a single conversation).
An optional store object.Used for persisting data across multiple threads (e.g., multiple conversations / users).
An optional list of node names to interrupt before.Useful if you want to add a user confirmation or other interrupt before taking an action.
An optional list of node names to interrupt after.Useful if you want to return directly or run additional processing on an output.
Whether to enable verbose logging for graph execution.When enabled, prints detailed information about each node execution, state updates, and transitions during agent runtime. Useful for debugging middleware behavior and understanding agent execution flow.
An optional name for the
CompiledStateGraph.This name will be automatically used when adding the agent graph to another graph as a subgraph node - particularly useful for building multi-agent systems.An optional
BaseCache instance to enable caching of graph execution.A compiled
StateGraph that can be used for chat interactions.Example
AgentState
create_agent.
The list of messages in the conversation.Uses the
add_messages reducer to automatically merge new messages into the existing list.The structured response from the agent, if a
response_format was specified.This field is populated when the agent produces structured output based on the configured response format.