Summary
OpenCode's task tool supports session resumption via task_id, allowing the orchestrator to call the same subagent session again with full context preservation. Currently, oh-my-opencode-slim spawns fresh subagent sessions for each delegation, losing valuable context and conversation history.
The Opportunity
When a subagent finishes and reports back, the orchestrator currently treats subsequent related work as a brand-new task. Instead, we should leverage task_id to resume the same session when:
- The follow-up work is directly related to the previous task
- Context from the previous session would improve quality/speed
- The same specialist agent is being called again
How It Works in OpenCode
From the task tool implementation:
const taskID = params.task_id
const session = taskID
? yield* sessions.get(SessionID.make(taskID)).pipe(Effect.catchCause(() => Effect.succeed(undefined)))
: undefined
const nextSession = session ?? (yield* sessions.create({...}))
When task_id is provided, the tool looks up the existing session. If found, it continues that session with all prior context (files read, conversation history, todos) intact.
Benefits
- Token efficiency - Avoid re-sending full context summaries
- Better continuity - Subagent remembers what it already explored/did
- Faster iterations - No warm-up period for the agent
- Deeper work - Enables multi-step collaboration with the same specialist
Implementation Considerations
Where to Store task_id
The orchestrator needs to track active subagent sessions. Options:
- Memory/state: Track in orchestrator's working memory (simplest)
- Structured output: Have subagents return
task_id in a structured format
- Session registry: Maintain a lightweight map of agent_type → active_session_id
Decision Logic
When should the orchestrator resume vs. spawn fresh?
| Scenario |
Action |
| Follow-up to same task |
Resume with task_id |
| New unrelated task |
Fresh session |
| Same agent, different task |
Fresh session (or user-configurable) |
| Explicit user request to continue |
Resume |
Prompt Updates Needed
- Orchestrator prompt: Add guidance on when/how to use
task_id for resumption
- Agent prompts: Ensure agents return
task_id clearly when they expect follow-up
- Documentation: Explain the feature to users
Proposed Design
// In orchestrator delegation logic
const delegate = async (task, context) => {
const existingSession = findRecentSessionForAgent(task.agentType, context)
if (existingSession && shouldResume(task, existingSession)) {
return await taskTool({
...task,
task_id: existingSession.task_id // Resume!
})
}
// Fresh session
const result = await taskTool(task)
storeSessionForAgent(task.agentType, result.task_id, context)
return result
}
Open Questions
- Session expiry: How long should we consider a session "resumable"? (Last 5 min? Same user turn?)
- Context window: Very long sessions might hit token limits - should we summarize before resuming?
- Multi-agent: If user manually @mentions an agent, should that connect to orchestrator-tracked sessions?
- Visibility: Should users see session resumption in the UI, or is it transparent?
Related
- OpenCode PR #7756: "Add subagent-to-subagent delegation with budgets, persistent sessions"
- Current behavior: Each
task call creates sessions.create({parentID: ctx.sessionID, ...})
Acceptance Criteria
Priority: Medium-High - This is a significant efficiency win for multi-step agent workflows.
Effort: Medium - Requires orchestrator prompt changes + state tracking logic.
Summary
OpenCode's
tasktool supports session resumption viatask_id, allowing the orchestrator to call the same subagent session again with full context preservation. Currently, oh-my-opencode-slim spawns fresh subagent sessions for each delegation, losing valuable context and conversation history.The Opportunity
When a subagent finishes and reports back, the orchestrator currently treats subsequent related work as a brand-new task. Instead, we should leverage
task_idto resume the same session when:How It Works in OpenCode
From the
tasktool implementation:When
task_idis provided, the tool looks up the existing session. If found, it continues that session with all prior context (files read, conversation history, todos) intact.Benefits
Implementation Considerations
Where to Store task_id
The orchestrator needs to track active subagent sessions. Options:
task_idin a structured formatDecision Logic
When should the orchestrator resume vs. spawn fresh?
task_idPrompt Updates Needed
task_idfor resumptiontask_idclearly when they expect follow-upProposed Design
Open Questions
Related
taskcall createssessions.create({parentID: ctx.sessionID, ...})Acceptance Criteria
task_idPriority: Medium-High - This is a significant efficiency win for multi-step agent workflows.
Effort: Medium - Requires orchestrator prompt changes + state tracking logic.