-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Description
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
When a user switches between primary agents during a session, the conversation history sent to the model should include metadata indicating which agent handled each prior message. Currently, agents receive a flat transcript with no agent attribution — they cannot determine which agent produced which response.
Motivation: Retrospective agent for double-loop learning
I maintain a Retrospective agent that reviews completed sessions and suggests improvements to AGENTS.md and agent definition files. This is a form of double-loop learning — not just completing tasks, but improving the system that shapes how tasks are completed.
The Retrospective agent works by reading the conversation context to understand what happened during the session. It looks for:
- Repeated corrections — Did the user have to correct an agent multiple times? That's a signal to improve that agent's instructions.
- Wrong agent for the job — Was an agent used for a task outside its intended scope?
- Permission friction — Were there permission prompts that were always approved or denied?
- Convention violations — Did an agent violate project conventions?
Without per-message agent attribution, the Retrospective agent can only infer which agent handled each turn from context clues (tone, tool usage, the user explicitly saying "I used the wrong agent"). This is unreliable and limits the quality of feedback.
Concrete example
In a recent session, the user started with the Project Manager agent to evaluate an architecture decision (App Runner vs Lambda for web hosting). Partway through, they realized the PM agent wasn't the right fit and switched to a general agent. At the end, they switched to the Retrospective agent for review.
The Retrospective agent could see the content of the full session but had no way to know which messages came from the PM agent vs the general agent. The user happened to say "I pointed the wrong agent at that initially" — without that remark, the Retrospective agent would have had no signal to suggest improving agent routing for architecture decisions.
If agent identity were included in the message history, the Retrospective agent could have directly observed: "Messages 1-3 were handled by project-manager, messages 4-12 by default, messages 13+ by retrospective" — and given precise feedback like "The project-manager agent was used for an architecture evaluation task outside its scope; consider documenting when to use which agent."
Proposed approach
Include the agent name (matching the filename in .opencode/agents/) as metadata on each assistant message in the conversation context. For example:
[agent: project-manager]
<assistant message content>
[agent: default]
<assistant message content>
The exact format is up to the OpenCode team — it could be a prefix, a structured field, or a system message injected at switch points. The key requirement is that downstream agents can determine which agent produced each prior response.
Relationship to existing issues
- [Bug] Primary agents lack identity awareness when user switches agents - cannot determine which agent is active #7492 addresses agents not knowing their own identity. This request is complementary — it's about agents knowing which other agents handled prior messages.
- [FEATURE]:Agent Switch During a Session in Desktop shall be "Printed" #11801 requests agent switches be visible in the UI. This request extends that concept to the model-facing conversation context.
OpenCode version
1.1.8