agent - 属性配置对照表
2026年1月14日 下午5:07:16
1、内置智能体属性配置对照表
| 属性名 (Method in Builder) | SimpleAgent | ReActAgent | TeamAgent |
|---|---|---|---|
| name (名称) | ✅ | ✅ | ✅ |
| title (标题) | ✅ | ✅ | ✅ |
| description (描述) | ✅ | ✅ | ✅ |
| profile (画像) | ✅ | ✅ | ✅ |
| systemPrompt (系统提示词) | ✅ | ✅ | ✅ |
| chatModel (对话模型) | ✅ | ✅ | ✅ |
| chatOptions (对话参数配置) | ✅ | ✅ | ✅ |
| outputKey (结果回填上下文的键) | ✅ | ✅ | ✅ |
| retryConfig (重试配置) | ✅ | ✅ | ✅ |
| options (执行选项) | ✅ | ✅ | ✅ |
| defaultInterceptorAdd (拦截器) | ✅ | ✅ | ✅ |
| defaultToolsContextPut (工具上下文) | ✅ | ✅ | ❌ |
| outputSchema (结构化输出约束) | ✅ | ✅ | ❌ |
| toolAdd (工具) | ✅ | ✅ | ❌ |
| historyWindowSize (历史窗口大小) | ✅ | ✅ | ❌ |
| handler (自定义处理器) | ✅ | ❌ | ❌ |
| graphAdjuster (计算图微调) | ❌ | ✅ | ✅ |
| finishMarker (结束标识符) | ❌ | ✅ | ✅ |
| maxSteps (最大推理步数) | ❌ | ✅ | ❌ |
| maxTotalIterations (最大迭代轮次) | ❌ | ❌ | ✅ |
| protocol (协作协议,如 Swarm) | ❌ | ❌ | ✅ |
| agentAdd (成员智能体添加) | ❌ | ❌ | ✅ |
2、配置建议与说明
SimpleAgent (单次直连):侧重于“输入 -> 处理 -> 输出”的轻量逻辑。它是唯一支持 handler 的智能体,适合作为原子化的任务节点。
ReActAgent (推理增强):侧重于“思考 -> 行动 -> 观察”的循环。配置核心在于 toolAdd 配合 maxSteps,确保推理过程既能闭环又不会由于模型幻觉导致无限死循环。
TeamAgent (多机协作):侧重于“编排与分发”。它是唯一支持 protocol 和 agentAdd 的容器。它不直接管理工具,而是通过协议将任务路由给不同的 Agent 成员。
3、配置示例
表述自己:
SimpleAgent resumeAgent = SimpleAgent.of(chatModel)
.name("ResumeExtractor")
.description("简历信息提取器")
.systemPrompt(SimpleSystemPrompt.builder()
.role("你是一个专业的人事助理")
.instruction("请从用户提供的文本中提取关键信息")
.build())
.outputSchema(ResumeInfo.class)
.build();
用 outputSchema 指定输出架构,提取数据:
SimpleAgent resumeAgent = SimpleAgent.of(chatModel)
.systemPrompt(SimpleSystemPrompt.builder()
.role("你是一个专业的人事助理")
.instruction("请从用户提供的文本中提取关键信息")
.build())
.outputSchema(ResumeInfo.class)
.build();
String userInput = "你好,我是张三,今年 28 岁。我的邮箱是 zhangsan@example.com。我精通 Java, Solon 和 AI 开发。";
ResumeInfo resumeInfo = resumeAgent.prompt(userInput).call().toBean(ResumeInfo.class);
用 outputKey 传递成果:
TeamAgent team = TeamAgent.of(chatModel)
.name("template_team")
.agentAdd(ReActAgent.of(chatModel)
.name("translator")
.outputKey("translate_result")
.systemPrompt(ReActSystemPrompt.builder()
.role("翻译官")
.instruction("直接输出译文,不要任何前缀解释。").build())
.build())
.agentAdd(ReActAgent.of(chatModel)
.name("polisher")
.systemPrompt(ReActSystemPrompt.builder()
.role("润色专家")
.instruction("请对这段译文进行优化:#{translate_result}")
.build())
.outputKey("final_result")
.build())
.protocol(TeamProtocols.SEQUENTIAL)
.build();
team.prompt("人工智能正在改变世界").call();
使用执行选项 options 传递工具上下文:
McpClientProvider mcpClient = McpClientProvider.builder()
.channel(McpChannel.STREAMABLE)
.url("http://localhost:8080/mcp")
.build();
SimpleAgent agent = SimpleAgent.of(LlmUtil.getChatModel())
.toolAdd(mcpClient)
.build();
agent.prompt("杭州今天天气怎么样?")
.options(options -> options.toolsContextPut("TOKEN", "xxx"))
.call();