尧图建网站 尧图建网站 YAOTU WEB BUILD 免费咨询
ARTICLE DETAIL

资讯详情

深耕网站建设与建站编程的一线实战洞察。

开源了!AgentMesh —— 一个让多 Agent 智能协作的 Java 框架

开源了!AgentMesh —— 一个让多 Agent 智能协作的 Java 框架 开源了AgentMesh —— 一个让多 Agent 智能协作的 Java 框架不止于 Tool Calling而是让多个 Agent 智能路由、并行协作、容错转移。GitHubhttps://github.com/XSerein666/AgentMesh为什么又造一个轮子用 Spring AI、LangChain4j 做单 Agent Tool Calling 很爽但一旦涉及多 Agent 协作问题就来了用户问帮我规划北京三日游——该找哪个 Agent天气旅行攻略酒店预订某个 Agent 挂了怎么办直接报错给用户多个 Agent 并行执行结果怎么汇总市面上的框架要么不支持多 Agent 编排要么路由靠硬编码规则要么没有故障转移。于是就有了 AgentMesh。AgentMesh 是什么一个Java 生态的多 Agent 智能协作框架构建在 Spring Boot 3.3.5 JDK 21 之上提供从 Agent 注册、智能路由、编排执行到可观测性的完整链路。核心功能1. 智能路由 —— 自动选择最合适的 Agent两阶段 LLM 路由策略先用关键词快速粗筛候选 Agent再让 LLM 精排打分选出最优解。支持 A/B 测试对比效果LRU TTL 缓存降低延迟低置信度时自动回退到关键词路由。agentmesh:routing:strategy:llm# keyword | llm | abllm:top-k:5confidence-threshold:0.6timeout:5scache:enabled:truemax-size:100ttl:300s2. 故障转移Failover—— Agent 挂了自动切换标记 Agent 为retryable超时TimeoutException、连接失败ConnectException、5xx 错误自动切换到备用 Agent。流式响应中途失败不触发重试避免重复执行。AgentConfig.builder().agentId(primary-agent).retryable(true)// 启用 failover.build();3. 多 Agent 编排 —— 顺序、并行、条件三种编排模式覆盖不同场景// 顺序编排Agent1 → Agent2 → Agent3newSequentialAgentOrchestrator(factory,agentClient);// 并行编排多个 Agent 同时执行结果汇总newParallelOrchestrator(factory,agentClient,metrics);// 条件路由 failoverLLM 选最优 Agent失败自动切换newConditionalOrchestrator(factory,agentClient,routingStrategy);4. A2A 协议Agent-to-Agent支持 AgentCard、AgentSkill、Task、Chat、SSE 流式响应让不同 Agent 之间通过标准协议通信和协作。5. 远程工具发现自动从远程 Agent 拉取工具列表Skills注册到本地 ToolRegistry无需手动配置跨 Agent 的工具调用。6. 四家 LLM 适配一套接口多模型切换模型适配器阿里云百炼DashScopeDashScopeAdapterOpenAIOpenAiAdapterOllama本地部署OllamaAdapterDeepSeekDeepSeekAdapter7. ReAct 推理引擎基于 LLM Function Calling 的 Thought → Action → Observation 推理循环支持多轮工具调用和结果收敛。8. 可观测性所有指标自动注册到 Micrometer对接 Prometheus Grafana指标说明agentmesh.agent.invocationsAgent 调用次数agentmesh.agent.latencyAgent 延迟 P50/P95/P99agentmesh.tool.executions工具执行次数agentmesh.llm.callsLLM 调用次数agentmesh.llm.tokensToken 消耗agentmesh.routing.cache路由缓存命中率agentmesh.routing.ab.consistencyA/B 测试一致率9. 记忆与规划Memory Planning短期记忆滑动窗口保留最近消息 LLM 摘要压缩长期记忆LLM 提取记忆信息 向量存储任务规划LLM 分解复杂任务为子任务 DAG按依赖关系执行10. 会话与任务管理会话管理内存和 JDBC 两种实现支持多轮对话上下文任务管理异步任务提交与轮询乐观锁防并发冲突和同类框架对比能力Spring AILangChain4jAgentScopeAgentMesh多 Agent 编排基础实验性基础顺序/并行/条件智能路由❌❌❌两阶段 LLM A/BFailover❌❌❌异常类型判断自动切换路由缓存❌❌❌LRU TTL SHA-256A2A 协议❌❌✅✅远程工具发现❌❌❌自动拉取注册可观测性基础需自建基础P50/P95/P99 traceId记忆与规划❌❌❌短期长期记忆 DAG 规划模块结构agentmesh/ ├── agentmesh-bom/ # 版本管理Bill of Materials ├── agentmesh-core/ # 核心框架 │ ├── agent/ # Agent 定义与编排引擎 │ ├── routing/ # 路由策略关键词/LLM/A/B │ ├── llm/ # LLM 客户端与适配器 │ ├── tool/ # 工具抽象与注册中心 │ ├── remote/ # 远程 Agent 调用与工具发现 │ ├── protocol/ # A2A 协议AgentCard/Task/SSE │ ├── registry/ # Agent 注册中心 │ ├── infrastructure/ # 可观测性指标/traceId │ ├── session/ # 会话管理 │ ├── task/ # 任务管理 │ ├── memory/ # 短期/长期记忆 │ ├── planning/ # 任务规划 │ └── prompt/ # Prompt 模板引擎 ├── agentmesh-rag/ # RAG 知识库模块Beta └── agentmesh-examples/ # 示例项目快速开始环境要求JDK 21Maven 3.91. 添加依赖dependencyManagementdependenciesdependencygroupIdio.github.xserein666/groupIdartifactIdagentmesh-bom/artifactIdversion1.0.0/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagementdependenciesdependencygroupIdio.github.xserein666/groupIdartifactIdagentmesh-core/artifactId/dependency/dependencies2. 配置dashscope:api-key:${DASHSCOPE_API_KEY}# 阿里云百炼 API Keyagentmesh:registry:self:agent-id:my-agentname:我的智能助手description:一个支持天气查询和知识检索的 Agentversion:1.0.0url:http://localhost:8080routing:strategy:keyword# keyword | llm | ab3. 定义 Agent 和工具ConfigurationpublicclassAgentConfig{BeanpublicToolweatherTool(){returnTool.of(weather,查询指定城市的天气,input-{Stringcity(String)input.get(city);returnMap.of(result,city晴25°C);});}BeanpublicAgentConfigmyAgent(){returnAgentConfig.builder().agentId(weather-agent).description(天气查询助手可以查询全国各城市的天气).systemPrompt(你是一个专业的天气助手请根据用户需求查询天气。).routingTags(List.of(天气,温度,降雨)).retryable(true).build();}}4. 运行 Demogitclone https://github.com/XSerein666/AgentMesh.gitcdAgentMesh/agentmesh-examples/agentmesh-demosetDASHSCOPE_API_KEYsk-your-key mvn spring-boot:run访问http://localhost:8080/chat?msg北京今天天气怎么样开源地址GitHubhttps://github.com/XSerein666/AgentMeshLicenseApache 2.0欢迎 Star、Issue、PR—如果你在做多 Agent 相关的项目或者对智能路由、故障转移感兴趣欢迎来试试。如果觉得有用赏个 Star 就是最大的鼓励。
返回列表