Skip to content

fix: prevent presetParameters from being overridden by tool-call input#1172

Merged
LearningGp merged 8 commits into
agentscope-ai:mainfrom
JGoP-L:fix-preset-parameters-precedence
Apr 28, 2026
Merged

fix: prevent presetParameters from being overridden by tool-call input#1172
LearningGp merged 8 commits into
agentscope-ai:mainfrom
JGoP-L:fix-preset-parameters-precedence

Conversation

@JGoP-L

@JGoP-L JGoP-L commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

1.0.12-SNAPSHOT

Description

This PR fixes an issue where presetParameters could be overridden by tool-call input during tool execution.

Background:
presetParameters are intended for framework-controlled values such as API keys or other hidden parameters. While these fields are excluded from the tool schema shown to the LLM, the execution-time merge order in ToolExecutor allowed tool-call input to overwrite preset values when the same key appeared in both places.

Changes made:

  • Updated ToolExecutor to merge tool-call input first and apply presetParameters last
  • Ensured preset parameters take precedence during execution and cannot be overridden by LLM-generated or caller-provided input
  • Updated the related unit test to reflect the intended precedence behavior

How to test:

  • Run:
    • mvn -pl agentscope-core -Dtest=io.agentscope.core.tool.ToolkitTest#testPresetParameters test
    • mvn -pl agentscope-core -Dtest=io.agentscope.core.tool.ToolkitTest#testPresetParametersOverride test
    • mvn -pl agentscope-core -Dtest=io.agentscope.core.tool.ToolkitTest test
    • mvn -pl agentscope-core -Dtest=ToolExecutorTest test
  • Verify that preset parameters are still injected correctly
  • Verify that when the same parameter exists in both tool-call input and presetParameters, the preset value wins

Closes #1119

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@JGoP-L JGoP-L requested review from a team and Copilot April 9, 2026 01:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a security/contract bug in ToolExecutor where framework-controlled presetParameters could be overwritten by tool-call input during execution, ensuring preset values remain authoritative (e.g., API keys and other hidden parameters).

Changes:

  • Adjusted tool input merge order so tool-call input is applied first and presetParameters are applied last (take precedence).
  • Updated the preset-parameter precedence unit test expectation to match the intended behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
agentscope-core/src/main/java/io/agentscope/core/tool/ToolExecutor.java Changes merge order so preset parameters override any same-key tool-call/caller input during execution.
agentscope-core/src/test/java/io/agentscope/core/tool/ToolkitTest.java Updates testPresetParametersOverride to assert preset values win over provided input.

@codecov

codecov Bot commented Apr 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread agentscope-core/src/main/java/io/agentscope/core/tool/ToolExecutor.java Outdated

@LearningGp LearningGp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@LearningGp LearningGp merged commit a951efe into agentscope-ai:main Apr 28, 2026
5 checks passed
liangxingguang pushed a commit to liangxingguang/agentscope-java that referenced this pull request May 21, 2026
agentscope-ai#1172)

## AgentScope-Java Version

1.0.12-SNAPSHOT

## Description

This PR fixes an issue where `presetParameters` could be overridden by
tool-call input during tool execution.

Background:
`presetParameters` are intended for framework-controlled values such as
API keys or other hidden parameters. While these fields are excluded
from the tool schema shown to the LLM, the execution-time merge order in
`ToolExecutor` allowed tool-call input to overwrite preset values when
the same key appeared in both places.

Changes made:
- Updated `ToolExecutor` to merge tool-call input first and apply
`presetParameters` last
- Ensured preset parameters take precedence during execution and cannot
be overridden by LLM-generated or caller-provided input
- Updated the related unit test to reflect the intended precedence
behavior

How to test:
- Run:
- `mvn -pl agentscope-core
-Dtest=io.agentscope.core.tool.ToolkitTest#testPresetParameters test`
- `mvn -pl agentscope-core
-Dtest=io.agentscope.core.tool.ToolkitTest#testPresetParametersOverride
test`
- `mvn -pl agentscope-core -Dtest=io.agentscope.core.tool.ToolkitTest
test`
  - `mvn -pl agentscope-core -Dtest=ToolExecutorTest test`
- Verify that preset parameters are still injected correctly
- Verify that when the same parameter exists in both tool-call input and
`presetParameters`, the preset value wins

Closes agentscope-ai#1119

## Checklist

- [ ]  Code has been formatted with `mvn spotless:apply`
- [ ]  All tests are passing (`mvn test`)
- [ ]  Javadoc comments are complete and follow project conventions
- [ ] Related documentation has been updated (e.g. links, examples,
etc.)
- [x]  Code is ready for review
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.

[Bug] presetParameters overridden by LLM input due to incorrect merge order in ToolExecutor

3 participants