Skip to content

feat(core): add an opt-in guard for repeated tool calls - #4313

Open
logicwu0 wants to merge 2 commits into
agentscope-ai:mainfrom
logicwu0:feat/4148-repetition-guard
Open

logicwu0 wants to merge 2 commits into
agentscope-ai:mainfrom
logicwu0:feat/4148-repetition-guard

Conversation

@logicwu0

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT

Description

Fixes #4148. With a model repeatedly requesting the same local tool and arguments, both call() and streamEvents() execute the tool four times when maxIters=4. That remains the default. Applications can opt in to RepetitionGuardMiddleware to warn the model and stop before dispatching another identical request.

The guard tracks consecutive calls within a single invocation. It ignores call IDs and JSON object key order, preserves array order, and supports tool-name exclusions for polling. Permission checks run first. At the stop threshold the entire not-yet-dispatched batch is skipped, its calls are accounted for, and both entry points return REPEATED_TOOL_CALL. For example, thresholds of 2 and 3 allow two tool executions, warn before the next reasoning step, and block the third execution.

Verified with a local mock model and a counting tool, without provider credentials. All 12 focused cases passed, including permission confirmation, external tools, batch receipts, and isolation across overlap, cancellation and subsequent turns. Full Maven reactor verification passed (114 modules); the documentation tests, build validation, and link checks also passed.

Checklist

  • Code formatted with mvn spotless:apply
  • Maven tests passed as part of mvn verify (environment-dependent skips remain)
  • Middleware behavior documented in English and Chinese with an opt-in example
  • Ready for review

@mintlify

mintlify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 3aed75d.

Approve preview

@zouyx zouyx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add an opt-in RepetitionGuardMiddleware for repeated tool calls

2 participants