Commit 5daacfc6 authored by 王舵's avatar 王舵

feature: 调整如下

- 增加启动 profile 区分环境
- fix: AgentToolManager中如果Tool 类是代理类则不能被 spring ai 正确识别,所以将传入 spring ai 中的Tool 类都降级为原始类
- 调整了data.sql, 默认启动不执行 scheam.sql
parent 53570949
...@@ -209,3 +209,4 @@ Thumbs.db ...@@ -209,3 +209,4 @@ Thumbs.db
ehthumbs.db ehthumbs.db
Icon? Icon?
*.icon? *.icon?
backend/src/main/resources/application-dev.yml
\ No newline at end of file
...@@ -309,7 +309,49 @@ ...@@ -309,7 +309,49 @@
</dependencies> </dependencies>
<profiles>
<!-- 开发环境(默认激活) -->
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault> <!-- 默认激活dev -->
</activation>
<properties>
<!-- 定义环境标识,对应配置文件后缀 -->
<spring.profiles.active>dev</spring.profiles.active>
</properties>
</profile>
<!-- 测试环境 -->
<profile>
<id>test</id>
<properties>
<spring.profiles.active>test</spring.profiles.active>
</properties>
</profile>
<!-- 生产环境 -->
<profile>
<id>prod</id>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
</profile>
</profiles>
<build> <build>
<resources>
<resource>
<!-- 配置文件所在目录 -->
<directory>src/main/resources</directory>
<filtering>true</filtering> <!-- 关键:开启资源过滤 -->
<includes>
<include>**/*</include> <!-- 包含所有配置文件 -->
</includes>
</resource>
</resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -322,6 +364,13 @@ ...@@ -322,6 +364,13 @@
</exclude> </exclude>
</excludes> </excludes>
</configuration> </configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin> </plugin>
<!-- Maven Compiler Plugin --> <!-- Maven Compiler Plugin -->
......
...@@ -587,7 +587,8 @@ public class AgentChatService { ...@@ -587,7 +587,8 @@ public class AgentChatService {
// 这里只需要等待足够的时间让异步的onComplete回调执行完成 // 这里只需要等待足够的时间让异步的onComplete回调执行完成
try { try {
// 通过轮询检查是否已完成,最多等待5秒 // 通过轮询检查是否已完成,最多等待5秒
long maxWaitTime = 5000; // long maxWaitTime = 5000;
long maxWaitTime = 60000;
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
while (!isCompleted.get() && (System.currentTimeMillis() - startTime) < maxWaitTime) { while (!isCompleted.get() && (System.currentTimeMillis() - startTime) < maxWaitTime) {
Thread.sleep(100); // 每100ms检查一次 Thread.sleep(100); // 每100ms检查一次
......
package pangea.hiagent.core; package pangea.hiagent.core;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -28,6 +31,7 @@ public class AgentToolManager { ...@@ -28,6 +31,7 @@ public class AgentToolManager {
/** /**
* 获取Agent可用的工具列表 * 获取Agent可用的工具列表
*
* @param agent Agent对象 * @param agent Agent对象
* @return 工具列表 * @return 工具列表
*/ */
...@@ -64,6 +68,7 @@ public class AgentToolManager { ...@@ -64,6 +68,7 @@ public class AgentToolManager {
/** /**
* 根据工具名称筛选工具 * 根据工具名称筛选工具
*
* @param allTools 所有工具 * @param allTools 所有工具
* @param toolNames 工具名称列表 * @param toolNames 工具名称列表
* @return 筛选后的工具列表 * @return 筛选后的工具列表
...@@ -76,6 +81,7 @@ public class AgentToolManager { ...@@ -76,6 +81,7 @@ public class AgentToolManager {
/** /**
* 根据工具名称集合筛选工具实例(用于ReActService) * 根据工具名称集合筛选工具实例(用于ReActService)
*
* @param allTools 所有工具实例 * @param allTools 所有工具实例
* @param toolNames 工具名称集合 * @param toolNames 工具名称集合
* @return 筛选后的工具实例列表 * @return 筛选后的工具实例列表
...@@ -96,8 +102,7 @@ public class AgentToolManager { ...@@ -96,8 +102,7 @@ public class AgentToolManager {
// 检查类名是否匹配 // 检查类名是否匹配
boolean isMatch = toolNames.contains(className) || boolean isMatch = toolNames.contains(className) ||
toolNames.stream().anyMatch(name -> toolNames.stream().anyMatch(name -> className.toLowerCase().contains(name.toLowerCase()));
className.toLowerCase().contains(name.toLowerCase()));
if (isMatch) { if (isMatch) {
log.debug("工具 {} 匹配成功", className); log.debug("工具 {} 匹配成功", className);
...@@ -113,6 +118,7 @@ public class AgentToolManager { ...@@ -113,6 +118,7 @@ public class AgentToolManager {
/** /**
* 构建工具描述文本 * 构建工具描述文本
*
* @param tools 工具列表 * @param tools 工具列表
* @return 工具描述文本 * @return 工具描述文本
*/ */
...@@ -140,6 +146,7 @@ public class AgentToolManager { ...@@ -140,6 +146,7 @@ public class AgentToolManager {
/** /**
* 检查字符串是否有值 * 检查字符串是否有值
*
* @param value 字符串值 * @param value 字符串值
* @return 是否有值 * @return 是否有值
*/ */
...@@ -149,6 +156,7 @@ public class AgentToolManager { ...@@ -149,6 +156,7 @@ public class AgentToolManager {
/** /**
* 根据Agent获取可用的工具实例 * 根据Agent获取可用的工具实例
*
* @param agent Agent对象 * @param agent Agent对象
* @return 工具实例列表 * @return 工具实例列表
*/ */
...@@ -164,10 +172,19 @@ public class AgentToolManager { ...@@ -164,10 +172,19 @@ public class AgentToolManager {
Set<String> availableToolNames = availableTools.stream() Set<String> availableToolNames = availableTools.stream()
.map(Tool::getName) .map(Tool::getName)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
for (String beanName : beanNames) { for (String beanName : beanNames) {
Object bean = applicationContext.getBean(beanName); Object bean = applicationContext.getBean(beanName);
String simpleClassName = bean.getClass().getSimpleName(); String simpleClassName = bean.getClass().getSimpleName();
// 判断是否是代理类,如果是代理类,获取目标类
if (AopUtils.isAopProxy(bean)) {
log.debug("beanName: {} 是代理类,尝试获取目标类", beanName);
try {
bean = ((Advised) bean).getTargetSource().getTarget();
simpleClassName = bean.getClass().getSimpleName();
} catch (Exception e) {
e.printStackTrace();
}
}
// 检查bean的类名是否与可用工具名称匹配 // 检查bean的类名是否与可用工具名称匹配
if (availableToolNames.contains(simpleClassName)) { if (availableToolNames.contains(simpleClassName)) {
......
...@@ -22,7 +22,8 @@ spring: ...@@ -22,7 +22,8 @@ spring:
sql: sql:
init: init:
schema-locations: classpath:schema.sql schema-locations: classpath:schema.sql
mode: always mode: never
# mode: always
# JPA/Hibernate配置 # JPA/Hibernate配置
jpa: jpa:
......
This diff is collapsed.
#!/bin/bash
###
# @Date: 2025-12-19 08:44:46
# @LastEditors: wangduo3 wangduo3@hisense.com
# @LastEditTime: 2025-12-19 14:39:27
# @FilePath: /pangea-agent/run-backend-with-env.sh
###
# 提取参数
ENV_PROFILE=$1
# 拼接启动命令(注意双引号保留参数格式,避免空格/特殊字符问题)
RUN_CMD="mvn spring-boot:run -P${ENV_PROFILE} -Dspring-boot.run.arguments=--spring.profiles.active=${ENV_PROFILE}"
cd backend
# 打印并执行命令
echo "执行启动命令:$RUN_CMD"
eval $RUN_CMD
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment