Solon v4.1.0

agent - 属性配置对照表

</> markdown
2026年6月11日 下午12:55:58

1、内置智能体属性配置对照表

属性名 (Method in Builder)SimpleAgentReActAgentTeamAgent
name (名称)✅✅✅
title (标题)✅✅✅
role (角色)✅✅✅
profile (画像)✅✅✅
instruction (指令)✅✅✅
chatModel (对话模型)✅✅✅
defaultOptions (默认选项)✅✅✅
outputKey (结果回填上下文的键)✅✅✅
retryConfig (重试配置)✅✅✅
maxRetries (最大任务重试次数)✅✅✅
defaultInterceptorAdd (添加拦截器)✅✅✅
defaultTalentAdd (添加才能)✅✅✅
defaultToolAdd (添加工具)✅✅✅
defaultToolContextPut (工具上下文)✅✅✅
outputSchema (结构化输出约束)✅✅❌
sessionWindowSize (会话窗口大小)✅✅❌
handler (自定义处理器)✅❌❌
finishMarker (结束标识符)❌✅✅
maxTurns (最大迭代轮次)❌✅✅
graphAdjuster (计算图微调)❌❌✅
protocol (协作协议,如 Swarm)❌❌✅
agentAdd (成员智能体添加)❌❌✅
recordWindowSize (协作记录窗口大小)❌❌✅

2、配置建议与说明

SimpleAgent (单次直连):侧重于 输入 -> 处理 -> 输出 的轻量逻辑。它是唯一支持 handler 的智能体,适合作为原子化的任务节点。

ReActAgent (推理增强):侧重于 思考 -> 行动 -> 观察 的循环。配置核心在于 toolAdd 配合 maxTurns,确保推理过程既能闭环又不会由于模型幻觉导致无限死循环。

TeamAgent (多机协作):侧重于 编排与分发。它是唯一支持 protocol 和 agentAdd 的容器。它不直接管理工具,而是通过协议将任务路由给不同的 Agent 成员。

3、配置示例

表述自己:

SimpleAgent resumeAgent = SimpleAgent.of(chatModel)
                .name("ResumeExtractor")
                .role("简历信息提取器")
                .instruction("请从用户提供的文本中提取关键信息")
                .outputSchema(ResumeInfo.class)
                .build();

用 outputSchema 指定输出架构,提取数据:

SimpleAgent resumeAgent = SimpleAgent.of(chatModel)
        .role("你是一个专业的人事助理")
        .instruction("请从用户提供的文本中提取关键信息")
        .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")
                .role("翻译团队")
                .agentAdd(ReActAgent.of(chatModel)
                        .name("translator")
                        .outputKey("translate_result")
                        .role("翻译官")
                        .instruction("直接输出译文,不要任何前缀解释。")
                        .build())
                .agentAdd(ReActAgent.of(chatModel)
                        .name("polisher")
                        .role("润色专家")
                        .instruction("请对这段译文进行优化:#{translate_result}")
                        .outputKey("final_result")
                        .build())
                .protocol(TeamProtocols.SEQUENTIAL)
                .build();
                
team.prompt("人工智能正在改变世界").call();

使用 MCP,以及执行选项 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(o -> o.toolContextPut("TOKEN", "xxx"))
        .call();