Middleware for async subagents running on remote LangGraph servers.
This middleware adds tools for launching, monitoring, and updating
background jobs on remote LangGraph deployments. Unlike the synchronous
SubAgentMiddleware, async subagents return immediately with a job ID,
allowing the main agent to continue working while subagents execute.
Job IDs are persisted in the agent state under async_subagent_jobs so they
survive context compaction/offloading and can be accessed programmatically.
AsyncSubAgentMiddleware(
self,
*,
async_subagents: list[AsyncSubAgent],
system_prompt: str | None = ASYNC_TASK_SYSTEM_PROMPT
)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",
}
],
)| Name | Type | Description |
|---|---|---|
async_subagents* | list[AsyncSubAgent] | List of async subagent specifications. Each must include |
system_prompt | str | None | Default: ASYNC_TASK_SYSTEM_PROMPTInstructions appended to the main agent's system prompt about how to use the async subagent tools. |
| Name | Type |
|---|---|
| async_subagents | list[AsyncSubAgent] |
| system_prompt | str | None |