生成代码工程
This commit is contained in:
parent
4c9251a62f
commit
cdb5b10dd8
90
README.md
90
README.md
|
|
@ -1,81 +1,39 @@
|
|||
# 多智能体协同系统 C++ 工程
|
||||
# Demo Project
|
||||
|
||||
这是一个基于 C++17 和 CMake 的多智能体协同系统骨架工程,实现了核心的调度引擎和智能体管理功能。
|
||||
一个简洁的 Spring Boot 3 + Java 17 单体后端工程。
|
||||
|
||||
## 项目结构
|
||||
## 技术栈
|
||||
|
||||
```
|
||||
├── CMakeLists.txt # CMake 构建配置文件
|
||||
├── README.md # 项目说明文档
|
||||
├── include/ # 头文件目录
|
||||
│ └── app.hpp # 应用程序主要头文件
|
||||
├── src/ # 源文件目录
|
||||
│ ├── main.cpp # 程序入口点
|
||||
│ └── app.cpp # 应用程序实现
|
||||
└── tests/ # 测试文件目录
|
||||
└── basic_test.cpp # 基础测试
|
||||
```
|
||||
- Java 17
|
||||
- Spring Boot 3.2.5
|
||||
- Maven
|
||||
- Knife4j + OpenAPI 3 (Swagger)
|
||||
|
||||
## 核心功能模块
|
||||
## 启动方式
|
||||
|
||||
### 1. 智能体管理
|
||||
- Agent 类的定义和管理
|
||||
- 智能体注册、注销和发现
|
||||
- 智能体元数据管理
|
||||
|
||||
### 2. 执行流引擎
|
||||
- 执行流节点定义
|
||||
- DAG(有向无环图)解析和执行
|
||||
- 串行和并行执行支持
|
||||
|
||||
### 3. 上下文管理
|
||||
- 全局上下文和节点局部上下文
|
||||
- 上下文数据传递和持久化
|
||||
|
||||
### 4. 任务调度
|
||||
- 任务队列管理
|
||||
- 任务状态跟踪
|
||||
- 异常重试机制
|
||||
|
||||
## 编译与运行
|
||||
|
||||
### 编译项目
|
||||
```bash
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake --build .
|
||||
mvn spring-boot:run
|
||||
```
|
||||
|
||||
### 运行主程序
|
||||
或打包后运行:
|
||||
|
||||
```bash
|
||||
./bin/multi_agent_system
|
||||
mvn package -DskipTests
|
||||
java -jar target/demo-1.0.0.jar
|
||||
```
|
||||
|
||||
### 运行测试
|
||||
```bash
|
||||
./bin/basic_test
|
||||
# 或使用 CMake 测试
|
||||
ctest
|
||||
```
|
||||
## 接口文档
|
||||
|
||||
## 依赖项
|
||||
启动后访问:
|
||||
|
||||
- C++17 或更高版本
|
||||
- CMake 3.15 或更高版本
|
||||
- 标准 C++ 库
|
||||
- Knife4j UI: http://localhost:8080/doc.html
|
||||
- Swagger JSON: http://localhost:8080/v3/api-docs
|
||||
|
||||
## 后续扩展方向
|
||||
## 接口列表
|
||||
|
||||
1. 添加 HTTP 客户端支持智能体通信
|
||||
2. 实现 JSON Schema 验证
|
||||
3. 添加数据库连接支持(MySQL、MongoDB)
|
||||
4. 实现 JWT 认证和 RBAC 权限控制
|
||||
5. 添加 SSE(Server-Sent Events)流式输出支持
|
||||
6. 容器化部署配置
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 当前为骨架实现,包含核心数据结构和基础功能
|
||||
- 实际生产环境需要添加网络通信、数据库持久化等模块
|
||||
- 建议结合前端图形化编排器使用
|
||||
| 方法 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| GET | /api/health | 健康检查 |
|
||||
| GET | /api/business/items | 获取所有业务数据 |
|
||||
| GET | /api/business/items/{id} | 根据ID获取业务数据 |
|
||||
| POST | /api/business/items | 新增业务数据 |
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.5</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>demo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>demo</name>
|
||||
<description>Demo Spring Boot Project</description>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<knife4j.version>4.5.0</knife4j.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Knife4j + Swagger -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
<version>${knife4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.example.demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.example.demo.config;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Contact;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class OpenApiConfig {
|
||||
|
||||
@Bean
|
||||
public OpenAPI customOpenAPI() {
|
||||
return new OpenAPI()
|
||||
.info(new Info()
|
||||
.title("Demo API")
|
||||
.version("1.0.0")
|
||||
.description("Spring Boot 3 Demo 工程接口文档")
|
||||
.contact(new Contact()
|
||||
.name("开发者")
|
||||
.email("dev@example.com")));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.example.demo.controller;
|
||||
|
||||
import com.example.demo.model.BusinessItem;
|
||||
import com.example.demo.service.BusinessService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "业务管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/business")
|
||||
public class BusinessController {
|
||||
|
||||
private final BusinessService businessService;
|
||||
|
||||
public BusinessController(BusinessService businessService) {
|
||||
this.businessService = businessService;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有业务数据")
|
||||
@GetMapping("/items")
|
||||
public List<BusinessItem> getAllItems() {
|
||||
return businessService.findAll();
|
||||
}
|
||||
|
||||
@Operation(summary = "根据ID获取业务数据")
|
||||
@GetMapping("/items/{id}")
|
||||
public ResponseEntity<BusinessItem> getItemById(
|
||||
@Parameter(description = "业务ID") @PathVariable Long id) {
|
||||
return businessService.findById(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@Operation(summary = "新增业务数据")
|
||||
@PostMapping("/items")
|
||||
public ResponseEntity<BusinessItem> createItem(@RequestBody BusinessItem item) {
|
||||
BusinessItem saved = businessService.save(item);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(saved);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.example.demo.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
@Tag(name = "健康检查")
|
||||
@RestController
|
||||
@RequestMapping("/api/health")
|
||||
public class HealthController {
|
||||
|
||||
@Operation(summary = "健康检查", description = "返回服务运行状态")
|
||||
@GetMapping
|
||||
public Map<String, Object> health() {
|
||||
return Map.of(
|
||||
"status", "UP",
|
||||
"timestamp", LocalDateTime.now().toString()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.example.demo.model;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 业务数据模型
|
||||
*/
|
||||
@Schema(description = "业务数据项")
|
||||
public class BusinessItem {
|
||||
|
||||
@Schema(description = "唯一标识", example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名称", example = "示例项目")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "描述", example = "这是一个示例描述")
|
||||
private String description;
|
||||
|
||||
public BusinessItem() {
|
||||
}
|
||||
|
||||
public BusinessItem(Long id, String name, String description) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package com.example.demo.service;
|
||||
|
||||
import com.example.demo.model.BusinessItem;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* 业务服务 - 基于内存假数据,后续可替换为数据库实现
|
||||
*/
|
||||
@Service
|
||||
public class BusinessService {
|
||||
|
||||
private final Map<Long, BusinessItem> store = new ConcurrentHashMap<>();
|
||||
private final AtomicLong idGenerator = new AtomicLong(1);
|
||||
|
||||
public BusinessService() {
|
||||
// 初始化假数据
|
||||
initMockData();
|
||||
}
|
||||
|
||||
private void initMockData() {
|
||||
save(new BusinessItem(null, "项目Alpha", "Alpha项目描述"));
|
||||
save(new BusinessItem(null, "项目Beta", "Beta项目描述"));
|
||||
save(new BusinessItem(null, "项目Gamma", "Gamma项目描述"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有业务数据
|
||||
*/
|
||||
public List<BusinessItem> findAll() {
|
||||
return new ArrayList<>(store.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取业务数据
|
||||
*/
|
||||
public Optional<BusinessItem> findById(Long id) {
|
||||
return Optional.ofNullable(store.get(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增业务数据
|
||||
*/
|
||||
public BusinessItem save(BusinessItem item) {
|
||||
if (item.getId() == null) {
|
||||
item.setId(idGenerator.getAndIncrement());
|
||||
}
|
||||
store.put(item.getId(), item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
server:
|
||||
port: 8080
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: demo
|
||||
|
||||
# Knife4j 配置
|
||||
knife4j:
|
||||
enable: true
|
||||
setting:
|
||||
language: zh-CN
|
||||
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
path: /swagger-ui.html
|
||||
api-docs:
|
||||
path: /v3/api-docs
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.example.demo;
|
||||
|
||||
import com.example.demo.model.BusinessItem;
|
||||
import com.example.demo.service.BusinessService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* BusinessService 单元测试
|
||||
*/
|
||||
public class BusinessServiceTest {
|
||||
|
||||
private BusinessService businessService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
businessService = new BusinessService();
|
||||
}
|
||||
|
||||
@Test
|
||||
void findAll_shouldReturnInitialMockData() {
|
||||
List<BusinessItem> items = businessService.findAll();
|
||||
assertEquals(3, items.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void findById_shouldReturnItemWhenExists() {
|
||||
Optional<BusinessItem> result = businessService.findById(1L);
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals("项目Alpha", result.get().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void findById_shouldReturnEmptyWhenNotExists() {
|
||||
Optional<BusinessItem> result = businessService.findById(999L);
|
||||
assertFalse(result.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void save_shouldAssignIdAndStoreItem() {
|
||||
BusinessItem newItem = new BusinessItem(null, "新项目", "新项目描述");
|
||||
BusinessItem saved = businessService.save(newItem);
|
||||
|
||||
assertNotNull(saved.getId());
|
||||
assertEquals("新项目", saved.getName());
|
||||
|
||||
Optional<BusinessItem> found = businessService.findById(saved.getId());
|
||||
assertTrue(found.isPresent());
|
||||
assertEquals("新项目描述", found.get().getDescription());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue