# AsyncSubAgentMiddleware

> **Class** in `deepagents`

📖 [View in docs](https://reference.langchain.com/python/deepagents/middleware/async_subagents/AsyncSubAgentMiddleware)

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.

## Signature

```python
AsyncSubAgentMiddleware(
    self,
    *,
    async_subagents: list[AsyncSubAgent],
    system_prompt: str | None = ASYNC_TASK_SYSTEM_PROMPT,
)
```

## Description

**Example:**

```python
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",
        }
    ],
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `async_subagents` | `list[AsyncSubAgent]` | Yes | 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. |
| `system_prompt` | `str \| None` | No | Instructions appended to the main agent's system prompt about how to use the async subagent tools. (default: `ASYNC_TASK_SYSTEM_PROMPT`) |

## Extends

- `AgentMiddleware[Any, ContextT, ResponseT]`

## Constructors

```python
__init__(
    self,
    *,
    async_subagents: list[AsyncSubAgent],
    system_prompt: str | None = ASYNC_TASK_SYSTEM_PROMPT,
) -> None
```

| Name | Type |
|------|------|
| `async_subagents` | `list[AsyncSubAgent]` |
| `system_prompt` | `str \| None` |


## Properties

- `state_schema`
- `tools`
- `system_prompt`

## Methods

- [`wrap_model_call()`](https://reference.langchain.com/python/deepagents/middleware/async_subagents/AsyncSubAgentMiddleware/wrap_model_call)
- [`awrap_model_call()`](https://reference.langchain.com/python/deepagents/middleware/async_subagents/AsyncSubAgentMiddleware/awrap_model_call)

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/64ecf141be0479f859f4efe25d139166b45ee18c/libs/deepagents/deepagents/middleware/async_subagents.py#L862)