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
ehthumbs.db
Icon?
*.icon?
backend/src/main/resources/application-dev.yml
\ No newline at end of file
......@@ -309,7 +309,49 @@
</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>
<resources>
<resource>
<!-- 配置文件所在目录 -->
<directory>src/main/resources</directory>
<filtering>true</filtering> <!-- 关键:开启资源过滤 -->
<includes>
<include>**/*</include> <!-- 包含所有配置文件 -->
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
......@@ -322,6 +364,13 @@
</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Maven Compiler Plugin -->
......
......@@ -587,7 +587,8 @@ public class AgentChatService {
// 这里只需要等待足够的时间让异步的onComplete回调执行完成
try {
// 通过轮询检查是否已完成,最多等待5秒
long maxWaitTime = 5000;
// long maxWaitTime = 5000;
long maxWaitTime = 60000;
long startTime = System.currentTimeMillis();
while (!isCompleted.get() && (System.currentTimeMillis() - startTime) < maxWaitTime) {
Thread.sleep(100); // 每100ms检查一次
......
package pangea.hiagent.core;
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.context.ApplicationContext;
import org.springframework.stereotype.Service;
......@@ -28,6 +31,7 @@ public class AgentToolManager {
/**
* 获取Agent可用的工具列表
*
* @param agent Agent对象
* @return 工具列表
*/
......@@ -64,6 +68,7 @@ public class AgentToolManager {
/**
* 根据工具名称筛选工具
*
* @param allTools 所有工具
* @param toolNames 工具名称列表
* @return 筛选后的工具列表
......@@ -76,6 +81,7 @@ public class AgentToolManager {
/**
* 根据工具名称集合筛选工具实例(用于ReActService)
*
* @param allTools 所有工具实例
* @param toolNames 工具名称集合
* @return 筛选后的工具实例列表
......@@ -96,8 +102,7 @@ public class AgentToolManager {
// 检查类名是否匹配
boolean isMatch = toolNames.contains(className) ||
toolNames.stream().anyMatch(name ->
className.toLowerCase().contains(name.toLowerCase()));
toolNames.stream().anyMatch(name -> className.toLowerCase().contains(name.toLowerCase()));
if (isMatch) {
log.debug("工具 {} 匹配成功", className);
......@@ -113,6 +118,7 @@ public class AgentToolManager {
/**
* 构建工具描述文本
*
* @param tools 工具列表
* @return 工具描述文本
*/
......@@ -140,6 +146,7 @@ public class AgentToolManager {
/**
* 检查字符串是否有值
*
* @param value 字符串值
* @return 是否有值
*/
......@@ -149,6 +156,7 @@ public class AgentToolManager {
/**
* 根据Agent获取可用的工具实例
*
* @param agent Agent对象
* @return 工具实例列表
*/
......@@ -164,10 +172,19 @@ public class AgentToolManager {
Set<String> availableToolNames = availableTools.stream()
.map(Tool::getName)
.collect(Collectors.toSet());
for (String beanName : beanNames) {
Object bean = applicationContext.getBean(beanName);
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的类名是否与可用工具名称匹配
if (availableToolNames.contains(simpleClassName)) {
......
......@@ -22,7 +22,8 @@ spring:
sql:
init:
schema-locations: classpath:schema.sql
mode: always
mode: never
# mode: always
# JPA/Hibernate配置
jpa:
......
-- 插入默认数据
-- 插入默认用户数据
# INSERT INTO sys_user (id, username, password, email, nickname, status, role) VALUES
# ('user-001', 'admin', '$2a$10$N.zmdr9k7uOCQb0bta/OauRxaOKSr.QhqyD2R5FKvMQjmHoLkm5Sy', 'admin@hiagent.com', 'Admin', 'active', 'admin');
#
# -- 插入默认LLM配置数据
# INSERT INTO llm_config (id, name, description, provider, model_name, api_key, base_url, temperature, max_tokens, top_p, enabled, owner) VALUES
# ('deepseek-default', 'deepseek-default', 'DeepSeek默认配置', 'deepseek', 'deepseek-chat', '', 'https://api.deepseek.com', 0.7, 4096, 0.9, true, 'user-001'),
# ('openai-default', 'openai-default', 'OpenAI默认配置', 'openai', 'gpt-3.5-turbo', '', 'https://api.openai.com/v1', 0.7, 4096, 0.9, false, 'user-001'),
# ('ollama-default', 'ollama-default', 'Ollama默认配置', 'ollama', 'llama2', '', 'http://localhost:11434', 0.7, 4096, 0.9, true, 'user-001'),
# ('hisense-default', 'hisense-default', 'Hisense默认配置', 'hisense', 'gpt-4-1', '', 'http://openai-proxy-v2-jt-higpt.cloudprd.hisense.com', 0.7, 4096, 0.9, true, 'user-001');
#
# -- 插入默认Agent数据
# INSERT INTO agent (id, name, description, status, default_model, owner, system_prompt, enable_re_act, history_length, enable_rag, rag_collection_id, rag_top_k, rag_score_threshold, tools) VALUES
# ('agent-1', '客服助手', '处理客户咨询的AI助手', 'active', 'deepseek-default', 'user-001', '你是一个专业的客服助手,请用友好和专业的态度回答客户的问题。', 1, 15, 1, 'customer-service-kb', 5, 0.8, '["search", "orderQuery", "refundProcessing"]'),
# ('agent-2', '技术支持', '提供技术支持服务的AI助手', 'active', 'openai-default', 'user-001', '你是一个技术专家,请帮助用户解决技术问题。', 1, 15, 1, 'technical-support-kb', 5, 0.8, '["search", "calculator", "technicalDocumentationRetrieval", "technicalCodeExplanation"]'),
# ('agent-3', '数据分析员', '专业的数据分析AI助手', 'active', 'deepseek-default', 'user-001', '你是一个数据分析专家,擅长处理和分析各种数据。', 0, 15, 1, 'data-analysis-kb', 5, 0.8, '["calculator", "chartGeneration", "statisticalCalculation"]'),
# ('agent-4', '内容创作助手', '帮助撰写各类文案的AI助手', 'active', 'hisense-default', 'user-001', '你是一个创意写作专家,能够帮助用户创作各种类型的文案。', 0, 15, 1, 'content-creation-kb', 5, 0.8, '["search", "writingStyleReference", "documentTemplate"]'),
# ('agent-5', '学习导师', '个性化学习指导AI助手', 'active', 'hisense-default', 'user-001', '你是一个教育专家,能够根据用户需求提供个性化的学习建议。', 1, 15, 1, 'learning-mentor-kb', 5, 0.8, '["search", "studyPlanGeneration", "courseMaterialRetrieval"]');
INSERT INTO sys_user (id, username, password, email, nickname, status, role) VALUES
('user-001', 'admin', '$2a$10$N.zmdr9k7uOCQb0bta/OauRxaOKSr.QhqyD2R5FKvMQjmHoLkm5Sy', 'admin@hiagent.com', 'Admin', 'active', 'admin');
# -- 插入默认工具数据
# INSERT INTO tool (id, name, display_name, description, category, status, timeout, http_method) VALUES
# ('tool-1', 'search', '搜索工具', '进行网络搜索查询', 'API', 'active', 30000, 'GET'),
# ('tool-2', 'calculator', '计算器', '进行数学计算', 'FUNCTION', 'active', 5000, 'POST'),
# ('tool-3', 'weather', '天气查询', '查询天气信息', 'API', 'active', 10000, 'GET'),
# ('tool-4', 'get_current_time', '获取当前时间', '获取当前系统时间', 'FUNCTION', 'active', 1000, 'GET'),
# ('tool-5', 'technicalDocumentationRetrieval', '技术文档检索', '检索和查询技术文档内容', 'FUNCTION', 'active', 10000, 'GET'),
# ('tool-6', 'technicalCodeExplanation', '技术代码解释', '分析和解释技术代码的功能和实现逻辑', 'FUNCTION', 'active', 10000, 'GET'),
# ('tool-7', 'chartGeneration', '图表生成', '根据数据生成各种类型的图表', 'FUNCTION', 'active', 10000, 'GET'),
# ('tool-8', 'statisticalCalculation', '统计计算', '执行各种统计分析计算', 'FUNCTION', 'active', 10000, 'GET'),
# ('tool-9', 'writingStyleReference', '创作风格参考', '提供各种写作风格的参考和指导', 'FUNCTION', 'active', 10000, 'GET'),
# ('tool-10', 'documentTemplate', '文档模板', '提供各种类型的文档模板', 'FUNCTION', 'active', 10000, 'GET'),
# ('tool-11', 'studyPlanGeneration', '学习计划制定', '根据学习目标和时间安排制定个性化的学习计划', 'FUNCTION', 'active', 10000, 'GET'),
# ('tool-12', 'courseMaterialRetrieval', '课程资料检索', '检索和查询相关课程资料', 'FUNCTION', 'active', 10000, 'GET');
#
# -- 插入oauth2.0 服务商信息
# INSERT INTO oauth2_provider
# (id, provider_name, display_name, description, auth_type, authorize_url, token_url, userinfo_url, client_id, client_secret, redirect_uri, `scope`, enabled, config_json, created_at, updated_at, created_by, updated_by, deleted, remark)
# VALUES('hiagent', 'sso', 'sso', 'sso-provider', 'authorization_code', 'https://sso.hisense.com/esc-sso/oauth2.0/authorize', 'https://sso.hisense.com/esc-sso/oauth2.0/accessToken', 'https://sso.hisense.com/esc-sso/oauth2.0/profile', '', '', '', 'user', 1, '{}', '2025-12-17 17:26:57', '2025-12-17 17:27:48', '', '', 0, '');
-- 插入默认LLM配置数据
INSERT INTO llm_config (id, name, description, provider, model_name, api_key, base_url, temperature, max_tokens, top_p, enabled, owner) VALUES
('deepseek-default', 'deepseek-default', 'DeepSeek默认配置', 'deepseek', 'deepseek-chat', '', 'https://api.deepseek.com', 0.7, 4096, 0.9, true, 'user-001'),
('openai-default', 'openai-default', 'OpenAI默认配置', 'openai', 'gpt-3.5-turbo', '', 'https://api.openai.com/v1', 0.7, 4096, 0.9, false, 'user-001'),
('ollama-default', 'ollama-default', 'Ollama默认配置', 'ollama', 'llama2', '', 'http://localhost:11434', 0.7, 4096, 0.9, true, 'user-001'),
('hisense-default', 'hisense-default', 'Hisense默认配置', 'hisense', 'gpt-4-1', '', 'http://openai-proxy-v2-jt-higpt.cloudprd.hisense.com', 0.7, 4096, 0.9, true, 'user-001');
-- 插入默认Agent数据
INSERT INTO agent (id, name, description, status, default_model, owner, system_prompt, enable_re_act, history_length, enable_rag, rag_collection_id, rag_top_k, rag_score_threshold, tools) VALUES
('agent-1', '客服助手', '处理客户咨询的AI助手', 'active', 'deepseek-default', 'user-001', '你是一个专业的客服助手,请用友好和专业的态度回答客户的问题。', 1, 15, 1, 'customer-service-kb', 5, 0.8, '["search", "orderQuery", "refundProcessing","HisenseSsoAuthTool"]'),
('agent-2', '技术支持', '提供技术支持服务的AI助手', 'active', 'openai-default', 'user-001', '你是一个技术专家,请帮助用户解决技术问题。', 1, 15, 1, 'technical-support-kb', 5, 0.8, '["search", "calculator", "technicalDocumentationRetrieval", "technicalCodeExplanation"]'),
('agent-3', '数据分析员', '专业的数据分析AI助手', 'active', 'deepseek-default', 'user-001', '你是一个数据分析专家,擅长处理和分析各种数据。', 0, 15, 1, 'data-analysis-kb', 5, 0.8, '["calculator", "chartGeneration", "statisticalCalculation"]'),
('agent-4', '内容创作助手', '帮助撰写各类文案的AI助手', 'active', 'hisense-default', 'user-001', '你是一个创意写作专家,能够帮助用户创作各种类型的文案。', 0, 15, 1, 'content-creation-kb', 5, 0.8, '["search", "writingStyleReference", "documentTemplate"]'),
('agent-5', '学习导师', '个性化学习指导AI助手', 'active', 'hisense-default', 'user-001', '你是一个教育专家,能够根据用户需求提供个性化的学习建议。', 1, 15, 1, 'learning-mentor-kb', 5, 0.8, '["search", "studyPlanGeneration", "courseMaterialRetrieval"]');
-- 插入默认工具数据
INSERT INTO tool (id, name, display_name, description, category, status, timeout, http_method) VALUES
('tool-1', 'search', '搜索工具', '进行网络搜索查询', 'API', 'active', 30000, 'GET'),
('tool-2', 'calculator', '计算器', '进行数学计算', 'FUNCTION', 'active', 5000, 'POST'),
('tool-3', 'weather', '天气查询', '查询天气信息', 'API', 'active', 10000, 'GET'),
('tool-4', 'get_current_time', '获取当前时间', '获取当前系统时间', 'FUNCTION', 'active', 1000, 'GET'),
('tool-5', 'technicalDocumentationRetrieval', '技术文档检索', '检索和查询技术文档内容', 'FUNCTION', 'active', 10000, 'GET'),
('tool-6', 'technicalCodeExplanation', '技术代码解释', '分析和解释技术代码的功能和实现逻辑', 'FUNCTION', 'active', 10000, 'GET'),
('tool-7', 'chartGeneration', '图表生成', '根据数据生成各种类型的图表', 'FUNCTION', 'active', 10000, 'GET'),
('tool-8', 'statisticalCalculation', '统计计算', '执行各种统计分析计算', 'FUNCTION', 'active', 10000, 'GET'),
('tool-9', 'writingStyleReference', '创作风格参考', '提供各种写作风格的参考和指导', 'FUNCTION', 'active', 10000, 'GET'),
('tool-10', 'documentTemplate', '文档模板', '提供各种类型的文档模板', 'FUNCTION', 'active', 10000, 'GET'),
('tool-11', 'studyPlanGeneration', '学习计划制定', '根据学习目标和时间安排制定个性化的学习计划', 'FUNCTION', 'active', 10000, 'GET'),
('tool-12', 'courseMaterialRetrieval', '课程资料检索', '检索和查询相关课程资料', 'FUNCTION', 'active', 10000, 'GET');
-- 插入oauth2.0 服务商信息
INSERT INTO oauth2_provider
(id, provider_name, display_name, description, auth_type, authorize_url, token_url, userinfo_url, client_id, client_secret, redirect_uri, `scope`, enabled, config_json, created_at, updated_at, created_by, updated_by, deleted, remark)
VALUES('hiagent', 'sso', 'sso', 'sso-provider', 'authorization_code', 'https://sso.hisense.com/esc-sso/oauth2.0/authorize', 'https://sso.hisense.com/esc-sso/oauth2.0/accessToken', 'https://sso.hisense.com/esc-sso/oauth2.0/profile', '', '', '', 'user', 1, '{}', '2025-12-17 17:26:57', '2025-12-17 17:27:48', '', '', 0, '');
-- 插入HisenseSsoAuthTool
INSERT INTO `hiagent`.`tool`(`id`, `name`, `display_name`, `description`, `category`, `status`, `parameters`, `return_type`, `return_schema`, `implementation`, `timeout`, `api_endpoint`, `http_method`, `headers`, `auth_type`, `auth_config`, `owner`, `created_at`, `updated_at`, `created_by`, `updated_by`, `deleted`, `remark`) VALUES
('tool-13', 'HisenseSsoAuthTool', 'Hisense SSO 认证工具', '用于 Hisense SSO 认证的工具', 'FUNCTION', 'active', NULL, NULL, NULL, NULL, 10000, NULL, 'GET', NULL, NULL, NULL, 'user-001', '2025-12-19 08:55:26', '2025-12-19 09:14:54', NULL, NULL, 0, NULL);
\ No newline at end of file
#!/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