Skip to content

[FEATURE]: Preserve agent identity across context compaction #21045

@ESRE-dev

Description

@ESRE-dev

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Specialized agents (judges, reviewers, planners, explorers) lose their identity after context compaction. The compaction summarizer has no knowledge of which agent is being compacted, so the summary omits role-specific context. Post-compaction, agents revert to generic implementor behavior — e.g. a reviewer starts suggesting code changes instead of reviewing.

Problem:

  • The compaction LLM receives no system prompt from the source agent, so it can't preserve role context
  • The summary template has no section for agent role/constraints
  • After compaction, non-native agents receive a generic "continue" message with no identity reinforcement

Proposed changes:

  1. Pass the source agent's system prompt (capped at 4K) to the compaction LLM as a system message
  2. Add an "Agent Role & Constraints" section to the compaction summary template
  3. Inject a post-compaction <system-reminder> for non-native agents to prevent role drift
  4. Expose the agent name on the experimental.session.compacting plugin hook

This is related to #16960 (compaction loses instruction context) and #17900 (agent stops working after compaction), but addresses the runtime agent identity specifically rather than AGENTS.md file preservation.

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions