G阿里云A原生应用AI井源开发者沙龙中国|上海站
Spring AlAlibaba Graph智能体开发指南与实践刘军2025/08
CONTENT01Agent开发模式Agant. Wondow.M-Ager1等主流智栏体开发模式目录02SpringAlAlibabaGraph如何使用5gring AlAibaba定义和编排Agert03分布式Agent04SpringAlAlibabaStudioPlatforAgart开发、调试、评估、部署平台
Part 1Agent开发模式
主流Agent开发模式简单LLM应用SingleAgentWorkflowMulti Agent
快速构建单智能体应用InLLMOutSingleAgentQuery/Read/Call/ResultsWriteResponseRetrievalMemoryTools最简单的智能体应用!同时也是最高级的智能体应用
在当前模型能力下单智能体架构的局限1.如果一个agent包含有太多的可用tools,模型会在决策工具选择时无所适从,效果变差2多轮执行下来、消息上下文会变得很大。消耗大量的token且影响模型当前专注度3模型上下文窗口有限4对手很多舞杂的任务,不止需要很多个光照,通常在某些环节还需要专业领域技能支持,比如科学计算、深入研究、写代码、绘画、任务规划等5单Agent在复杂仟条场号下的可维护性会变差
典型的workflow模式-ChainPassLLMCall 2LLMCall3OutOutput2LLMCall1GateOutput1ExitFail
典型的workflow模式-RoutingLLMCall1LLMCallLLMCall 2OutnRouterLLMCall3
典型的MultiAgent模式SingleAgentWetworkSupervisorSupervisorHierarchicalCustom(astools)->DD
Part 2使用Spring Al Alibaba Graph编排智能体
Spring AlAlibaba Agentic Framework架构图开发入口Spring AlAlibaba是一款灵活的、模块化的智能体低代码平台零代码CopllotAgentic APIAaent开发框架。SpringAlAlibabaSpringBootStarters(楼入Spring生态)让开发人员事容易创建、部署和编排从简单仟条到党AgenticFrameworkSDK染工作流的Agent智能体架构。RuntImeuman In LooStreamingContextMCOToolCallbackEvaluateTracingCbservabilityA2AugmentedLLMSpringAlModelPromptToolRAG
Agent基本定义ReactAgent agent=ReactAgent.builder().name("single_agent").model(chatModel).description("A simple agent that can answer questions.").build(;name(必须)智能体名称、在多agent场景下要求必须唯一(必须),模型s,使用SpvingAV底层原子抽象,模型商无)model description(可选),智能体所具备能力的描述总结,多agent场景下必填。
为Agent设置指令、工具、更多参数配置ReactAgent agent=ReactAgent.builder().name("single_agent").model(chatModeL).description("A simple agent that can write articles.").instruction("You are a helpful article witer assistant, pleasewite articlesofthe topics given byuser.").tools(List.of(DemoTool.getToolCallback())).chatOptions(DashScopeChatOptions.builder().withTemperature(0.7).build()).build(;Instruction(可选),类似Prompt,描述任务/目标、角色、行为、步骤、如何使用工具等于oTools(可选),标准的SpringAl工具,支持MCP,agent也可以作为工具·chatOotions(可选),控制底层模型行为的参数,包括temperature.topk等,古:headers
支持的Agent类型SpringAlAlibaba Graph支持的Agent类型:ReactAgent、工作流、多智能体、A2A远程智能体BaseAgentFlowAgentSequentialParallelLoopA2aRemoteReactAgentAgentAgentAgentAgent
不同Agent类型特性与适用场景ReactAgentFlowAgentMultiAgent核心特性推理、生成、工具使用控制多个智能体流程控制多个智能体流程流程编排无预先定义好的流程如传支持大模型决策的流程控串行、并行、回环等制、如LImRouting、Supervisor等确定性具有较高不确定性具有较高确定性无
WorkflowAgent-SequentialAgentquentialAgentsub_agents_1sub_agents,200OutputInputReactAgentwriterAgent=ReactAgent.builder().name("writer_agent").model(chatModeL).description("可以写文章。").instruction("你是一个知名的作家,擅长写作和创作。请根据用户的提问进行回答。").outputKey("article").build(;ReactAgentreviewerAgent=R...