fix: track all tool invocations in ToolMetrics instead of overwriting#1892
Open
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Open
fix: track all tool invocations in ToolMetrics instead of overwriting#1892giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Conversation
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
62abba9 to
29496bc
Compare
Contributor
Author
|
Friendly ping — fixes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)