Skip to main content

Overview

Subagent is Zeus’s task delegation mechanism, allowing the main Agent to dispatch subtasks to specialized sub-agents for execution. Through SubagentMiddleware, the main Agent can process multiple independent subtasks in parallel without interrupting its own reasoning. Core values of Subagent:
  • Task Decomposition: Break complex tasks into independent subtasks for separate execution
  • Focused Isolation: Each sub-agent has its own independent context, preventing interference
  • Parallel Execution: Multiple subtasks can be processed concurrently for improved efficiency
  • Result Aggregation: After sub-agents complete, results are returned to the main Agent for continued reasoning

Architecture

Relationship with Main Agent

DimensionMain AgentSubagent
ContextFull System Prompt + conversation historyMinimal context + task description
ToolsAll available toolsInherits main Agent’s tool set
LifecycleSession-levelSingle task
CheckpointYes (via LangGraph)No independent Checkpoint
MemoryRead/write accessInherits main Agent’s configuration

Tool Interface

The Agent invokes Subagent through the task tool:
Tool NameFunctionParameters
taskDelegate a subtask to a sub-agentagent: sub-agent name, task: task description

Usage Example

When the main Agent receives a complex request (e.g., “Analyze this data and generate a visualization report”), it can:
  1. Create a subtask: “Analyze sales.csv data and compute key metrics”
  2. Create another subtask: “Generate charts based on the analysis results”
  3. Collect results from both sub-agents and synthesize the final report

SubagentMiddleware

Subagent capability is provided by the DeepAgents framework’s SubagentMiddleware. This middleware is automatically registered during Agent creation, injecting the sub-agent list into the main Agent’s tool set.

Configuration

In BaseService._create_agent(), the sub-agent list is passed via the subagents parameter:
agent = create_deep_agent(
    model=self.llm,
    tools=tools,
    system_prompt=system_prompt,
    subagents=subagents,  # Sub-agent list
    middleware=middleware,
    ...
)

Execution Flow


Frontend Integration

When processing the SSE stream, the frontend distinguishes between main Agent and Subagent messages:
  • Subagent’s write_todos calls are skipped and not displayed in the main Agent’s task list
  • Subagent’s tool calls and results are shown in a nested format in the Trajectory panel
  • The isInsideSubagent() state flag is used to identify the message source

Design Principles

PrincipleDescription
Minimal ContextSub-agents receive only the necessary task description, not the full conversation history
Independent ExecutionSub-agent execution does not block the main Agent’s other operations
Result Pass-throughSub-agent execution results are returned to the main Agent as Tool Results
Error IsolationSub-agent failure does not cause the main Agent to crash

Use Cases

ScenarioDescription
Data AnalysisSplit data cleaning, statistical analysis, and visualization into independent subtasks
Code GenerationGenerate frontend components, backend APIs, and database migrations separately
Document WritingDelegate different sections to different sub-agents for parallel writing
Information ResearchSearch multiple sources simultaneously and aggregate results