Compaction strips system prompt's <agent_instructions> block from custom agent profiles selected via /agent
Describe the bug
When a custom agent is selected via /agent (or --agent=), the agent profile's instructions are loaded into the session system prompt context as <agent_instructions> block.
After /compact runs (either manually or via automatic compaction at ~80-95% context), the <agent_instructions> block is stripped from the context and not restored.
This effectively discards the custom agent's persona, behavioral rules, guidelines, and all other instructions -- making the /agent selection meaningless after compaction.
Affected version
1.0.34
Steps to reproduce the behavior
Steps to reproduce
- Create a custom agent profile at
~/.copilot/agents/my-agent.agent.mdwith disable-model-invocation: true and substantial instructions - Launch copilot and select the agent via
/agent - Verify the agent instructions are active (e.g., the model follows behaviour defined in the custom agent file)
- Have a conversation long enough to trigger automatic compaction, or run /compact manually
- Observe that the model no longer follows the custom agent instructions
- Ask the model to check its system prompt — the
<agent_instructions>block is absent
Expected behavior
Expected behavior
The system prompt's <agent_instructions> block from the selected custom agent profile should survive compaction. It is session configuration, not conversational history — it should be treated equivalently to .github/copilot-instructions.md or instruction files, which persist across compaction.
Actual behavior
The <agent_instructions> block is discarded during compaction. The model reverts to default behavior without the custom agent's rules.
Additional context
No response
I can confirm the issue: I see the same behavior.
maybe relevant to #3006