第3节:智能体配置表设计

首先我们需要安装对应的依赖父pom下

复制代码
  
              <dependency>
                  <groupId>com.google.adk</groupId>
                  <artifactId>google-adk</artifactId>
                  <version>0.4.0</version>
              </dependency>
  ​
              <dependency>
                  <groupId>com.google.adk</groupId>
                  <artifactId>google-adk-dev</artifactId>
                  <version>0.4.0</version>
              </dependency>
  ​
              <dependency>
                  <groupId>com.google.adk</groupId>
                  <artifactId>google-adk-spring-ai</artifactId>
                  <version>0.4.0</version>
              </dependency>
  ​
              <dependency>
                  <groupId>com.google.adk.samples</groupId>
                  <artifactId>google-adk-sample-helloworld</artifactId>
                  <version>0.4.0</version>
              </dependency>
  ​
              <dependency>
                  <groupId>com.google.adk</groupId>
                  <artifactId>google-adk-contrib-langchain4j</artifactId>
                  <version>0.2.0</version>
              </dependency>
  ​
  <!--            <dependency>-->
  <!--                <groupId>dev.langchain4j</groupId>-->
  <!--                <artifactId>langchain4j-core</artifactId>-->
  <!--                <version>1.4.0</version>-->
  <!--            </dependency>-->
  ​
  <!--            <dependency>-->
  <!--                <groupId>dev.langchain4j</groupId>-->
  <!--                <artifactId>langchain4j-open-ai</artifactId>-->
  <!--                <version>1.4.0</version>-->
  <!--            </dependency>-->
  ​
              <!-- spring ai 1.1.0 https://central.sonatype.com/artifact/org.springframework.ai/spring-ai-bom -->
              <dependency>
                  <groupId>org.springframework.ai</groupId>
                  <artifactId>spring-ai-bom</artifactId>
                  <version>1.1.0-M3</version>
                  <type>pom</type>
                  <scope>import</scope>
              </dependency>
  ​
              <!-- langchain4j https://mvnrepository.com/artifact/dev.langchain4j/langchain4j-bom -->
              <dependency>
                  <groupId>dev.langchain4j</groupId>
                  <artifactId>langchain4j-bom</artifactId>
                  <version>1.4.0</version>
                  <type>pom</type>
                  <scope>import</scope>
              </dependency>
  ​
              <!-- 设计模式框架 -->
              <dependency>
                  <groupId>cn.bugstack.wrench</groupId>
                  <artifactId>xfg-wrench-starter-design-framework</artifactId>
                  <version>3.0.0</version>
              </dependency>
  ​

app目录下

复制代码
  
          <!-- spring ai & google adk begin -->
  ​
          <dependency>
              <groupId>com.google.adk</groupId>
              <artifactId>google-adk</artifactId>
          </dependency>
  ​
          <dependency>
              <groupId>com.google.adk</groupId>
              <artifactId>google-adk-dev</artifactId>
          </dependency>
  ​
          <dependency>
              <groupId>com.google.adk.samples</groupId>
              <artifactId>google-adk-sample-helloworld</artifactId>
          </dependency>
  ​
          <dependency>
              <groupId>com.google.adk</groupId>
              <artifactId>google-adk-contrib-langchain4j</artifactId>
          </dependency>
  ​
          <dependency>
              <groupId>com.google.adk</groupId>
              <artifactId>google-adk-spring-ai</artifactId>
          </dependency>
  ​
          <dependency>
              <groupId>dev.langchain4j</groupId>
              <artifactId>langchain4j</artifactId>
          </dependency>
  ​
          <dependency>
              <groupId>dev.langchain4j</groupId>
              <artifactId>langchain4j-core</artifactId>
          </dependency>
  ​
          <dependency>
              <groupId>dev.langchain4j</groupId>
              <artifactId>langchain4j-open-ai</artifactId>
          </dependency>
  ​
          <dependency>
              <groupId>org.springframework.ai</groupId>
              <artifactId>spring-ai-openai</artifactId>
          </dependency>
  ​
          <dependency>
              <groupId>org.springframework.ai</groupId>
              <artifactId>spring-ai-starter-mcp-client-webflux</artifactId>
          </dependency>
  ​
          <!-- spring ai & google adk end -->

需求分析

以使用工程yml文件方式配置通用智能体配置表,允许用户在使用脚手架创建完智能体工程后,通过yml配置出自己需要的智能体,再结合业务场景做对应的开发和衔接

流程设计

  • 首先,一个智能体配置所需的最基本信息包括;应用名称、智能体描述、智能体模块,主要的组件类配置都在智能体模块下,AiApi 负责对接 AI 接口,ChatModel 负责模型创建(也会把 AiApi 对接),之后还要创建出 MCP 工具。

  • 之后就是对于单一智能体的创建,这里可以按顺序创建出很多智能体,之后到AgentWorkflow 中进行编排,构造出一个完整的智能体

功能实现

对象设计

复制代码
  
  @Data
  public class AiAgentConfigTableVO {
  ​
      /**
       * 应用名称
       */
      private String appName;
  ​
      /**
       * 智能体列表
       */
      private Agent agent;
  ​
  ​
  ​
      @Data
      public static class Agent{
  ​
          /**
           * 智能体ID
           */
          private String agentId;
  ​
          /**
           * 智能体名称
           */
          private String agentName;
  ​
          /**
           * 智能体描述
           */
          private String agentDesc;
      }
  ​
      @Data
      public static class Module{
  ​
          private AiApi aiApi;
  ​
          @Data
          public static class AiApi{
  ​
              private String baseUrl;
              private String apiKey;
              private String completionsPath = "/v1/chat/completions";
              private String embeddingsPath = "/v1/embeddings";
          }
  ​
          @Data
          public static class ChatModel{
  ​
              private String model;
              private List<ToolMcp> toolMcpList;
  ​
              @Data
              public static class ToolMcp{
  ​
                  private SSEServerParameters sse;
  ​
                  private StdioServerParameters stdio;
  ​
                  @Data
                  public static class SSEServerParameters {
                      private String name;
                      private String baseUri;
                      private String sseEndpoint;
                      private Integer requestTimeout = 3000;
  ​
                  }
  ​
                  @Data
                  public static class StdioServerParameters {
                      private String name;
                      private Integer requestTimeout = 3000;
                      private ServerParameters serverParameters;
  ​
                      @Data
                      public static class ServerParameters {
                          private String command;
                          private List<String> args;
                          private Map<String, String> env;
  ​
                      }
                  }
              }
  ​
              @Data
              public static class Agent {
                  private String name;
                  private String instruction;
                  private String description;
                  private String outputKey;
  ​
              }
  ​
              @Data
              public static class AgentWorkflow {
                  /**
                   * 类型;loop、parallel、sequential
                   */
                  private String type;
                  private String name;
                  private List<String> subAgents;
                  private String description;
                  private Integer maxIterations = 3;
  ​
              }
          }
      }
  }

配置yml

复制代码
  
  spring:
    config:
      import:
  #      - classpath:agent/test_agent_02.yml
        - classpath:agent/test_agent.yml
  ​

配置类加载

复制代码
  
  @Slf4j
  @Configuration
  @EnableConfigurationProperties(AiAgentAutoConfigProperties.class)
  public class AiAgentAutoConfig implements ApplicationListener<ApplicationReadyEvent> {
  ​
      @Resource
      private AiAgentAutoConfigProperties aiAgentAutoConfigProperties;
  ​
      @Override
      public void onApplicationEvent(ApplicationReadyEvent event) {
          try {
              log.info("😊Ai Agent 智能体装配 {}", JSON.toJSONString(aiAgentAutoConfigProperties.getTables().values()));
          } catch (Exception e) {
              throw new RuntimeException(e);
          }
      }
  }
  ​

@EnableConfigurationProperties(xxx.class):是开启配置自动绑定

  • ApplicationListener监听器,

  • <ApplicationReadyEvent>监听「SpringBoot 完全启动成功」这件事 ,

  • onApplicationEvent()当项目启动完成 → 自动调用这个方法

相关推荐
土星云SaturnCloud31 分钟前
边缘计算 + AI 视频存管一体机:快递末端网点分拣提效与安全管控实战方案
服务器·人工智能·ai·边缘计算
起个名字费劲死了34 分钟前
VisionMaster集成深度学习算法(基础狗)
人工智能·深度学习·算法
制造业的搬运工34 分钟前
车载 PCB 打样周期与选型指南:从 IATF 16949 到 IPC-6012 的 5 个硬指标
大数据·网络·人工智能·制造·pcb工艺
55873 生态系统35 分钟前
55873 正和博弈经济模型:重构数字时代商业价值体系
大数据·人工智能·重构·全域文明操作系统·55873 操作系统·55873全域文明生态体系
adinnet202637 分钟前
多轮对话与上下文压缩:追问时模型怎么记住前面说的
数据库·microsoft
法狗狗技术团队1 小时前
2026年标书审查工具测评:AI标书检查软件怎么选?
人工智能·招投标·投标·标书检查·标书审查·标书制作·投标全流程
“AI国潮设计-小江”1 小时前
【SDXL实战】用AI生成“财神爷蛋糕×英歌舞人物”潮汕国潮甜品IP,附Prompt与批量生成思路
开发语言·人工智能·python·aigc
Bode_20021 小时前
企业数智孪生构建方法
人工智能·智能制造
jqpwxt1 小时前
启点创新科技景区私有化票务管理系统:智慧景区数字化建设核心服务商,以本地部署筑牢景区数字化安全与稳定底座
大数据·人工智能·科技·云计算·旅游
skywalk81631 小时前
Deepseek harness的4种模式 配置文件内容
linux·人工智能·ubuntu·deepseek·harness