Skip to content

Commit 7bed2e5

Browse files
rinceyuanj-zhangyiyuanSteveSandersonMSCopilot
authored
docs: document complete sub-agent event data fields (#2072)
* docs: document complete sub-agent event data fields The event table for sub-agent lifecycle events was missing several fields that are available in the typed event interfaces: - subagent.started: add \model?\ - subagent.completed: add \model?\, \durationMs?\, \ otalTokens?\, \ otalToolCalls?\ - subagent.failed: add \model?\, \durationMs?\, \ otalTokens?\, \ otalToolCalls?\ Also update the Node.js code example to demonstrate accessing the performance metrics (duration, tokens, tool calls) from completed/failed events. * docs: complete subagent event references Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: j-zhangyiyuan <j-zhangyiyuan@microsoft.com> Co-authored-by: Steve Sanderson <1101362+SteveSandersonMS@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fca5346 commit 7bed2e5

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

docs/features/custom-agents.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ Sub-agent-originated session events share the parent session stream and include
445445
| Event | Emitted when | Data |
446446
|-------|-------------|------|
447447
| `subagent.selected` | Runtime selects an agent for the task | `agentName`, `agentDisplayName`, `tools` |
448-
| `subagent.started` | Sub-agent begins execution | `toolCallId`, `agentName`, `agentDisplayName`, `agentDescription` |
449-
| `subagent.completed` | Sub-agent finishes successfully | `toolCallId`, `agentName`, `agentDisplayName` |
450-
| `subagent.failed` | Sub-agent encounters an error | `toolCallId`, `agentName`, `agentDisplayName`, `error` |
448+
| `subagent.started` | Sub-agent begins execution | `toolCallId`, `agentName`, `agentDisplayName`, `agentDescription`, `model?` |
449+
| `subagent.completed` | Sub-agent finishes successfully | `toolCallId`, `agentName`, `agentDisplayName`, `model?`, `durationMs?`, `totalTokens?`, `totalToolCalls?` |
450+
| `subagent.failed` | Sub-agent encounters an error | `toolCallId`, `agentName`, `agentDisplayName`, `error`, `model?`, `durationMs?`, `totalTokens?`, `totalToolCalls?` |
451451
| `subagent.deselected` | Runtime switches away from the sub-agent ||
452452

453453
### Subscribing to events
@@ -466,11 +466,15 @@ session.on((event) => {
466466

467467
case "subagent.completed":
468468
console.log(`✅ Sub-agent completed: ${event.data.agentDisplayName}`);
469+
if (event.data.durationMs !== undefined) console.log(` Duration: ${event.data.durationMs}ms`);
470+
if (event.data.totalTokens !== undefined) console.log(` Tokens: ${event.data.totalTokens}`);
471+
if (event.data.totalToolCalls !== undefined) console.log(` Tool calls: ${event.data.totalToolCalls}`);
469472
break;
470473

471474
case "subagent.failed":
472475
console.log(`❌ Sub-agent failed: ${event.data.agentDisplayName}`);
473476
console.log(` Error: ${event.data.error}`);
477+
if (event.data.durationMs !== undefined) console.log(` Duration: ${event.data.durationMs}ms`);
474478
break;
475479

476480
case "subagent.selected":

docs/features/streaming-events.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ A custom agent was invoked as a sub-agent.
741741
| `agentName` | `string` || Internal name of the sub-agent |
742742
| `agentDisplayName` | `string` || Human-readable display name |
743743
| `agentDescription` | `string` || Description of what the sub-agent does |
744+
| `model` | `string` | | Model the sub-agent will run with, when known at start |
744745

745746
### `subagent.completed`
746747

@@ -751,6 +752,10 @@ A sub-agent finished successfully.
751752
| `toolCallId` | `string` || Matches the corresponding `subagent.started` |
752753
| `agentName` | `string` || Internal name |
753754
| `agentDisplayName` | `string` || Display name |
755+
| `model` | `string` | | Model used by the sub-agent |
756+
| `durationMs` | `number` | | Wall-clock execution duration in milliseconds |
757+
| `totalTokens` | `number` | | Total input and output tokens consumed |
758+
| `totalToolCalls` | `number` | | Total tool calls made |
754759

755760
### `subagent.failed`
756761

@@ -762,6 +767,10 @@ A sub-agent encountered an error.
762767
| `agentName` | `string` || Internal name |
763768
| `agentDisplayName` | `string` || Display name |
764769
| `error` | `string` || Error message |
770+
| `model` | `string` | | Model selected for the sub-agent, when known |
771+
| `durationMs` | `number` | | Wall-clock execution duration in milliseconds |
772+
| `totalTokens` | `number` | | Total input and output tokens consumed before failure |
773+
| `totalToolCalls` | `number` | | Total tool calls made before failure |
765774

766775
### `subagent.selected`
767776

@@ -966,9 +975,9 @@ This table lists key `data` payload fields. Common envelope fields are documente
966975
| `user_input.completed` || User Input | `requestId` |
967976
| `elicitation.requested` || User Input | `requestId`, `message`, `requestedSchema` |
968977
| `elicitation.completed` || User Input | `requestId` |
969-
| `subagent.started` | | Sub-Agent | `toolCallId`, `agentName`, `agentDisplayName` |
970-
| `subagent.completed` | | Sub-Agent | `toolCallId`, `agentName`, `agentDisplayName` |
971-
| `subagent.failed` | | Sub-Agent | `toolCallId`, `agentName`, `error` |
978+
| `subagent.started` | | Sub-Agent | `toolCallId`, `agentName`, `agentDisplayName`, `model?` |
979+
| `subagent.completed` | | Sub-Agent | `toolCallId`, `agentName`, `agentDisplayName`, `model?`, `durationMs?`, `totalTokens?`, `totalToolCalls?` |
980+
| `subagent.failed` | | Sub-Agent | `toolCallId`, `agentName`, `error`, `model?`, `durationMs?`, `totalTokens?`, `totalToolCalls?` |
972981
| `subagent.selected` | | Sub-Agent | `agentName`, `agentDisplayName`, `tools` |
973982
| `subagent.deselected` | | Sub-Agent | *(empty)* |
974983
| `skill.invoked` | | Skill | `name`, `path`, `content`, `allowedTools?` |

0 commit comments

Comments
 (0)