Skip to content

[BUG] 渐进式工具 Tool 披露在外部动态维护一个Map失效的问题 #4929

Open

Description

@Prometheusxiao

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

因为我的skill是需要进行自我进化升级,可能存储今天用tool1,明天用tool2,后天用tool3的情况,不断升级迭代,就需要对当前skill进行动态挂在工具。
我自己实现了一个数据库版的SkillRegistry,并在内部维护了一个用于在创建SkillsAgentHook挂载到groupedTools
public static final Map<String, List<ToolCallback>> GROUPED_TOOLS = new ConcurrentHashMap<>();
而这个GROUPED_TOOLS 会在SkillRegistry调用Optional<SkillMetadata> get(String name)或 Optional<SkillMetadata> getByPath(String skillPath)动态加载当前技能的工具,但是这是无效的,后来我发现在创建SkillsAgentHook的时候如果挂载的是一个空的groupedTools就导致interceptorBuilder不配置groupedTools(源码143行)
@Override public List<ModelInterceptor> getModelInterceptors() { SkillsInterceptor.Builder interceptorBuilder = SkillsInterceptor.builder().skillRegistry(this.skillRegistry); if (!this.groupedTools.isEmpty()) { interceptorBuilder.groupedTools(this.groupedTools); } if (this.toolCallbackResolver != null) { interceptorBuilder.toolCallbackResolver(this.toolCallbackResolver); } return List.of(interceptorBuilder.build()); }

Expected Behavior

interceptorBuilder.groupedTools时不要检查传入的this.groupedTools.isEmpty

Steps To Reproduce

1.自己定义Map<String, List> GROUPED_TOOLS = new ConcurrentHashMap<>()。
2.然后将这个空的GROUPED_TOOLS 挂载到SkillsAgentHook。
3.创建ReactAgent注入刚才的SkillsAgentHook。
4.向GROUPED_TOOLS 注入工具。
5.调用刚才ReactAgent,会发现工具无法使用。

Environment

Spring AI Alibaba version(s):

Debug logs

No response

Anything else?

No response

Activity

  1. Anon2Tokyo commented on Aug 26, 2026

    @Anon2Tokyo

    Hello, I'm very interested in this issue and would like to try to resolve it.

  2. oss-sentinel-ai commented on Aug 27, 2026

    @oss-sentinel-ai

    Issue Evaluation

    Category: kind/bug | Area: area/agent-framework | Status: Confirmed ✅

    The issue is verified against the current codebase.

    Root Cause: In SkillsAgentHook.getModelInterceptors(), the isEmpty() guard prevents an initially-empty groupedTools map from being passed to SkillsInterceptor.Builder:

    if (!this.groupedTools.isEmpty()) {
        interceptorBuilder.groupedTools(this.groupedTools);
    }

    When the user passes a ConcurrentHashMap that is empty at construction time and populates it later, the interceptor never receives the map reference because the check fails at the first call.

    Workaround (available now): Use groupedToolsSupplier() instead of groupedTools() in the builder. The supplier is invoked lazily on each call and is designed for dynamic tool registration:

    SkillsAgentHook hook = SkillsAgentHook.builder()
        .skillRegistry(registry)
        .groupedToolsSupplier(() -> myDynamicMap)
        .build();

    Suggested fix: Remove the isEmpty() guard so that the map reference is always passed. Since the map is shared by reference, later mutations will be visible to the interceptor regardless.

    Severity: Low-Medium — the groupedToolsSupplier API already covers this use case, but the isEmpty() guard is a footgun for users who pass a mutable map directly.


    Automated evaluation by github-manager

  3. Prometheusxiao commented on Aug 27, 2026

    @Prometheusxiao
    Author

    我注意到了你们最新代码提供了supplier的方式,非常感谢你们!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions