类 DynamicSkillMiddleware

java.lang.Object
io.agentscope.core.skill.DynamicSkillMiddleware
所有已实现的接口:
MiddlewareBase

public class DynamicSkillMiddleware extends Object implements MiddlewareBase
Dynamically composes skills from an ordered list of repositories 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. bindToolkit / registerSkillLoadTool are idempotent on a fresh SkillBox, so the rebuild stays cheap.

Subclasses can plug runtime visibility logic (canary lists, environment gates, etc.) by overriding filterVisible(List, RuntimeContext) — the default implementation returns the input list unchanged.

  • 构造器详细资料

    • DynamicSkillMiddleware

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

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

      public DynamicSkillMiddleware(List<AgentSkillRepository> repositories, Toolkit toolkit, SkillFilter builderFilter, boolean codeExecutionEnabled, Path workDir)
      Full constructor.
      参数:
      repositories - compose-ordered list (low-to-high priority); merged by skill name
      toolkit - toolkit to register load_skill_through_path on
      builderFilter - optional builder-time skill filter; null treated as SkillFilter.all()
      codeExecutionEnabled - 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 - stable working directory for uploadSkillFiles; null ⇒ the middleware mkdtemps one on first reload and reuses it
  • 方法详细资料

    • getCurrentSkillBox

      public SkillBox getCurrentSkillBox()
      Returns the most recently materialised SkillBox, or null when no skills are visible yet (e.g. before the first call()).
    • onSystemPrompt

      public reactor.core.publisher.Mono<String> onSystemPrompt(Agent agent, RuntimeContext ctx, String currentPrompt)
      从接口复制的说明: MiddlewareBase
      Transform the system prompt string (pipeline pattern).

      Multiple middlewares are applied sequentially; each receives the output of the previous one.

      指定者:
      onSystemPrompt 在接口中 MiddlewareBase
      参数:
      agent - the agent instance
      ctx - per-call runtime context (session, user, attributes)
      currentPrompt - the current system prompt
      返回:
      the (possibly transformed) system prompt
    • 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, …). Called once per call(), after merging across repositories and before the SkillBox is rebuilt.

      Default implementation returns raw unchanged.

      参数:
      raw - the merged, deduplicated skill list (low-to-high repository priority order)
      ctx - the per-call RuntimeContext; never null
      返回:
      the visible subset (must not be null; an empty list short-circuits the prompt update for this call)