Repository navigation
Open
Open
Copy link
Labels
area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agentsarea:sessionsSession management, resume, history, session picker, and session state
Description
Summary
When a user invokes /agent <name> to switch to a custom agent at the session root, no dedicated event is emitted. The only signal that an agent switch occurred is the <agent_instructions> block silently prepended to user.message.data.transformedContent. This makes it difficult for downstream tooling to reliably track which custom agent is active.
Current behavior
/agent review-pr-commentsrewrites the next user message by prepending<agent_instructions>...</agent_instructions>intotransformedContent- There is no
session.agent_changedorsession.agent_invokedevent inevents.jsonl subagent.selectedexists but fires rarely (21 events across 920+ sessions in one user's history) and doesn't appear to be the canonical marker for root-level/agentswitchessession.mode_changedandsession.model_changeexist for other session-level state changes, but agents have no equivalent
Impact
- Session analytics: Tools like copilot-session-tools that enrich
events.jsonlinto queryable databases cannot reliably count or filter by which custom agent was used. The only workaround is parsing<agent_instructions>blocks out oftransformedContent, which is fragile and undocumented. - Skill auditing: When auditing skill/agent effectiveness, the lack of a clean event means agent usage counts are dramatically undercounted (in one audit,
review-pr-commentsshowed 0 dispatches viatasktool but actually had 390 root-level invocations hidden intransformedContent). - Observability: Users and platform teams can't answer "which custom agents are actually being used?" without deep parsing of message content.
Proposed solution
Emit a new event when /agent <name> is invoked at the session root:
{"type": "session.agent_invoked", "agentName": "review-pr-comments", "agentSource": "user", "timestamp": "..."}Fields:
agentName: The agent identifier as it appears in the.agent.mdfilenameagentSource:"user"for custom agents in~/.copilot/agents/,"project"for repo-level agents,"builtin"for platform agents
This would parallel the existing session.mode_changed and session.model_change events.
Workaround (current)
Parse transformedContent for <agent_instructions> blocks and extract the agent name — but this is fragile, undocumented, and requires access to the full message payload rather than just the event stream.
Metadata
Metadata
Assignees
Labels
area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agentsarea:sessionsSession management, resume, history, session picker, and session state
Activity
k4otix commentedon Dec 3, 2026
+1. This matters for OTel as well as
events.jsonl.Custom agents can carry their own instructions and tool sets, so "which agent was active when this tool call ran?" is a basic question for security review. Today the OTel
invoke_agentspan hasgithub.copilot.agent.typeand the list of available custom agents (github.copilot.context.custom_agent_names), but not the active one. A root-level/agentswitch can't be seen in the trace.A dedicated event for the switch, plus
gen_ai.agent.nameoninvoke_agentand its child spans, would make agent attribution reliable.