Subagent Orchestration
Asta supports subagent orchestration for running background tasks in isolated sessions. Subagents are useful for:- Long-running research (“Learn about X for 10 minutes”)
- Parallel tasks (“Research competitors while I draft the pitch”)
- Delegated work (“Analyze this report and summarize key risks”)
- Multi-step workflows (“Create a Notion database and populate it”)
~/workspace/source/backend/app/subagent_orchestrator.py
How It Works
- User requests a background task (explicitly or via internal delegation)
- Main agent spawns a subagent in an isolated conversation
- Subagent runs independently (doesn’t block the main chat)
- Result auto-delivers when complete (or times out)
- Main agent continues with the result
Subagents share the same AI provider and model as the main session unless overridden.
Command: /subagents
Use /subagents to view and manage active subagent runs:
Viewing Subagent Output
Spawning Subagents
Automatic (Preferred)
Asta automatically spawns subagents for tasks that benefit from isolation:Explicit (Advanced)
Use thesessions_spawn tool directly:
task(required): The instruction for the subagentlabel(optional): Human-readable labelrunTimeoutSeconds(optional): Max execution time (default: 30 minutes)cleanup(optional):keepordelete(default:keep)model(optional): Override the AI model for this subagentthinking(optional): Override thinking level (off,low,medium,high,xhigh)
Subagent Operations
Source:~/workspace/source/backend/app/subagent_orchestrator.py:52-157
sessions_spawn
Spawn a new background subagent run.
Returns immediately with a runId and sessionId. The subagent runs asynchronously.
Response:
sessions_list
List recent subagent runs for the current session.
Response:
sessions_history
Read the full conversation history for a subagent.
Request:
sessions_send
Send a follow-up message to a running subagent.
Request:
timeoutSeconds > 0, waits for a reply (default: 30 seconds). Otherwise returns immediately.
sessions_stop
Stop a running subagent.
Request:
Configuration
Set these in.env or Settings:
Concurrency Limits
Source:~/workspace/source/backend/app/subagent_orchestrator.py:491-521
Asta enforces these limits:
- Max concurrent: Only N subagents can run at once (default: 3)
- Max depth: Subagents cannot spawn their own subagents by default (depth=1)
- Max children: Each session can have at most N active child subagents (default: 5)
sessions_spawn returns:
Lifecycle & Auto-Announce
Source:~/workspace/source/backend/app/subagent_orchestrator.py:351-437
States
| State | Description |
|---|---|
running | Subagent is actively processing |
completed | Finished successfully |
timeout | Exceeded runTimeoutSeconds |
stopped | Stopped by user or system |
error | Crashed or failed |
interrupted | Recovered after restart (stale state) |
Auto-Announce
When a subagent finishes (any terminal state), Asta automatically:- Adds an assistant message to the parent session with the result
- Sends a notification (if running in Telegram)
- Archives the session after N minutes (default: 60)
You don’t need to poll or wait for results. The result will appear as a new message when ready.
Use Cases
Background Research
User:- Spawns a subagent:
sessions_spawn({task: "Learn about GraphQL...", runTimeoutSeconds: 300}) - Returns immediately: “I’ve started background research. I’ll let you know when it’s done.”
- User continues working
- 5 minutes later, result auto-delivers: “Here’s what I learned about GraphQL…”
Parallel Tasks
User:- Spawns 3 subagents (one per competitor)
- Each researches independently
- Results merge when all complete
- Drafts table with findings
Multi-Step Workflows
User:- Spawns a subagent for the full workflow
- Subagent executes each step sequentially
- Returns final state (database URL, task IDs)
- Main chat continues without blocking
Debugging Subagents
Source:~/workspace/source/backend/app/subagent_orchestrator.py:631-655
Viewing Logs
Subagent activity is logged tobackend/asta.log:
Spawning subagent: sub_xxx— Subagent startedSubagent sub_xxx completed— Finished successfullySubagent sub_xxx timeout— Exceeded time limitMarked N stale running subagents interrupted— Recovered after restart
Checking Status
Use the desktop app or web panel:- Go to Chat → Subagents (sidebar)
- View active and recent subagent runs
- Click a run to see its full history
Stale Runs After Restart
Source:~/workspace/source/backend/app/subagent_orchestrator.py:631-654
If Asta restarts while subagents are running, they’re marked as interrupted on startup. The main session receives:
Troubleshooting
Subagent never finishes
Subagent never finishes
Check the timeout:
- Default: 30 minutes
- Set explicit timeout:
runTimeoutSeconds: 600(10 minutes)
'Max concurrent subagents reached'
'Max concurrent subagents reached'
Wait for a running subagent to complete, or stop one:Or increase the limit in
.env:Result not announced
Result not announced
Check:
- Subagent status:
/subagents - Backend logs:
tail -f asta.log | grep -i subagent - Parent conversation ID matches current session
running state, manually stop it:Cannot spawn nested subagents
Cannot spawn nested subagents
By default, This lets subagents spawn their own subagents (depth 2).
ASTA_SUBAGENTS_MAX_DEPTH=1 (no nesting).To allow nested subagents:Advanced: Custom Subagent Models
Override the model for specific subagents:- Cost optimization (use cheaper models for simple tasks)
- Quality boost (use premium models for complex analysis)
- Provider testing (compare results across models)
Next Steps
- Exec Tool Security - Run commands in subagents
- Creating Skills - Build multi-step workflows
- Telegram Bot Setup - Use subagents from mobile