AsyncSubAgentMiddleware(
self,
*,
async_subagents: list[AsyncSubAgent],
system_prompt: str | None | Name | Type | Description |
|---|---|---|
async_subagents* | list[AsyncSubAgent] | |
system_prompt | str | None | Default: ASYNC_TASK_SYSTEM_PROMPT |
| Name | Type |
|---|---|
| async_subagents | list[AsyncSubAgent] |
| system_prompt | str | None |
Middleware for async subagents running on remote Agent Protocol servers.
This middleware adds tools for launching, monitoring, and updating
background tasks on remote Agent Protocol servers. Unlike the synchronous
SubAgentMiddleware, async subagents return immediately with a task ID,
allowing the main agent to continue working while subagents execute.
Works with any Agent Protocol-compliant server ā LangGraph Platform (managed) or self-hosted (e.g. a FastAPI server implementing the Agent Protocol spec).
Task IDs are persisted in the agent state under async_tasks so they
survive context compaction/offloading and can be accessed programmatically.
Example:
from deepagents.middleware.async_subagents import AsyncSubAgentMiddleware
middleware = AsyncSubAgentMiddleware(
async_subagents=[
{
"name": "researcher",
"description": "Research agent for deep analysis",
"url": "https://my-deployment.langsmith.dev",
"graph_id": "research_agent",
}
],
)List of async subagent specifications.
Each must include name, description, and graph_id. url is
optional ā omit it to use ASGI transport for local servers.
Instructions appended to the main agent's system prompt about how to use the async subagent tools.
Update the system message to include async subagent instructions.
(async) Update the system message to include async subagent instructions.