SubAgentMiddleware(
self,
*,
backend: BackendProtocol | BackendFactory | None = None,
subagents| Name | Type | Description |
|---|---|---|
backend | BackendProtocol | BackendFactory | None | Default: NoneBackend for file operations and execution. Required for the new API. |
subagents | list[SubAgent | CompiledSubAgent] | None | Default: None |
system_prompt | str | None | Default: TASK_SYSTEM_PROMPT |
task_description | str | None | Default: None |
| Name | Type |
|---|---|
| backend | BackendProtocol | BackendFactory | None |
| subagents | list[SubAgent | CompiledSubAgent] | None |
| system_prompt | str | None |
| task_description | str | None |
Middleware for providing subagents to an agent via a task tool.
This middleware adds a task tool to the agent that can be used to invoke subagents.
Subagents are useful for handling complex tasks that require multiple steps, or tasks
that require a lot of context to resolve.
A chief benefit of subagents is that they can handle multi-step tasks, and then return a clean, concise response to the main agent.
Subagents are also great for different domains of expertise that require a narrower subset of tools and focus.
Example:
from deepagents.middleware import SubAgentMiddleware
from langchain.agents import create_agent
agent = create_agent(
"openai:gpt-4o",
middleware=[
SubAgentMiddleware(
backend=my_backend,
subagents=[
{
"name": "researcher",
"description": "Research agent",
"system_prompt": "You are a researcher.",
"model": "openai:gpt-4o",
"tools": [search_tool],
}
],
)
],
)
.. deprecated::
The following arguments are deprecated and will be removed in version 0.5.0:
default_model, default_tools, default_middleware,
default_interrupt_on, general_purpose_agent. Use backend and subagents instead.
List of fully-specified subagent configs. Each SubAgent
must specify model and tools. Optional interrupt_on on
individual subagents is respected.
Instructions appended to main agent's system prompt about how to use the task tool.
Custom description for the task tool.