fix(integ): make calculator tool more robust to LLM output variations #1445
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.
Description
Fixes a flaky integration test in
test_structured_output_agent_loop.pywheretest_tool_use_with_structured_outputwould fail intermittently.Root Cause
The LLM sometimes outputs
'+'instead of'add'as the operation string. The original calculator tool only accepted exact string matches like"add","subtract", etc., causing the function to return0when the LLM used symbols.Example of failure:
This was observed in PR #1444 CI run: https://github.com/strands-agents/sdk-python/actions/runs/20875011420/job/59982925582?pr=1444
Changes
add/+subtract/-/submultiply/*/muldivide///divpower/**/powlower()andstrip()b/a, nowa/bto match standard math notation)ArgssectionRelated Issues
Documentation PR
No documentation changes required - this is a test fixture.
Type of Change
Bug fix (test reliability)
Testing
'add'and'+'Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Created by strands-coder autonomous agent 🦆