github / github/copilot-cli

Feature: Emit a dedicated event when user switches to a custom agent via /agent

Offen
#2,838 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area:agents area:sessions
Vorherrschende Sprache
Shell
Sterne
11.2k
Forks
1.9k
Ø Merge
14 Std. 16 Min.
Gemergte PRs (30 T.)
6

Beschreibung

## Summary

When a user invokes `/agent ` 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 `` 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-comments` rewrites the next user message by prepending `...` into `transformedContent`
- There is no `session.agent_changed` or `session.agent_invoked` event in `events.jsonl`
- `subagent.selected` exists 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 `/agent` switches
- `session.mode_changed` and `session.model_change` exist for other session-level state changes, but agents have no equivalent

## Impact

- **Session analytics**: Tools like [copilot-session-tools](https://github.com/Arithmomaniac/copilot-session-tools) that enrich `events.jsonl` into queryable databases cannot reliably count or filter by which custom agent was used. The only workaround is parsing `` blocks out of `transformedContent`, 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-comments` showed 0 dispatches via `task` tool but actually had 390 root-level invocations hidden in `transformedContent`).
- **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 ` is invoked at the session root:

```jsonl
{"type": "session.agent_invoked", "agentName": "review-pr-comments", "agentSource": "user", "timestamp": "..."}
```

Fields:
- `agentName`: The agent identifier as it appears in the `.agent.md` filename
- `agentSource`: `"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 `` 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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start by locating the root-level /agent command handling and the existing session.mode_changed and session.model_change event emitters. Add the proposed session.agent_invoked event with agentName, agentSource, and timestamp, then verify that invoking /agent at the session root produces the event in events.jsonl without relying on transformedContent parsing.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
shell
Bereich
cli, observability
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.