DynamicSkillMiddleware
@SuppressWarnings("deprecation") public class DynamicSkillMiddleware implements MiddlewareBase
io/agentscope/core/skill/DynamicSkillMiddleware.java:61–410Dynamic 技能中间件,在智能体执行流程中提供横切扩展。位于 io.agentscope.core.skill 包,实现 MiddlewareBase。核心成员包括 onSystemPrompt、filterVisible、DynamicSkillMiddleware。
Dynamically composes skills from an ordered list of repositories (AgentSkillRepository)
on every call() via #onSystemPrompt(Agent, RuntimeContext, String), replacing the static
skill prompt with a per-call view that supports per-user skill isolation and one-click
marketplace integration.
The repository list is iterated low-priority first; when two repositories provide a skill
with the same AgentSkill#getName(), the later (higher-priority) entry wins.
Rebuilding on every call is intentional: per-user namespaced repositories may return
different content under the same skill name as the RuntimeContext switches users, so
caching by skill id alone would mask those swaps. A content-addressed cache keyed by the
visible-view signature reuses an already-materialised (immutable) box when the visible content
is unchanged, so uploadSkillFiles only re-runs when content actually changes. No tools
are (re)registered on the shared toolkit.
Subclasses can plug runtime visibility logic (canary lists, environment gates, etc.) by
overriding #filterVisible(List, RuntimeContext) — the default implementation returns
the input list unchanged.
构造器摘要Constructor Summary
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Mono<String> onSystemPrompt(Agent agent, RuntimeContext ctx, String currentPrompt) | 处理系统提示词事件。 Performs the on system prompt operation. |
protected List<AgentSkill> filterVisible(List<AgentSkill> raw, RuntimeContext ctx) | 过滤可见。 Hook for subclasses to drop skills that should not be visible in the current request
(canary releases, allow-lists, environment gates, …). |
构造器详情Constructor Detail
DynamicSkillMiddleware
public DynamicSkillMiddleware(List<AgentSkillRepository> repositories, Toolkit toolkit)
初始化 DynamicSkillMiddleware 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
repositories | List<AgentSkillRepository> | repositories(类型 `List`)。The repositories. |
toolkit | Toolkit | 工具包(类型 `Toolkit`)。The toolkit. |
io/agentscope/core/skill/DynamicSkillMiddleware.java:84–86DynamicSkillMiddleware
public DynamicSkillMiddleware(List<AgentSkillRepository> repositories, Toolkit toolkit, SkillFilter builderFilter)
初始化 DynamicSkillMiddleware 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
repositories | List<AgentSkillRepository> | repositories(类型 `List`)。The repositories. |
toolkit | Toolkit | 工具包(类型 `Toolkit`)。The toolkit. |
builderFilter | SkillFilter | 构建器过滤器(类型 `SkillFilter`)。The builder filter. |
io/agentscope/core/skill/DynamicSkillMiddleware.java:88–91DynamicSkillMiddleware
public DynamicSkillMiddleware(List<AgentSkillRepository> repositories, Toolkit toolkit, SkillFilter builderFilter, boolean codeExecutionEnabled, Path workDir)
初始化 DynamicSkillMiddleware 实例。
Full constructor.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
repositories | List<AgentSkillRepository> | repositories(类型 `List`)。compose-ordered list (low-to-high priority); merged by skill name |
toolkit | Toolkit | 工具包(类型 `Toolkit`)。toolkit to register `load_skill_through_path` on |
builderFilter | SkillFilter | 构建器过滤器(类型 `SkillFilter`)。optional builder-time skill filter; null treated as `SkillFilter#all()` |
codeExecutionEnabled | boolean | code 执行已启用(类型 `boolean`)。when `true`, toggles the prompt provider's code-execution block. Set this only when the agent has a shell-like tool wired in; otherwise the prompt asks the model to do things it cannot. |
workDir | Path | work 目录(类型 `Path`)。stable working directory for `uploadSkillFiles`; `null` ⇒ the middleware mkdtemps one on first reload and reuses it |
io/agentscope/core/skill/DynamicSkillMiddleware.java:105–122方法详情Method Detail
onSystemPrompt
public Mono<String> onSystemPrompt(Agent agent, RuntimeContext ctx, String currentPrompt)
处理系统提示词事件。
Performs the on system prompt operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | Agent | 智能体(类型 `Agent`)。The agent. |
ctx | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。The ctx. |
currentPrompt | String | 当前提示词(类型 `String`)。The current prompt. |
Mono<String>io/agentscope/core/skill/DynamicSkillMiddleware.java:124–142filterVisible
protected List<AgentSkill> filterVisible(List<AgentSkill> raw, RuntimeContext ctx)
过滤可见。
Hook for subclasses to drop skills that should not be visible in the current request (canary releases, allow-lists, environment gates, …).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
raw | List<AgentSkill> | 原始(类型 `List`)。the merged, deduplicated skill list (low-to-high repository priority order) |
ctx | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。the per-call `RuntimeContext`; never `null` |
List<AgentSkill>io/agentscope/core/skill/DynamicSkillMiddleware.java:156–158