Track multi-agent v2 spawn calls in analytics (#39722)

## What changed

- Emit started and completed collaboration tool events for multi-agent v2
  `spawn_agent` calls, including failed invocations.
- Record execution duration and successful child-agent configuration metadata
  without including the spawn prompt.
- Deduplicate collaboration and subagent activity items by call ID when
  calculating per-turn subagent tool counts.

## Testing

- Extend the app-server multi-agent v2 integration test to cover successful
  and failed spawn telemetry, duration, prompt omission, and turn counts.

GitOrigin-RevId: c1c2fb9cc2a1a9b0f63ef68509ad36d11a92d1e5
This commit is contained in:
jif authored and copyberry committed 2026-08-20 14:33:55 +00:00
1 parent 1674b0a130
commit 9894a14c81
4 files changed
+182 -11

No files matched your search

+7 -2
View File
@@ -464,6 +464,7 @@ struct TurnToolCounts {
mcp_tool_call: usize,
dynamic_tool_call: usize,
subagent_tool_call: usize,
subagent_tool_call_ids: HashSet<String>,
web_search: usize,
image_generation: usize,
}
@@ -475,7 +476,11 @@ impl TurnToolCounts {
ThreadItem::FileChange { .. } => self.file_change += 1,
ThreadItem::McpToolCall { .. } => self.mcp_tool_call += 1,
ThreadItem::DynamicToolCall { .. } => self.dynamic_tool_call += 1,
ThreadItem::CollabAgentToolCall { .. } | ThreadItem::SubAgentActivity { .. } => {
ThreadItem::CollabAgentToolCall { id, .. }
| ThreadItem::SubAgentActivity { id, .. } => {
if !self.subagent_tool_call_ids.insert(id.clone()) {
return;
}
self.subagent_tool_call += 1;
}
ThreadItem::WebSearch(_) => self.web_search += 1,
@@ -2672,7 +2677,7 @@ fn tool_item_event(input: ToolItemEventInput<'_>) -> Option<TrackEventRequest> {
ToolItemOutcome {
terminal_status,
failure_kind,
execution_duration_ms: None,
execution_duration_ms: observed_duration_ms(started_at_ms, completed_at_ms),
},
ToolItemContext {
started_at_ms,