Skip to content

fix(skill): add methods for setting skill states#1055

Open
jujn wants to merge 1 commit intoagentscope-ai:mainfrom
jujn:fix_1051
Open

fix(skill): add methods for setting skill states#1055
jujn wants to merge 1 commit intoagentscope-ai:mainfrom
jujn:fix_1051

Conversation

@jujn
Copy link
Contributor

@jujn jujn commented Mar 27, 2026

Description

Close #1051

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

@jujn jujn requested review from a team and Copilot March 27, 2026 14:19
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

Adds an API to explicitly toggle a skill’s logical activation state, enabling callers to deactivate skills and (after an explicit sync) disable the corresponding tool group in the bound Toolkit. This addresses the need raised in #1051 to inactivate a skill and its tools so they don’t remain available across subsequent turns.

Changes:

  • Add SkillBox#setSkillActive(String, boolean) with Javadoc clarifying that syncToolGroupStates() must be called to apply changes to the Toolkit.
  • Add a JUnit test verifying that tool-group activation changes only after an explicit syncToolGroupStates() call.

Reviewed changes

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

File Description
agentscope-core/src/main/java/io/agentscope/core/skill/SkillBox.java Introduces setSkillActive(...) to update the logical activation state of a skill.
agentscope-core/src/test/java/io/agentscope/core/skill/SkillBoxTest.java Adds coverage for the new activation API and the explicit-sync behavior with tool groups.

Comment on lines +306 to +311
* @throws IllegalArgumentException if skillId is null
*/
public void setSkillActive(String skillId, boolean active) {
if (skillId == null) {
throw new IllegalArgumentException("Skill ID cannot be null");
}
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

setSkillActive silently no-ops when skillId is unknown (because SkillRegistry#setSkillActive ignores missing registrations) but still logs as if the state was updated. This can hide configuration mistakes and makes it hard for callers to know whether deactivation actually happened. Consider validating exists(skillId) and throwing an IllegalArgumentException (or returning a boolean / logging a warning when the skill is not found).

Suggested change
* @throws IllegalArgumentException if skillId is null
*/
public void setSkillActive(String skillId, boolean active) {
if (skillId == null) {
throw new IllegalArgumentException("Skill ID cannot be null");
}
* @throws IllegalArgumentException if skillId is null or the skill does not exist
*/
public void setSkillActive(String skillId, boolean active) {
if (skillId == null) {
throw new IllegalArgumentException("Skill ID cannot be null");
}
if (!exists(skillId)) {
throw new IllegalArgumentException("Skill ID does not exist: " + skillId);
}

Copilot uses AI. Check for mistakes.
Comment on lines +262 to +283
@Test
@DisplayName("Should update skill active state and require explicit sync")
void testSetSkillActiveRequiresExplicitSync() {
AgentSkill skill =
new AgentSkill("test_active_skill", "Test Active Skill", "# Content", null);
AgentTool testTool = createTestTool("active_test_tool");

skillBox.registration().skill(skill).agentTool(testTool).apply();

String toolsGroupName = skill.getSkillId() + "_skill_tools";

assertFalse(
skillBox.isSkillActive(skill.getSkillId()),
"Skill should be inactive initially");
assertNotNull(toolkit.getToolGroup(toolsGroupName), "ToolGroup should be created");
assertFalse(
toolkit.getToolGroup(toolsGroupName).isActive(),
"ToolGroup should be inactive initially");

skillBox.setSkillActive(skill.getSkillId(), true);
skillBox.syncToolGroupStates();
assertTrue(
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

This new behavior adds a null check in setSkillActive, but the test suite doesn’t currently assert that setSkillActive(null, ...) throws IllegalArgumentException (similar to the existing null-safety tests for removeSkill/exists). Adding a test case would prevent regressions and clarify the intended contract.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...c/main/java/io/agentscope/core/skill/SkillBox.java 60.00% 1 Missing and 1 partial ⚠️

📢 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.

[Feature]: skill激活后如何取消并inactive对应的tool

2 participants