Skip to content

feat(copilot): attribute tool metrics to invoking agents - #6266

Merged
j15z merged 6 commits into
stagingfrom
feat/track-subagent-tool-use
Aug 5, 2026
Merged

feat(copilot): attribute tool metrics to invoking agents#6266
j15z merged 6 commits into
stagingfrom
feat/track-subagent-tool-use

Conversation

@j15z

@j15zj15z commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve the invoking agent across Sim tool execution and replay paths
  • Attribute tool call, latency, and span telemetry to bounded agent names
  • Fall back to main and collapse unknown labels to other
  • Coordinate with the companion Mothership PR: https://github.com/simstudioai/mothership/pull/399

Type of Change

  • New feature

Testing

  • bun run lint
  • Full ship audit suite
  • Focused Copilot tests: 51 passing

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercelBot commented Aug 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentActionsUpdated (UTC)
docsSkippedSkippedAug 4, 2026 10:30pm

Request Review

@cursor

cursorBot commented Aug 4, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches copilot streaming state and shared telemetry label keys; execution semantics are mostly unchanged aside from new optional fields and metric attributes.

Overview
Copilot Sim-side tool telemetry now records which agent invoked each tool, aligned with the companion Mothership work.

Stream handling adds optional agentId on ToolCallState, taken from event.scope.agentId (default main). Main and subagent tool registration paths set it on new calls; replays use ??= so the first attribution wins when partial frames repeat with different agents.

Metrics and traces extend recordSimToolMetric and withCopilotToolSpan with gen_ai.agent.name, normalized via normalizeToolAgentId against registered catalog subagent IDs plus main, collapsing anything else to other for bounded Prometheus cardinality. The tool executor forwards toolCall.agentId ?? 'main on success, error, and unexpected throw paths.

Reviewed by Cursor Bugbot for commit 560fa26. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-appsBot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR preserves invoking-agent attribution through Copilot tool handling and applies a shared bounded normalization policy to tool metrics and spans.

  • Stores the invoking agent on tool-call state, including partial and replayed calls.
  • Adds normalized agent labels to Sim tool counters, duration histograms, and OpenTelemetry spans.
  • Adds focused coverage for propagation, replay behavior, fallback attribution, and unknown-agent normalization.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported unbounded span-label issue is fixed because both tool metrics and spans now use the same catalog-backed normalization.

Important Files Changed

FilenameOverview
apps/sim/lib/copilot/request/handlers/tool.tsPropagates event-scope agent IDs into main and subagent tool-call state while retaining the initial attribution during replay.
apps/sim/lib/copilot/request/metrics.tsAdds a catalog-derived bounded agent-name normalizer and includes the normalized value in tool metrics.
apps/sim/lib/copilot/request/otel.tsApplies the shared agent-name normalization to Copilot tool spans, resolving the previously reported unbounded-label issue.
apps/sim/lib/copilot/request/tools/executor.tsForwards stored agent attribution to both span and metric emission across success and error paths.

Reviews (2): Last reviewed commit: "fix(copilot): bound tool span agent labe..." | Re-trigger Greptile

Comment threadapps/sim/lib/copilot/request/otel.ts Outdated
@j15z
j15zforce-pushed the feat/track-subagent-tool-use branch from b81c66e to 560fa26CompareAugust 4, 2026 22:29
@j15z

j15z commented Aug 4, 2026

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@j15z

j15z commented Aug 4, 2026

Copy link
Copy Markdown
CollaboratorAuthor

@cursor review

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 560fa26. Configure here.

@j15z
j15z merged commit 9ff7eae into stagingAug 5, 2026
30 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/track-subagent-tool-use branch August 5, 2026 18:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@j15z@Sg312