[PY] fix: #1705 - Output of multiple calls to same tool are overwritten #2228
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.
The current implementation of the planner did not account for multiple calls to the same tool since it did not keep track of the call id (
call.id
) which is different for each call, regardless of which tool.Therefore, the list was only being indexed by
tool_id
.The result was that subsequent calls to the same tool within the same run would overwrite the result of the previous call, and at the end of the run, results would be missing triggering an Exception.
The issue is fixed by adding a sublevel to the list of tools called as part of a run (this list is stored on assistants_planner.py
tool_map:dict
) which does keep track of the unique call_id, so that their result values are not overwritten by subsequent calls to the same tool within the same run.Linked issues
closes: #1705
Details
In order to trigger this issue, submit a prompt that triggers multiple calls to the same tool on the same run (i.e. which city is warmer today, LA or Chicago?). The same tool would be called once for each city (i.e. get-weather) but the data returned would only contain results for one city. This results on an Exception being raised. Steps can be found on #1705.
Change details
Key change is that
state.temp.action_outputs[command.action_id]
becomesstate.temp.action_outputs[command.action][command.action_id]
on teams/ai/ai.py.Attestation Checklist
My code follows the style guidelines of this project
I have checked for/fixed spelling, linting, and other errors
I have commented my code for clarity
I have made corresponding changes to the documentation (updating the doc strings in the code is sufficient)
My changes generate no new warnings
I have added tests that validates my changes, and provides sufficient test coverage. I have tested with:
New and existing unit tests pass locally with my changes