fix(think): implement automatic recursion prevention for think tool#167
Merged
cagataycali merged 1 commit intostrands-agents:mainfrom Jul 22, 2025
Merged
Conversation
The think tool was vulnerable to infinite recursion when nested agents would call the think tool again, creating a loop. This fix implements automatic exclusion of the 'think' tool from nested agents to prevent this recursion issue. Key changes: - Automatically filter out 'think' tool when creating nested agents - Added logging for recursion prevention (warning for explicit requests, debug for inheritance) - Updated system prompts to encourage use of other tools instead of prohibiting think tool - Comprehensive test coverage for all recursion scenarios The fix handles both explicit tool requests and tool inheritance scenarios: - When tools are explicitly specified and include 'think', it logs a warning and excludes it - When inheriting all tools from parent, it automatically excludes 'think' with debug logging - Maintains compatibility with existing functionality while preventing recursion Root cause was the think tool being available to its own nested agents, allowing infinite recursive calls. The solution preserves all other tools and functionality while safely preventing this specific recursion pattern. Tested with multiple scenarios including explicit requests, inheritance, empty tool lists, and multi-cycle operations.
jer96
approved these changes
Jul 22, 2025
3 tasks
TAKEDA-Takashi
added a commit
to TAKEDA-Takashi/tools
that referenced
this pull request
Feb 5, 2026
…revent recursion When _create_task_agent() inherits tools from the parent agent, the workflow tool itself was included, which could cause infinite recursion if a task agent invoked the workflow tool again. This follows the same recursion prevention pattern established by the think tool (PR strands-agents#167): the workflow tool is automatically excluded from task agents in both the explicit tool list path and the inherit-all path. Closes strands-agents#383 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
4 tasks
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.
Description
This PR implements automatic recursion prevention for the
thinktool to resolve a critical bug where nested agents could call thethinktool recursively, causing infinite loops and stack overflow errors.Problem
The
thinktool was vulnerable to infinite recursion when:thinktool itself)thinktoolthinkagainThis created a dangerous recursion pattern:
think→ nested agent →think→ nested agent → ∞Solution
Implemented automatic exclusion of the
thinktool from nested agents with:thinktool from nested agent tool listsKey Changes
think.pyto excludethinktool from nested agentsthinkthinktool requestedRelated Issues
Fixes infinite recursion bug in think tool that could cause stack overflow and system instability.
Documentation PR
No documentation changes required - this is an internal bug fix that maintains existing API compatibility.
Type of Change
Testing
Comprehensive testing completed with all quality assurance checks passing:
Pre-commit Hooks (All Passed ✅)
hatch fmt --linter- ✅ Passedhatch fmt --formatter- ✅ PassedAdditional Testing
Checklist
Test Results Summary
Before/After Behavior
Before (Problematic):
After (Fixed):
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.