Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.agentscope.core.model.ToolSchema;
import io.agentscope.core.skill.AgentSkill;
import io.agentscope.core.skill.SkillBox;
import io.agentscope.core.skill.SkillFilter;
import io.agentscope.core.skill.repository.AgentSkillRepository;
import io.agentscope.core.skill.repository.FileSystemSkillRepository;
import io.agentscope.core.tool.Toolkit;
Expand Down Expand Up @@ -393,6 +394,8 @@ static SubagentFactory buildDeclaredFactory(
// lose any --add-dir style allow-list configured at the main level.
final io.agentscope.harness.agent.filesystem.spec.LocalFilesystemSpec
capturedLocalFilesystemSpec = b.localFilesystemSpec;
final List<AgentSkillRepository> capturedSkillRepos = List.copyOf(b.skillRepositories);
final Path capturedProjectGlobalSkillsDir = b.projectGlobalSkillsDir;
// See buildGeneralPurposeFactory: propagate the parent's (distributed) state store so the
// subagent's conversation survives cross-node re-materialization. Null in local defaults.
final io.agentscope.core.state.AgentStateStore capturedStateStore = b.stateStoreOverride;
Expand Down Expand Up @@ -467,6 +470,16 @@ static SubagentFactory buildDeclaredFactory(
if (capturedDisableMemoryHooks) sub.disableMemoryHooks();
if (capturedDisableSessionPersistence) sub.disableSessionPersistence();

if (!capturedSkillRepos.isEmpty()) sub.skillRepositories(capturedSkillRepos);
if (capturedProjectGlobalSkillsDir != null) {
sub.projectGlobalSkillsDir(capturedProjectGlobalSkillsDir);
}

List<String> skillAllowlist = decl.getSkills();
if (!skillAllowlist.isEmpty()) {
sub.skillFilter(SkillFilter.only(skillAllowlist.toArray(new String[0])));
}

sub.middlewares(capturedMiddlewares);
return sub.build();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public static SubagentDeclaration parse(String markdown, String name, Path mainW
}

List<String> tools = parseToolNames(asString(fm.get("tools")));
List<String> skills = parseToolNames(asString(fm.get("skills")));

SubagentDeclaration.Builder builder =
SubagentDeclaration.builder()
Expand All @@ -309,7 +310,8 @@ public static SubagentDeclaration parse(String markdown, String name, Path mainW
.mode(declMode)
.hidden(hidden)
.exposeToUser(exposeToUser)
.tools(tools.isEmpty() ? null : tools);
.tools(tools.isEmpty() ? null : tools)
.skills(skills.isEmpty() ? null : skills);

if (workspacePath != null) {
builder.workspace(workspacePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public enum Mode {
private final boolean inheritParentPermissions;
private final Boolean exposeToUser;
private final List<String> tools;
private final List<String> skills;

/** Base URL of the remote task server (e.g. {@code http://host:8080}). */
private final String url;
Expand All @@ -117,6 +118,7 @@ private SubagentDeclaration(Builder b) {
this.inheritParentPermissions = b.inheritParentPermissions;
this.exposeToUser = b.exposeToUser;
this.tools = b.tools != null ? List.copyOf(b.tools) : List.of();
this.skills = b.skills != null ? List.copyOf(b.skills) : List.of();
this.url = b.url;
this.headers = b.headers != null && !b.headers.isEmpty() ? Map.copyOf(b.headers) : null;
}
Expand Down Expand Up @@ -274,6 +276,10 @@ public List<String> getTools() {
return tools;
}

public List<String> getSkills() {
return skills;
}

/** Returns {@code true} when this declaration targets a remote task HTTP server. */
public boolean isRemote() {
return url != null && !url.isBlank();
Expand Down Expand Up @@ -321,6 +327,7 @@ public static final class Builder {
private boolean inheritParentPermissions = true;
private Boolean exposeToUser;
private List<String> tools;
private List<String> skills;
private String url;
private Map<String, String> headers;

Expand Down Expand Up @@ -489,6 +496,11 @@ public Builder tools(List<String> tools) {
return this;
}

public Builder skills(List<String> skills) {
this.skills = skills;
return this;
}

/**
* Remote task server base URL. Mutually exclusive with {@link #workspace(Path)} and a
* non-blank {@link #inlineAgentsBody(String)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import io.agentscope.core.model.ChatResponse;
import io.agentscope.core.model.Model;
import io.agentscope.core.model.ToolSchema;
import io.agentscope.core.skill.SkillFilter;
import io.agentscope.core.state.AgentStateStore;
import io.agentscope.core.tool.AgentTool;
import io.agentscope.core.tool.Toolkit;
Expand Down Expand Up @@ -1018,6 +1019,54 @@ void toolsAllowlist_filtersInheritedParentTools_only() throws Exception {
"child-local memory tools should not be filtered by inherited allowlist");
}

// =========================================================================
// Skills allowlist
// =========================================================================

@Test
void skillsAllowlist_declarationWithSkills_setsSkillFilterOnChild() throws Exception {
Files.createDirectories(workspace);

SubagentDeclaration decl =
SubagentDeclaration.builder()
.name("narrow-skills")
.description("only allowed skills")
.inlineAgentsBody("Focus on allowed skills.")
.skills(List.of("allowed_skill"))
.build();

assertEquals(List.of("allowed_skill"), decl.getSkills());

SkillFilter filter = SkillFilter.only(decl.getSkills().toArray(new String[0]));
assertTrue(filter.isAllowed("allowed_skill"), "allowlisted skill should pass");
assertFalse(filter.isAllowed("denied_skill"), "non-allowlisted skill should be blocked");
}

@Test
void skillsAllowlist_emptyList_defaultsToAll() {
SubagentDeclaration decl =
SubagentDeclaration.builder()
.name("all-skills")
.description("inherits all skills")
.inlineAgentsBody("Use any skill.")
.build();

assertTrue(decl.getSkills().isEmpty(), "no skills declared should yield empty list");
}

@Test
void skillsAllowlist_nullSkills_defaultsToEmptyList() {
SubagentDeclaration decl =
SubagentDeclaration.builder()
.name("null-skills")
.description("null skills")
.inlineAgentsBody("body")
.skills(null)
.build();

assertTrue(decl.getSkills().isEmpty(), "null skills should yield empty list");
}

// =========================================================================
// AgentSpecLoader — markdown declaration parsing
// =========================================================================
Expand Down Expand Up @@ -1049,6 +1098,36 @@ void agentSpecLoader_markdownDeclaration_isolatedWithWorkspacePath() throws Exce
assertEquals(List.of("read_file", "grep_files"), decl.getTools());
}

@Test
void agentSpecLoader_markdownDeclaration_parsesSkillsAllowlist() throws Exception {
Files.createDirectories(workspace);
String markdown =
"""
---
description: Agent with skills filter
tools: [read_file]
skills: [weather_lookup, code_review]
---
""";
SubagentDeclaration decl = AgentSpecLoader.parse(markdown, "filtered-agent", workspace);
assertNotNull(decl);
assertEquals(List.of("weather_lookup", "code_review"), decl.getSkills());
}

@Test
void agentSpecLoader_markdownDeclaration_noSkills_returnsEmptyList() throws Exception {
Files.createDirectories(workspace);
String markdown =
"""
---
description: Agent without skills
---
""";
SubagentDeclaration decl = AgentSpecLoader.parse(markdown, "no-skills", workspace);
assertNotNull(decl);
assertTrue(decl.getSkills().isEmpty(), "no skills declared should yield empty list");
}

@Test
void agentSpecLoader_markdownDeclaration_sharedMode_noPath_inlineBody() throws Exception {
Files.createDirectories(workspace);
Expand Down
Loading