AgentScope 是阿里巴巴通义实验室开源的企业级多智能体开发框架,核心理念是 “build and run agents you can see, understand and trust”(构建你看得见、听得懂、信得过的智能体)。
源码地址:https://github.com/agentscope-ai/agentscope-java
实践开源参考:
https://github.com/memglongdeqiangse/mini-claw
https://github.com/Stonewuu/ai-fusion-video
ReAct智能体使用
java代码示例
// 7. 构建 ReActAgent
ReActAgent.Builder agentBuilder = ReActAgent.builder()
.name(mainAgentName)
.sysPrompt(systemPrompt)
.model(model)
.maxIters(999)
.hooks(List.of(streamingHook));
if (toolkit != null) {
agentBuilder.toolkit(toolkit);
}
ReActAgent agent = agentBuilder.build();
// 13. 后台异步调用 Agent
// agent.call() 返回 Mono<Msg>,Hook 会在执行过程中推送事件
Disposable agentDisposable = agent.call(userMsg)
ReActAgent类参数:

以上代码有以下几个知识点:
一、toolkit 工具的调用
分二类tools,普通工具、子 Agent 工具
// 创建 Toolkit(启用并行执行)
Toolkit toolkit = new Toolkit(ToolkitConfig.builder()
.parallel(true) // 并行执行多工具
.executionConfig(ExecutionConfig.builder()
.timeout(Duration.ofMinutes(20))
.build())
.build());
// 注册普通工具(通过 AgentScopeToolAdapter 适配)
for (ToolExecutor tool : filteredTools) {
AgentScopeToolAdapter adapter = new AgentScopeToolAdapter(tool, toolExecContext, cancellationToken);
toolkit.registerAgentTool(adapter);
}
加载tools. --> filteredTools
注册tools-- >toolkit.registerAgentTool(adapter);
二、streamingHook 钩子函数
钩子(Hook)是 AgentScope 中的扩展点,相当于java中的切面编程,实现无侵入式扩展,允许开发者在特定位置自定义智能体行为,提供了一种灵活的方式来修改或扩展智能体的功能,而无需更改其核心实现。

三、systemPrompt系统消息、userMsg用户消息
消息类型:一般消息,textContent
// 11. 构建 Agent 输入
Msg userMsg = Msg.builder()
.role(MsgRole.USER)
.textContent(inputMessage)
.build();
多模态消息
| ImageBlock | 图像数据 |
| AudioBlock | 音频数据 |
| VideoBlock | 视频数据 |
四、记忆(略)
- 多种数据库,如 SQLite、PostgreSQL、MySQL 等
- 用户和会话管理

1258

被折叠的 条评论
为什么被折叠?



