-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Description
Problem Statement
When building multi-phase agent workflows, there's currently no way to resume a specific subagent with its previous context. Each Task/subagent invocation starts fresh.
Use Case
Complex workflows like specification-driven development have multiple phases:
- Specify - Architect agent creates specs
- Clarify - Same architect resolves ambiguities
- Implement - Engineer agent writes code
- Validate - Same engineer runs tests
Currently, the engineer in step 4 has no memory of what they implemented in step 3. The context is lost between invocations.
Proposed Solution
Add an optional resumeSessionId parameter to subagent invocation:
// First call - returns session ID
const result = await invokeSubagent({
agent: "engineer",
task: "Implement the auth system based on these specs..."
});
// result.sessionId: "xyz789"
// Later - resume with full context
const continued = await invokeSubagent({
agent: "engineer",
task: "Now add tests for the auth system you just built",
resumeSessionId: "xyz789" // Load previous session context
});Technical Considerations
What would need to change:
- Subagent API - Add optional
resumeSessionIdparameter - Session metadata - Store/expose child session IDs to parent
- Context loading - When resuming, prepend previous child session events to new session
- Session lifecycle - Make child sessions persistent and queryable by parent
Current architecture (from my understanding):
# Parent session
~/.opencode/sessions/abc123.jsonl
# Child session (ephemeral)
~/.opencode/sessions/xyz789.jsonl # Currently no way to reference laterAlternatives Considered
- Manual context injection - Parent could summarize and inject previous work, but loses nuance and adds token overhead
- Session-level resume -
/sessionsworks for whole conversations but not individual subagents - Longer initial prompts - Include everything upfront, but context windows have limits
Additional Context
This came up while migrating PAI (Personal AI Infrastructure) to run on OpenCode. PAI's Task tool has a resume parameter that enables stateful agent workflows.
Related: Issue #6558 (model selection for subagents) - similar pattern of adding optional Task parameters.
Happy to help with implementation if this is something the team is interested in!