AS AgentScopeAPI 手册 / API Reference

DynamicSkillMiddleware

@SuppressWarnings("deprecation") public class DynamicSkillMiddleware implements MiddlewareBase
源码Source io/agentscope/core/skill/DynamicSkillMiddleware.java:61–410

Dynamic 技能中间件,在智能体执行流程中提供横切扩展。位于 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

构造器Constructor说明Description
public DynamicSkillMiddleware(List<AgentSkillRepository> repositories, Toolkit toolkit)
初始化 `DynamicSkillMiddleware` 实例。
Creates a new instance.
public DynamicSkillMiddleware(List<AgentSkillRepository> repositories, Toolkit toolkit, SkillFilter builderFilter)
初始化 `DynamicSkillMiddleware` 实例。
Creates a new instance.
public DynamicSkillMiddleware(List<AgentSkillRepository> repositories, Toolkit toolkit, SkillFilter builderFilter, boolean codeExecutionEnabled, Path workDir)
初始化 `DynamicSkillMiddleware` 实例。
Full constructor.

方法摘要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.

参数Parameters
名称Name类型Type说明Description
repositoriesList<AgentSkillRepository>repositories(类型 `List`)。The repositories.
toolkitToolkit工具包(类型 `Toolkit`)。The toolkit.
源码Source io/agentscope/core/skill/DynamicSkillMiddleware.java:84–86

DynamicSkillMiddleware

public DynamicSkillMiddleware(List<AgentSkillRepository> repositories, Toolkit toolkit, SkillFilter builderFilter)

初始化 DynamicSkillMiddleware 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
repositoriesList<AgentSkillRepository>repositories(类型 `List`)。The repositories.
toolkitToolkit工具包(类型 `Toolkit`)。The toolkit.
builderFilterSkillFilter构建器过滤器(类型 `SkillFilter`)。The builder filter.
源码Source io/agentscope/core/skill/DynamicSkillMiddleware.java:88–91

DynamicSkillMiddleware

public DynamicSkillMiddleware(List<AgentSkillRepository> repositories, Toolkit toolkit, SkillFilter builderFilter, boolean codeExecutionEnabled, Path workDir)

初始化 DynamicSkillMiddleware 实例。

Full constructor.

参数Parameters
名称Name类型Type说明Description
repositoriesList<AgentSkillRepository>repositories(类型 `List`)。compose-ordered list (low-to-high priority); merged by skill name
toolkitToolkit工具包(类型 `Toolkit`)。toolkit to register `load_skill_through_path` on
builderFilterSkillFilter构建器过滤器(类型 `SkillFilter`)。optional builder-time skill filter; null treated as `SkillFilter#all()`
codeExecutionEnabledbooleancode 执行已启用(类型 `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.
workDirPathwork 目录(类型 `Path`)。stable working directory for `uploadSkillFiles`; `null` ⇒ the middleware mkdtemps one on first reload and reuses it
源码Source 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.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。The agent.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
currentPromptString当前提示词(类型 `String`)。The current prompt.
返回Returns Mono<String>
返回Mono。Returns mono.
源码Source io/agentscope/core/skill/DynamicSkillMiddleware.java:124–142

filterVisible

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, …).

参数Parameters
名称Name类型Type说明Description
rawList<AgentSkill>原始(类型 `List`)。the merged, deduplicated skill list (low-to-high repository priority order)
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。the per-call `RuntimeContext`; never `null`
返回Returns List<AgentSkill>
返回列出。the visible subset (must not be `null`; an empty list short-circuits the prompt update for this call)
源码Source io/agentscope/core/skill/DynamicSkillMiddleware.java:156–158

继承成员Inherited Members

继承自Methods inherited from MiddlewareBase
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.