Skip to content

feat(tool): add thread-safe whitelist management and dynamic desc#379

Merged
AlbumenJ merged 3 commits intoagentscope-ai:mainfrom
fang-tech:feat-tool-support-denylist-in-shellCommandTool
Dec 28, 2025
Merged

feat(tool): add thread-safe whitelist management and dynamic desc#379
AlbumenJ merged 3 commits intoagentscope-ai:mainfrom
fang-tech:feat-tool-support-denylist-in-shellCommandTool

Conversation

@fang-tech
Copy link
Contributor

@fang-tech fang-tech commented Dec 27, 2025

AgentScope-Java Version

1.0.4

Description

Add a list of allowed commands to the description sent to LLM. This helps to reduce the occurrence of LLM running commands that are not allowed. Although it incurs an increase in the consumption of one-time tokens, it can reduce the number of tool invocations, which is a more token-consuming behavior. At the same time, make the modification of the allowedCommand set thread-safe.

Checklist

Please check the following items before code is ready to be reviewed.

  • 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

@fang-tech fang-tech requested review from a team and Copilot December 27, 2025 16:18
@fang-tech fang-tech changed the title feat(tool): add thread-safe whitelist management and dynamic descript… feat(tool): add thread-safe whitelist management and dynamic desc Dec 27, 2025
Copy link
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

This PR modernizes the ShellCommandTool by migrating from annotation-based tool definitions to the AgentTool interface pattern, while also introducing thread-safe whitelist management capabilities and dynamic description generation.

Key changes include:

  • Refactored from @Tool/@ToolParam annotations to implementing the AgentTool interface with explicit method implementations
  • Enhanced whitelist management with thread-safe operations using ConcurrentHashMap.newKeySet()
  • Added new public API methods for dynamic whitelist manipulation: addAllowedCommand(), removeAllowedCommand(), clearAllowedCommands(), and isCommandAllowed()

Reviewed changes

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

File Description
agentscope-core/src/main/java/io/agentscope/core/tool/coding/ShellCommandTool.java Implements AgentTool interface, replaces HashSet with ConcurrentHashMap for thread-safe whitelist, adds defensive copying in constructor, implements getName/getDescription/getParameters/callAsync methods, and adds new whitelist management API
agentscope-core/src/test/java/io/agentscope/core/tool/coding/ShellCommandToolTest.java Adds comprehensive test coverage for whitelist management operations, thread safety scenarios, AgentTool interface implementation, and updates existing test to use new addAllowedCommand() method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fang-tech fang-tech force-pushed the feat-tool-support-denylist-in-shellCommandTool branch from 8c99831 to 073badf Compare December 27, 2025 16:45
@codecov
Copy link

codecov bot commented Dec 28, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../agentscope/core/tool/coding/ShellCommandTool.java 93.33% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@AlbumenJ AlbumenJ merged commit 44056ef into agentscope-ai:main Dec 28, 2025
4 checks passed
JGoP-L pushed a commit to JGoP-L/agentscope-java that referenced this pull request Dec 29, 2025
…entscope-ai#379)

## AgentScope-Java Version

1.0.4

## Description

Add a list of allowed commands to the description sent to LLM. This
helps to reduce the occurrence of LLM running commands that are not
allowed. Although it incurs an increase in the consumption of one-time
tokens, it can reduce the number of tool invocations, which is a more
token-consuming behavior. At the same time, make the modification of the
allowedCommand set thread-safe.

## Checklist

Please check the following items before code is ready to be reviewed.

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

---------

Co-authored-by: Albumen Kevin <jhq0812@gmail.com>
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.

2 participants