Skip to content

Conversation

@zastrowm
Copy link
Member

@zastrowm zastrowm commented Oct 24, 2025

Description

First fix for part of #1069

Previous to this PR, the flow was:

If the agent generates an invalid tool name (say tool with spaces), the flow ends up being:

  1. The LLM generates a toolUse block for a tool that has an invalid name (specifically it doesn't match this regex
  2. The message with the toolUse is appended to the agent's history.
  3. Tool execution begins - first in event_loop._handle_tool_execution which calls validate_and_prepare_tools is invoked. The validation fails which has two side-effects:
    1. The original/invalid tool name is overwritten with INVALID_TOOL_NAME
    2. A tool-result is added indicating the invalidness of the tool-name
  4. We then early exit out of tool execution because there are no tool-uses

At (4) above the loop should instead continue as normal and pass flow back to the model which is what this PR does.

AFAICT the "bail out if there are no tool-uses" made sense back before we had the full Agent interface and you had to handle tool invocations yourself; however, we should never be returning out of the loop with tool_use now as we manage the tool calling on behalf of the agent and we don't guide folks to check the stop_reason for cases like this. AKA: we need to handle this automatically.

Notes

This PR also removes __init__ from the test types module - when attempting to run tests from the IDE I was running into dependencies which were importing types from the test module.

It seems to be a well-known problem:

And the solution is just to remove the init from the test types module.

Related Issues

#1069

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Partial fix to strands-agents#1069 - previously the agent would prematurely exit if the agent generated a tool with an invalid name; this avoids that by ensuring the agent loop continues with zero tool-uses.
When attempting to run tests from the IDE I was running into dependencies which were importing types from the test module.

It seems to be a well-known problem:

 - https://stackoverflow.com/questions/36669895/site-py-attributeerror-module-object-has-no-attribute-moduletype-upon-runn
 - https://stackoverflow.com/questions/36250353/importing-a-library-from-or-near-a-script-with-the-same-name-raises-attribute

And the quick solution is just to remove the __init__ from the test types module.
@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

pgrayy
pgrayy previously approved these changes Oct 24, 2025
mehtarac
mehtarac previously approved these changes Oct 24, 2025
@zastrowm zastrowm dismissed stale reviews from mehtarac and pgrayy via 4451d91 October 24, 2025 14:38
@github-actions github-actions bot added size/m and removed size/m labels Oct 24, 2025
@zastrowm zastrowm merged commit 999e654 into strands-agents:main Oct 24, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants