马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Spring AI Alibaba 项目目次结构阐明
项目概述
Spring AI Alibaba 是一个多模块 Maven 项目,接纳分层架构计划,从底层到上层依次为:Graph 焦点运行时、Agent 框架、Studio 应用和 Spring Boot Starters。项目遵照模块化计划原则,每个模块都有明确的职责边界。
目次结构阐明
第一层模块
项目根目次下包罗以下重要模块:- spring-ai-alibaba/
- ├── spring-ai-alibaba-bom/ # BOM 模块
- ├── spring-ai-alibaba-graph-core/ # Graph 核心运行时
- ├── spring-ai-alibaba-agent-framework/ # Agent 框架
- ├── spring-ai-alibaba-studio/ # Studio 应用
- ├── spring-boot-starters/ # Spring Boot Starters
- │ ├── spring-ai-alibaba-starter-a2a-nacos/
- │ └── spring-ai-alibaba-starter-config-nacos/
- ├── tools/ # 工具目录
- └── docs/ # 文档目录
复制代码 模块详细阐明
1. spring-ai-alibaba-bom
职责:Bill of Materials (BOM) 模块,同一管理全部 Spring AI Alibaba 模块的依靠版本。
关键特性:
- 提供依靠版本管理
- 简化子模块的依靠设置
- 确保版本同等性
使用方式:- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>com.alibaba.cloud.ai</groupId>
- <artifactId>spring-ai-alibaba-bom</artifactId>
- <version>1.1.0.0-M4</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
复制代码 2. spring-ai-alibaba-graph-core
职责:Graph 焦点运行时,提供底层的工作流和多 Agent 编排框架。这是整个框架的根本层,提供状态图、节点、边等焦点抽象。
关键入口点:
- StateGraph:状态图界说类,用于构建工作流图
- public class StateGraph {
- /**
- * Constant representing the END of the graph.
- */
- public static final String END = "__END__";
- /**
- * Constant representing the START of the graph.
- */
- public static final String START = "__START__";
- /**
- * Constant representing the ERROR of the graph.
- */
- public static final String ERROR = "__ERROR__";
- /**
- * Constant representing the NODE_BEFORE of the graph.
- */
- public static final String NODE_BEFORE = "__NODE_BEFORE__";
复制代码 - GraphRunner:图实验引擎,负责实验编译后的图
- public class GraphRunner {
- private final CompiledGraph compiledGraph;
- private final RunnableConfig config;
- private final AtomicReference<Object> resultValue = new AtomicReference<>();
- // Handler for main execution flow - demonstrates encapsulation
- private final MainGraphExecutor mainGraphExecutor;
- public GraphRunner(CompiledGraph compiledGraph, RunnableConfig config) {
- this.compiledGraph = compiledGraph;
- this.config = config;
- // Initialize the main execution handler - demonstrates encapsulation
- this.mainGraphExecutor = new MainGraphExecutor();
- }
- public Flux<GraphResponse<NodeOutput>> run(OverAllState initialState) {
复制代码 - CompiledGraph:编译后的可实验图
- OverAllState:全局状态对象,用于在节点间转达数据
焦点概念:
- Node:工作流中的节点,封装特定操纵或模子调用
- Edge:节点间的边,表现状态转换
- OverAllState:全局状态,携带整个流程的共享数据
3. spring-ai-alibaba-agent-framework
职责:Agent 框架,基于 Graph 焦点运行时构建的高级 Agent 开发框架。提供 ReactAgent、SequentialAgent、ParallelAgent 等预构建的 Agent 范例,简化 Agent 开发。
关键入口点:
<ul>ReactAgent:焦点 Agent 范例,实现 ReAct(Reasoning + Acting)范式
[code]public class ReactAgent extends BaseAgent { private static final int DEFAULT_MAX_ITERATIONS = 10; private final AgentLlmNode llmNode; private final AgentToolNode toolNode; private CompiledGraph compiledGraph; private List hooks; private List modelInterceptors; private List toolInterceptors; private int maxIterations; private int iterations = 0; private String instruction; private Function shouldContinueFunc; public ReactAgent(AgentLlmNode llmNode, AgentToolNode toolNode, CompileConfig compileConfig, Builder builder) throws GraphStateException { super(builder.name, builder.description, builder.includeContents, builder.returnReasoningContents, builder.outputKey, builder.outputKeyStrategy); this.instruction = builder.instruction; this.llmNode = llmNode; this.toolNode = toolNode; this.compileConfig = compileConfig; this.shouldContinueFunc = builder.shouldContinueFunc; this.hooks = builder.hooks; this.modelInterceptors = builder.modelInterceptors; this.toolInterceptors = builder.toolInterceptors; this.includeContents = builder.includeContents; this.inputSchema = builder.inputSchema; this.inputType = builder.inputType; this.outputSchema = builder.outputSchema; this.outputType = builder.outputType; this.maxIterations = builder.maxIterations |