Agent factory for creating agents with middleware support.
Destination to jump to when a middleware node returns.
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.
Promote nested named agents into typed handles on run.subagents.
The base _TasksLifecycleBase records each namespace's lc_agent_name
(set by create_agent(name=...)) and, on every task start, fires
_on_started with the resolved graph_name and a cause for genuine
subagent boundaries. This transformer gates on that boundary using the
inherited _lc_by_ns map: a nested run is a subagent when it carries an
lc_agent_name. Same-named nested agents (e.g. a subagent that invokes
itself) are surfaced; unnamed agents (None) are excluded. Trade-off: a
non-agent subgraph that inherited the parent's name will also surface.
On the first matching task start it builds a child mux and emits a typed
handle on run.subagents, then forwards subsequent child-scope events into
that handle so the nested run can be consumed independently.
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).
Input state schema for the agent.
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.
Output state schema for the agent.
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.
Union type for all supported response format strategies.