Skip to main content

Usage

Deep Agent can spawn specialized subagents to handle complex, multi-step independent tasks with isolated context. The task tool is automatically created and injected into the agent’s toolset. It allows spawning:
  • general-purpose agents - Full-featured agents with all tools for research and complex tasks
  • Custom named agents - Specialized agents you define and pass to DeepAgent

Params

task(description: str, subagent_type: str) -> str
ParameterTypeDescription
descriptionstrDetailed task description for the subagent to complete autonomously
subagent_typestrType of subagent: "general-purpose" or custom agent name
Return Value: The final result from the subagent’s execution.

Available Subagent Types

  1. general-purpose: Automatically available, created with same model as parent agent
  2. Custom agents: Agents you provide in the subagents parameter

When to Use Subagents

  • Complex independent tasks that can be fully delegated
  • Parallel processing of multiple related tasks
  • Specialized expertise requiring focused knowledge
  • Context isolation for heavy token usage
  • Quality assurance with review and validation

Creating Custom Subagents

from upsonic import DeepAgent, Agent, Task

# Create specialized agents with names
researcher = Agent(
    "openai/gpt-4o",
    name="researcher",
    system_prompt="You are a research expert focused on gathering information"
)

code_reviewer = Agent(
    "openai/gpt-4o",
    name="code-reviewer",
    system_prompt="You are a code review expert focused on quality and best practices"
)

# Create Deep Agent with subagents
agent = DeepAgent(
    "openai/gpt-4o",
    subagents=[researcher, code_reviewer]
)

task = Task("Research AI trends and create a technical report with code examples")
result = agent.do(task)
# Agent can delegate research to researcher and code review to code-reviewer

Adding Subagents Dynamically

agent = DeepAgent("openai/gpt-4o")

# Add subagent after creation
analyst = Agent("openai/gpt-4o", name="analyst", system_prompt="Data analysis expert")
agent.add_subagent(analyst)

Important Notes

  • Subagents execute autonomously and return a single result
  • Subagents have isolated context (no memory sharing)
  • Subagent results are not visible to the user directly
  • Each subagent must have a name attribute set