Skip to content

[FEATURE]: Agent-level resume for subagents (resumeSessionId parameter) #6584

@Steffen025

Description

@Steffen025

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:

  1. Specify - Architect agent creates specs
  2. Clarify - Same architect resolves ambiguities
  3. Implement - Engineer agent writes code
  4. 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:

  1. Subagent API - Add optional resumeSessionId parameter
  2. Session metadata - Store/expose child session IDs to parent
  3. Context loading - When resuming, prepend previous child session events to new session
  4. 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 later

Alternatives Considered

  1. Manual context injection - Parent could summarize and inject previous work, but loses nuance and adds token overhead
  2. Session-level resume - /sessions works for whole conversations but not individual subagents
  3. 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!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions