Skip to content

fix(example): Inconsistent groupManager in ReActAgent.Builder#build due to toolkit copying#560

Merged
AlbumenJ merged 3 commits intoagentscope-ai:mainfrom
fishl3j:fix_tool_group_example
Jan 16, 2026
Merged

fix(example): Inconsistent groupManager in ReActAgent.Builder#build due to toolkit copying#560
AlbumenJ merged 3 commits intoagentscope-ai:mainfrom
fishl3j:fix_tool_group_example

Conversation

@fishl3j
Copy link
Contributor

@fishl3j fishl3j commented Jan 14, 2026

During ReActAgent.Builder#build, the toolkit is copied to prevent state interference. However, this leads to a mismatch in groupManager instances under certain conditions:

  • If registerMetaTool() is called on the original toolkit, the meta tool holds a reference to the original toolkit's groupManager.
  • After copying, the new toolkit's schemaProvider uses the copied toolkit's groupManager.
  • As a result, the groupManager used for tool group activation differs from the one used in schema generation, causing inconsistency.
    Fix:
  • Remove direct calls to registerMetaTool() on the original toolkit.
  • Instead, use Builder.enableMetaTool(true) to register the meta tool during build time on the copied toolkit.
  • This ensures both the meta tool and the schemaProvider use the same groupManager instance.

@fishl3j fishl3j requested a review from a team January 14, 2026 09:33
@cla-assistant
Copy link

cla-assistant bot commented Jan 14, 2026

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

问题描述:
- ReActAgent.Builder#build 时会复制 toolkit 以避免状态干扰
- 如果在原始 toolkit 上调用 registerMetaTool(),meta tool 会使用原始 toolkit 的 groupManager
- 但复制后的 toolkit 的 schemaProvider 使用的是新 toolkit 的 groupManager
- 导致 toolGroup 激活操作的 groupManager 与 tool scheme 生成的 groupManager 不一致

修复方案:
- 移除在原始 toolkit 上直接调用 registerMetaTool() 的方式
- 改为通过 Builder.enableMetaTool(true) 在 build 时在复制的 toolkit 上注册 meta tool
- 确保 meta tool 和 schemaProvider 使用同一个 groupManager 实例

修改文件:
- ToolGroupExample.java: 移除 toolkit.registerMetaTool() 调用,改用 .enableMetaTool(true)
@fishl3j fishl3j force-pushed the fix_tool_group_example branch from 69b2731 to ff30d64 Compare January 14, 2026 09:52
@AlbumenJ
Copy link
Collaborator

Please translate title and description into English

@fishl3j fishl3j changed the title fix: 修复 ReActAgent.Builder#build 时 toolkit 复制导致的 groupManager 不一致问题 fix: Inconsistent groupManager in ReActAgent.Builder#build due to toolkit copying Jan 15, 2026
@AlbumenJ AlbumenJ changed the title fix: Inconsistent groupManager in ReActAgent.Builder#build due to toolkit copying fix(example): Inconsistent groupManager in ReActAgent.Builder#build due to toolkit copying Jan 16, 2026
@AlbumenJ AlbumenJ merged commit e39a44d into agentscope-ai:main Jan 16, 2026
5 checks passed
Alexxigang pushed a commit to Alexxigang/agentscope-java that referenced this pull request Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants