- langgraph_agent_toolkit.agents.agent_executor.interrupt_value_to_content(value)[source][source]
Render an interrupt payload as valid
AIMessagecontent (a string).Custom
interrupt()blueprints pass a string (used as-is).HumanInTheLoopMiddlewarepasses a request dict ({"action_requests": [...]}); its per-actiondescriptionalready holds a readable approval prompt, so join those and append a hint on how to reply. This keeps the dict out ofAIMessage(content=...), which only accepts a string or content-block list.
- langgraph_agent_toolkit.agents.agent_executor.build_resume_command(interrupted_tasks, user_input)[source][source]
Build the
Command(resume=...)for an interrupted run.HumanInTheLoopMiddlewareexpects{"decisions": [...]}; other interrupts (custominterrupt()blueprints) read the raw input dict (e.g.resume_value["message"]). When the pending interrupt is a HITL tool-approval request, translate the user’s reply into one decision per pending tool call:approve/yes-> approve,reject[: reason]/no-> reject, any other text -> respond (sent to the model). Otherwise resume with the raw input unchanged.
- class langgraph_agent_toolkit.agents.agent_executor.AgentExecutor(*args)[source][source]
Bases:
objectHandles the loading, execution and saving logic for different LangGraph agents.
Initialize the AgentExecutor by importing agents.
- Parameters:
*args – Variable length strings specifying the agents to import, e.g., “langgraph_agent_toolkit.agents.blueprints.react.agent:react_agent”.
- Raises:
ValueError – If no agents are provided.
- __init__(*args)[source][source]
Initialize the AgentExecutor by importing agents.
- Parameters:
*args – Variable length strings specifying the agents to import, e.g., “langgraph_agent_toolkit.agents.blueprints.react.agent:react_agent”.
- Raises:
ValueError – If no agents are provided.
- load_agents_from_imports(args)[source][source]
Dynamically imports agents based on the provided import strings.
- Parameters:
args (tuple)
- Return type:
None
- static handle_agent_errors(func)[source][source]
Handle errors occurring during agent execution.
Specifically handles GraphRecursionError and other exceptions.
- async invoke(agent_id, input, thread_id=None, user_id=None, model_name=None, model_provider=None, model_config_key=None, agent_config=None, recursion_limit=None)[source][source]
Invoke an agent with a message and return the response.
- Parameters:
agent_id (str) – ID of the agent to invoke
thread_id (str | None) – Optional thread ID for conversation history
user_id (str | None) – Optional user ID for the agent
model_name (str | None) – Optional model name to override the default
model_provider (str | None) – Optional model provider to override the default
model_config_key (str | None) – Optional model config key to override the default
agent_config (Dict[str, Any] | None) – Optional additional configuration for the agent
recursion_limit (int | None) – Optional recursion limit for the agent
- Returns:
The agent’s response
- Return type:
- stream(agent_id, input, thread_id=None, user_id=None, model_name=None, model_provider=None, model_config_key=None, stream_tokens=True, agent_config=None, recursion_limit=None)[source][source]
Stream an agent’s response to a message, yielding either tokens or messages.
- Parameters:
agent_id (str) – ID of the agent to invoke
thread_id (str | None) – Optional thread ID for conversation history
user_id (str | None) – Optional user ID for the agent
model_name (str | None) – Optional model name to override the default
model_provider (str | None) – Optional model provider to override the default
model_config_key (str | None) – Optional model config key to override the default
stream_tokens (bool) – Whether to stream individual tokens
agent_config (Dict[str, Any] | None) – Optional additional configuration for the agent
recursion_limit (int | None) – Optional recursion limit for the agent
- Yields:
Either ChatMessage objects for full messages or strings for token chunks
- Return type:
AsyncGenerator[str | ChatMessage, None]