geqintan commited on
Commit
d460df0
·
1 Parent(s): e170d36
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  google-adk
2
  supabase
3
  litellm
 
 
1
  google-adk
2
  supabase
3
  litellm
4
+ python-dotenv
team_framework/team_quant_rows-20250514.sql ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ INSERT INTO "public"."team_quant" ("id", "model", "instruction", "tools", "description", "created_at", "name", "is_root", "sub_agents", "sort_id", "title", "global_instruction") VALUES ('497bb1fe-f22b-4dbb-8122-3470df8e665f', 'gemini-2.5-flash-preview-04-17', '你是AI金融量化研究员/分析师 (AI Quantitative Researcher/Analyst): 这是核心角色。负责:
2
+
3
+ - 开发和测试股票分析模型,例如价值投资模型、动量模型、技术分析模型等。
4
+ - 利用统计学、计量经济学等方法分析股票数据,发现投资机会。
5
+ - 对股票进行估值分析,评估其投资价值。
6
+ - 监控市场风险,提出风险控制建议。', null, 'AI金融量化研究员/分析师 (AI Quantitative Researcher/Analyst)', '2025-05-12 09:34:49.92523+00', 'ai_quant_researcher', 'false', null, '1', 'AI金融量化研究员', null), ('634f97af-516d-4d11-9113-b3ef82a9d04c', 'gemini-2.5-flash-preview-04-17', '你是AI金融量化开发工程师 (AI Quantitative Developer/Engineer):
7
+
8
+ 负责将研究成果转化为可执行的代码和系统。
9
+ 职责:
10
+ 将量化研究员开发的策略模型转化为程序代码实现。
11
+ 构建和维护策略回测平台。
12
+ 开发和维护自动化交易执行系统。
13
+ 处理和管理交易所需的数据(数据清洗、存储、获取)。
14
+ 负责交易系统的日常运行和维护。
15
+ 协助实现风险控制的技术逻辑。', null, 'AI金融量化开发工程师(AI Quantitative Developer/Engineer)', '2025-05-12 17:00:29.407603+00', 'ai_quant_developer', 'false', null, '4', 'AI金融量化开发工程师', null), ('825c4f17-0d49-4c3e-bf8b-a15b0183e73f', 'gemini-2.5-flash-preview-04-17', '你是AI金融量化交易员 (AI Quantitative Trader) 或 交易执行/监控专员:
16
+
17
+ 负责交易策略的实际执行、监控和管理。
18
+ 在自动化量化交易中,这个角色的职责通常包括:
19
+ 启动和监控自动化交易系统。
20
+ 管理交易头寸和资金分配。
21
+ 实时监控市场和系统运行状态。
22
+ 处理交易中的异常情况和错误。
23
+ 执行实时的风险控制措施。
24
+ 与研究员和开发工程师沟通系统表现和市场反馈。', null, 'AI金融量化交易员(AI Quantitative Trader)', '2025-05-12 16:57:25.300213+00', 'ai_quant_trader', 'false', null, '3', 'AI金融量化交易员', null), ('bba6efef-9db5-44c4-817b-df69f1b3a453', 'gemini-2.5-flash-preview-04-17', '你是AI金融量化数据科学家 (AI Data Scientist):
25
+
26
+ 专注于数据基础设施、数据处理和高级数据分析。
27
+ 职责:
28
+ 负责更复杂、更多样化数据源的收集、清洗、转换和管理(包括非结构化数据、另类数据等)。
29
+ 构建高效的数据管道和数据湖/仓库。
30
+ 应用机器学习、深度学习等高级统计和建模技术来发现数据中的模式和信号。
31
+ 支持量化研究员进行更深入的数据探索和特征工程。
32
+ 可能负责数据质量监控和数据治理。', null, 'AI金融量化数据科学家(AI Data Scientist)', '2025-05-11 12:37:23.847852+00', 'ai_data_scientist', 'false', null, '2', 'AI金融量化数据科学家', null), ('c78579d7-6fe5-4c73-860b-777ac202fc28', 'gemini-2.5-flash-preview-04-17', '你是AI金融量化交易团队的调度员(AI Dispatcher)
33
+ - 你的主要工作是调配好整个金融量化交易团队的分工协作
34
+ - 除了分配调度不要做其他具体工作
35
+ - 如果你的团队成员都无法进行的工作,你就委婉告诉用户说你无法解答', null, 'AI金融量化交易团队的调度员(AI Dispatcher)', '2025-05-10 09:58:58.341622+00', 'ai_dispatcher', 'true', '["ai_quant_researcher","ai_data_scientist","ai_quant_trader","ai_quant_developer"]', '99', 'AI金融量化调度员', 'AI金融量化交易团队有个响亮的名字:“AI金融量化梦之队”,你是该团队的成员,当agent回答时,请带上你的角色名,比如:我是xxx(角色名),当用户问起你是谁,你就说出你的角色名称,比如我是:量化研究员');
teams/base_team/agent.py CHANGED
@@ -11,9 +11,9 @@ def my_before_model_callback(callback_context, **kwargs):
11
  # 建议将敏感信息通过环境变量传递,而不是直接硬编码或从文件中读取
12
  # 这里为了演示,直接使用了从 .env 文件读取到的值
13
  # 在实际生产环境中,请确保通过安全的方式加载配置
14
- SUPABASE_URL = os.environ.get("SUPABASE_URL", "https://bbvyxjvleoizsipxydsm.supabase.co")
15
- SUPABASE_KEY = os.environ.get("SUPABASE_KEY", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJidnl4anZsZW9изsipxydsmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDQ1MzkwNjIsImV4cCI6MjA2MDExNTA2Mn0.cbUNhiCHXqIaW4leU_vGTKVI51gLVvsFOVWYS_vJrA4")
16
- DB_TABLE_NAME = os.environ.get("DB_TABLE_NAME", "team_quant")
17
 
18
  # 初始化 Supabase 客户端
19
  supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
 
11
  # 建议将敏感信息通过环境变量传递,而不是直接硬编码或从文件中读取
12
  # 这里为了演示,直接使用了从 .env 文件读取到的值
13
  # 在实际生产环境中,请确保通过安全的方式加载配置
14
+ SUPABASE_URL = os.environ.get("SUPABASE_URL")
15
+ SUPABASE_KEY = os.environ.get("SUPABASE_KEY")
16
+ DB_TABLE_NAME = os.environ.get("DB_TABLE_NAME")
17
 
18
  # 初始化 Supabase 客户端
19
  supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
teams/base_team/cache.py CHANGED
@@ -1,6 +1,9 @@
1
  import os
2
  from supabase import create_client, Client
3
  import time
 
 
 
4
 
5
  # Simple in-memory cache
6
  api_key_cache = {}
 
1
  import os
2
  from supabase import create_client, Client
3
  import time
4
+ from dotenv import load_dotenv
5
+
6
+ load_dotenv()
7
 
8
  # Simple in-memory cache
9
  api_key_cache = {}
teams/base_team/team_quant_rows.sql DELETED
@@ -1,3 +0,0 @@
1
- INSERT INTO "public"."team_quant" ("id", "model", "instruction", "tools", "description", "created_at", "name", "is_root", "sub_agents", "sort_id", "title", "global_instruction") VALUES ('bba6efef-9db5-44c4-817b-df69f1b3a453', 'gemini-2.0-pro-exp', '你是谷歌搜索专家,专门搜索和金融量化交易相关的信息。
2
- 仅执行搜索操作,不处理其他任务', '["searcher"]', '你是搜索专家,专门搜索和金融量化交易相关的信息', '2025-05-11 12:37:23.847852+00', 'searcher', 'false', null, '1', '金融量化信息检索专家', null), ('c78579d7-6fe5-4c73-860b-777ac202fc28', 'gemini-2.0-pro-exp', '你是量化交易团队的调度员。
3
- 将搜索任务委派给google_searcher', null, '量化交易团队的调度员', '2025-05-10 09:58:58.341622+00', 'dispatcher', 'true', '["searcher"]', null, '调度员', '量化交易团队成员');
 
 
 
 
test.py DELETED
@@ -1,5 +0,0 @@
1
- d=1
2
- a={"b":{"c":d}}
3
- print(a["b"]["c"])
4
- d=2
5
- print(a["b"]["c"])
 
 
 
 
 
 
utils.py.willdel DELETED
@@ -1,122 +0,0 @@
1
- from google.adk.agents import Agent
2
- from google.adk.agents.invocation_context import InvocationContext
3
- from google.adk.tools import google_search
4
- from supabase import create_client, Client
5
-
6
- import logging # 导入 logging 模块
7
- import os,json
8
-
9
- # 配置日志
10
- logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(name)s - %(message)s')
11
- logger = logging.getLogger(__name__)
12
-
13
- class Base_Agent(Agent):
14
- def __init__(self, agent_id: str):
15
- logger.info("Base_Agent __init__ started.")
16
-
17
- # 从环境变量加载 Supabase URL 和 Key
18
- url: str = os.environ.get("SUPABASE_URL")
19
- key: str = os.environ.get("SUPABASE_KEY") # 从环境变量获取 Supabase Key
20
-
21
- if not url or not key:
22
- logger.error("Supabase URL or Key not set in environment variables.")
23
- # 如果环境变量未设置,可以使用默认配置
24
- logger.warning("Supabase URL and Key not set. Using default agent configuration.")
25
- super().__init__(
26
- name="基础助手",
27
- model="gemini-2.0-flash-exp",
28
- instruction="执行基本指令",
29
- tools=[google_search],
30
- description="一个执行基本通用命令的基础助手"
31
- )
32
- logger.info("Base_Agent initialized with default configuration.")
33
- return # Exit __init__ if using default config
34
-
35
- logger.info("Supabase URL and Key loaded from environment variables.")
36
-
37
- # 创建 Supabase 客户端
38
- try:
39
- supabase: Client = create_client(url, key)
40
- logger.info("Supabase client created successfully.")
41
- except Exception as e:
42
- logger.error(f"Error creating Supabase client: {e}")
43
- # 如果创建客户端失败,使用默认配置
44
- logger.warning("Error creating Supabase client. Using default agent configuration.")
45
- super().__init__(
46
- name="基础助手",
47
- model="gemini-2.0-flash-exp",
48
- instruction="执行基本指令",
49
- tools=[google_search],
50
- description="一个执行基本通用命令的基础助手"
51
- )
52
- return # Exit __init__ if using default config
53
-
54
- # 从数据库加载 agent 配置信息
55
- try:
56
- logger.info(f"Attempting to load agent configuration from Supabase for id: {agent_id}")
57
- # 查询 airs_agents 表,获取对应的 agent 配置
58
- data, count = supabase.table('airs_agents').select('*').eq('id', agent_id).execute()
59
-
60
- if not data or not data[0]:
61
- logger.error(f"Agent configuration for id '{self.agent_id}' not found in Supabase table 'airs_agents'.")
62
- # 如果配置未找到,使用默认配置
63
- logger.warning("Agent configuration not found. Using default agent configuration.")
64
- super().__init__(
65
- name="基础助手",
66
- model="gemini-2.0-flash-exp",
67
- instruction="执行基本指令",
68
- tools=[google_search],
69
- description="一个执行基本通用命令的基础助手"
70
- )
71
- return # Exit __init__ if using default config
72
- print('\n\n\n\ndata',data)
73
- print('**************************')
74
- print('data[0]',data[0])
75
- print('data[1]',data[1])
76
- print('data[1][0]',data[1][0])
77
-
78
- config = data[1][0] # 假设查询结果是列表中的第一个字典
79
- logger.info("Agent configuration data fetched from Supabase. config: ",)
80
-
81
- # 解析 tools 字段(假设存储为 JSONB)
82
- tools_list = []
83
- if config.get("tools"):
84
- logger.info("Processing tools field.")
85
- try:
86
- stored_tools = json.loads(config["tools"]) if isinstance(config["tools"], str) else config["tools"]
87
- # 示例:如果存储的是工具名称列表,查找对应的工具对象
88
- available_tools = {"google_search": google_search} # 假设可用的工具映射
89
- tools_list = [available_tools.get(tool_name) for tool_name in stored_tools if available_tools.get(tool_name)]
90
- print('\n\n\n\ntools_list',tools_list)
91
- # logger.info(f"Tools processed: {[tool.__name__ for tool in tools_list if tool]}")
92
- except Exception as tool_e:
93
- logger.error(f"Error parsing or mapping tools: {tool_e}")
94
- # 如果解析或映射工具失败,可以使用默认工具或空列表
95
- tools_list = [google_search] # 默认使用 google_search
96
- logger.warning("Using default tool: google_search")
97
-
98
- # 使用从数据库获取的配置初始化 Base_Agent 实例自身
99
- print('\n\n\n\nconfig: ',config)
100
- super().__init__(
101
- name=config.get("name", "基础助手"),
102
- model=config.get("model", "gemini-2.0-flash-exp"),
103
- instruction=config.get("instruction", "执行基本指令"),
104
- tools=tools_list, # 使用从数据库加载并解析的工具列表
105
- description=config.get("description", "一个执行基本通用命令的基础助手")
106
- )
107
- logger.info("Base_Agent initialized successfully with Supabase configuration.")
108
-
109
- except Exception as e:
110
- logger.error(f"Error loading agent configuration from Supabase: {e}")
111
- # 如果从数据库加载失败,使用默认配置
112
- logger.warning("Error loading agent configuration from Supabase. Using default agent configuration.")
113
- super().__init__(
114
- name="基础助手",
115
- model="gemini-2.0-flash-exp",
116
- instruction="执行基本指令",
117
- tools=[google_search],
118
- description="一个执行基本通用命令的基础助手"
119
- )
120
-
121
- logger.info("Base_Agent __init__ finished.")
122
-