Skip to content

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

Open
JGoP-L wants to merge 4 commits intoagentscope-ai:mainfrom
JGoP-L:fix-preset-parameters-precedence
Open

fix: prevent presetParameters from being overridden by tool-call input#1172
JGoP-L wants to merge 4 commits intoagentscope-ai:mainfrom
JGoP-L:fix-preset-parameters-precedence

Conversation

@JGoP-L
Copy link
Copy Markdown
Contributor

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

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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

2 participants