Agent factory for creating agents with middleware support.
Initialize a chat model from any supported provider using a unified interface.
Two main use cases:
config. Makes it easy to switch between models/providers without
changing your codeRequires the integration package for the chosen model provider to be installed.
See the model_provider parameter below for specific package names
(e.g., pip install langchain-openai).
Refer to the provider integration's API reference
for supported model parameters to use as **kwargs.
Creates an agent graph that calls tools in a loop until a stopping condition is met.
For more details on using create_agent,
visit the Agents docs.
Base middleware class for an agent.
Subclass this and implement any of the defined methods to customize agent behavior between steps in the main agent loop.
State schema for the agent.
Model response with an optional 'Command' from 'wrap_model_call' middleware.
Use this to return a 'Command' alongside the model response from a 'wrap_model_call' handler. The command is applied as an additional state update after the model node completes, using the graph's reducers (e.g. 'add_messages' for the 'messages' key).
Because each 'Command' is applied through the reducer, messages in the command are added alongside the model response messages rather than replacing them. For non-reducer state fields, later commands overwrite earlier ones (outermost middleware wins over inner).
Model request information for the agent.
Response from model execution including messages and optional structured output.
The result will usually contain a single AIMessage, but may include an additional
ToolMessage if the model used a tool for structured output.
Annotation used to mark state attributes as omitted from input or output schemas.
Automatically select the best strategy for structured output.
Raised when model returns multiple structured output tool calls when only one is expected.
Information for tracking structured output tool metadata.
This contains all necessary information to handle structured responses generated via tool calls, including the original schema, its type classification, and the corresponding tool implementation used by the tools strategy.
Use the model provider's native structured output method.
Information for tracking native structured output metadata.
This contains all necessary information to handle structured responses generated via native provider output, including the original schema, its type classification, and parsing logic for provider-enforced JSON.
Base class for structured output errors.
Raised when structured output tool call arguments fail to parse according to the schema.
Use a tool calling strategy for model responses.