fix: track all tool invocations in ToolMetrics instead of overwriting#1892
fix: track all tool invocations in ToolMetrics instead of overwriting#1892giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Conversation
62abba9 to
29496bc
Compare
|
Friendly ping — fixes |
29496bc to
ccf5b79
Compare
|
Rebased this branch onto the latest Local validation I ran:
Real branch-vs-main proof (using the repo venv and explicit
So the rebased branch preserves backwards compatibility ( |
Previously, ToolMetrics.add_call() overwrote self.tool with the latest invocation, losing all previous tool inputs and IDs. Users inspecting AgentResult.metrics.tool_metrics could only see the last call's data. Changes: - Add 'invocations' list field to ToolMetrics that accumulates every call - Update add_call() to append each tool invocation to the list - Update to_dict() / get_summary() to expose invocations array - Keep self.tool update for backwards compatibility Closes strands-agents#301
|
Refreshed this branch onto current Repo-native gate (run twice with no code changes between passes):
Results on refreshed head
Direct branch-vs-main proof on exact source trees used the same temporary
Proof result:
The current
|
ccf5b79 to
d3c02e4
Compare
Problem
ToolMetrics.add_call()overwritesself.toolwith the latest invocation on every call (line 142:self.tool = tool). When users inspectAgentResult.metrics.tool_metrics, they can only see the last call'stoolUseIdandinput— all previous invocations are lost.This means
to_dict()/get_summary()only expose the final tool call's data, making it impossible to audit which inputs were passed across multiple invocations of the same tool.Closes #301
Solution
invocations: list[ToolUse]field toToolMetricsthat accumulates every calladd_call()to append each tool invocation to the listto_dict()to expose aninvocationsarray with all tool_use_ids and input_paramsself.toolis still updated to the latest invocation — existing code readingmetrics.toolcontinues to workChanges
src/strands/telemetry/metrics.py: Addedinvocationsfield, updatedadd_call()andto_dict()tests/strands/telemetry/test_metrics.py: Updated existing tests + 2 new tests for invocation trackingTesting
get_summary()includes full invocations array.toolstill points to latest)