geqintan commited on
Commit
57e6e1c
·
1 Parent(s): d681c4e
__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ print('\n\n\n\n\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&')
ai_quant_agent.txt ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {'after_agent_callback': None,
2
+ 'after_model_callback': None,
3
+ 'after_tool_callback': None,
4
+ 'before_agent_callback': None,
5
+ 'before_model_callback': <function my_before_model_callback at 0x10e18ba60>,
6
+ 'before_tool_callback': None,
7
+ 'code_executor': None,
8
+ 'description': 'Agent to answer questions about the time and weather in a '
9
+ 'city.',
10
+ 'disallow_transfer_to_parent': False,
11
+ 'disallow_transfer_to_peers': False,
12
+ 'examples': None,
13
+ 'generate_content_config': None,
14
+ 'global_instruction': '',
15
+ 'include_contents': 'default',
16
+ 'input_schema': None,
17
+ 'instruction': 'You are a helpful agent who can answer user questions about '
18
+ 'the time and weather in a city.\n'
19
+ "Before you answer, you should say your name: 'I am "
20
+ "weather_time_agent'",
21
+ 'model': 'gemini-2.5-flash-preview-04-17',
22
+ 'name': 'weather_time_agent',
23
+ 'output_key': None,
24
+ 'output_schema': None,
25
+ 'parent_agent': None,
26
+ 'planner': None,
27
+ 'sub_agents': [LlmAgent(name='greeting_agent', description='Handles simple greetings and hellos', parent_agent=None, sub_agents=[], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are the Greeting Agent. Your ONLY task is to provide a friendly greeting to the user. \nDo not engage in any other conversation or tasks.\nBefore you answer, you should say your name: 'I am greeting_agent'", global_instruction='', tools=[], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=None, after_model_callback=None, before_tool_callback=None, after_tool_callback=None),
28
+ LlmAgent(name='farewell_agent', description='Handles simple farewells and goodbyes', parent_agent=None, sub_agents=[], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are the Farewell Agent. Your ONLY task is to provide a polite goodbye message.\nIf not about goodbye, just transfer to weather_time_agent.\nDo not perform any other actions.\nBefore you answer, you should say your name: 'I am farewell_agent'", global_instruction='', tools=[], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=None, after_model_callback=None, before_tool_callback=None, after_tool_callback=None)],
29
+ 'tools': [<function get_weather at 0x10e35b380>,
30
+ <function get_current_time at 0x10e18bce0>]}
{teams → bak}/get_weather/.env.example RENAMED
File without changes
{teams → bak}/get_weather/__init__.py RENAMED
@@ -1,2 +1 @@
1
  from . import agent
2
- from . import load_tools
 
1
  from . import agent
 
{teams → bak}/get_weather/agent.py RENAMED
@@ -1,52 +1,40 @@
1
  ### adk web ./teams
2
-
3
- # load tools from teams_tools,tools 的保存方法 tools['name']=tool
4
- from get_weather.load_tools import load_tools_from_db
5
- from get_weather.load_agents import load_agents_from_db
6
- from get_weather.cache import get_api_key # Import get_api_key
7
  from google.adk.agents import Agent
8
- from google.adk.models.lite_llm import LiteLlm
 
 
 
9
  import os
10
 
11
- tools = load_tools_from_db()
12
-
13
- # def my_before_model_callback(agent, model_input, callback_context, **kwargs):
14
  def my_before_model_callback(callback_context, **kwargs):
15
  os.environ["GOOGLE_API_KEY"] = get_api_key() # 直接设置环境变量
16
-
17
- # load not_root_agent from teams_agents
18
- agents = load_agents_from_db()
19
- for i in range(len(agents)):
20
- agents[i].before_model_callback = my_before_model_callback
21
 
22
  greeting_agent = Agent(
23
  name="greeting_agent",
24
- model="gemini-2.0-flash-exp",
25
  instruction="You are the Greeting Agent. Your ONLY task is to provide a friendly greeting to the user. "
26
  "Do not engage in any other conversation or tasks."
27
  "before you answer, you should say your name: 'I am greeting_agent'",
28
- # Crucial for delegation: Clear description of capability
29
  description="Handles simple greetings and hellos",
30
- before_model_callback=my_before_model_callback # Add the callback here
31
- )
32
 
33
  farewell_agent = Agent(
34
- name="farewell_agent",
35
- model="gemini-2.0-flash-exp",
36
-
37
  instruction="You are the Farewell Agent. Your ONLY task is to provide a polite goodbye message. "
38
  "If not about goodbye, just transfer to weather_time_agent"
39
  "Do not perform any other actions."
40
- "before you answer, you should say your name: 'I am farewell_agent'",
41
- # Crucial for delegation: Clear description of capability
42
  description="Handles simple farewells and goodbyes",
43
- before_model_callback=my_before_model_callback # Add the callback here
44
  )
45
 
46
- # load root_agent from teams_agents
47
- root_agent = Agent(
48
  name="weather_time_agent",
49
- model="gemini-2.0-flash-exp",
50
  description=(
51
  "Agent to answer questions about the time and weather in a city."
52
  ),
@@ -54,8 +42,12 @@ root_agent = Agent(
54
  "You are a helpful agent who can answer user questions about the time and weather in a city."
55
  "before you answer, you should say your name: 'I am weather_time_agent'"
56
  ),
57
- tools=[tools['get_weather'],tools['get_current_time']],
58
- # sub_agents=[greeting_agent, farewell_agent],
59
- sub_agents=agents,
60
- before_model_callback=my_before_model_callback # Add the callback here
61
  )
 
 
 
 
 
1
  ### adk web ./teams
 
 
 
 
 
2
  from google.adk.agents import Agent
3
+ from .tools.get_current_time import get_current_time
4
+ from .tools.get_weather import get_weather
5
+ from .cache import get_api_key
6
+ # from .team import init_team, get_team
7
  import os
8
 
 
 
 
9
  def my_before_model_callback(callback_context, **kwargs):
10
  os.environ["GOOGLE_API_KEY"] = get_api_key() # 直接设置环境变量
11
+ print('888888888888888888888888888888888888888888888')
 
 
 
 
12
 
13
  greeting_agent = Agent(
14
  name="greeting_agent",
15
+ model="gemini-2.5-flash-preview-04-17",
16
  instruction="You are the Greeting Agent. Your ONLY task is to provide a friendly greeting to the user. "
17
  "Do not engage in any other conversation or tasks."
18
  "before you answer, you should say your name: 'I am greeting_agent'",
 
19
  description="Handles simple greetings and hellos",
20
+ before_model_callback=my_before_model_callback
21
+ )
22
 
23
  farewell_agent = Agent(
24
+ name="farewell_agent",
25
+ model="gemini-2.5-flash-preview-04-17",
 
26
  instruction="You are the Farewell Agent. Your ONLY task is to provide a polite goodbye message. "
27
  "If not about goodbye, just transfer to weather_time_agent"
28
  "Do not perform any other actions."
29
+ "before you answer, you should say your name: 'I am farewell_agent'",
30
+ before_model_callback=my_before_model_callback,
31
  description="Handles simple farewells and goodbyes",
 
32
  )
33
 
34
+ print("\n\n\n\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\nroot_agent init")
35
+ root_agent=Agent(
36
  name="weather_time_agent",
37
+ model="gemini-2.5-flash-preview-04-17",
38
  description=(
39
  "Agent to answer questions about the time and weather in a city."
40
  ),
 
42
  "You are a helpful agent who can answer user questions about the time and weather in a city."
43
  "before you answer, you should say your name: 'I am weather_time_agent'"
44
  ),
45
+ # global_instruction = '请在每一句回答里都加上:“我的主人”',
46
+ tools=[get_weather, get_current_time],
47
+ sub_agents=[greeting_agent, farewell_agent],
48
+ before_model_callback=my_before_model_callback
49
  )
50
+
51
+ import pprint
52
+ print('\n\n\n\n*************************************\n\nroot_agent dict: \n')
53
+ pprint.pprint(root_agent.__dict__) # 尝试打印对象的字典表示
{teams → bak}/get_weather/cache.py RENAMED
File without changes
{teams → bak}/get_weather/readme.md RENAMED
File without changes
bak/get_weather/team.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys, os
2
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')))
3
+ from team_framework.load_team_config import load_team_config
4
+ from team_framework.load_tools import load_tools
5
+ from team_framework.load_agents import load_agents, load_root_agent
6
+ from google.adk.agents import Agent
7
+
8
+ _team = {}
9
+
10
+ def init_team():
11
+ global _team
12
+ _team= {}
13
+ _team_config = load_team_config()
14
+ print('\n\n\n\n\n***************************\n_team_config')
15
+ print(_team_config)
16
+ _team["tools"] = load_tools(_team_config['tools'])
17
+ _team["agents"] = load_agents(_team_config['agents'])
18
+
19
+ _team["root_agent"] = load_root_agent(_team_config['root_agent'])
20
+ _team["root_agent"].tools = [] ## 为 root_agent 添加工具
21
+ for item in _team_config['root_agent']['tools']:
22
+ # print('\n\n\n\n|||||||||||||||||| item',item)
23
+ _team["root_agent"].tools.append(_team['tools'][item])
24
+ _team["root_agent"].sub_agents=[]
25
+ for item in _team_config['root_agent']['sub_agents']:
26
+ print('\n\n\n\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| \nitem',item)
27
+ print(_team['agents'][item])
28
+ _team["root_agent"].sub_agents.append(_team['agents'][item])
29
+ # _team["root_agent"].agents.append(_team['agents'][item])
30
+
31
+ def get_team():
32
+ global _team
33
+ return _team
teams/get_weather/load_tools.py → bak/get_weather/tool.py.copy RENAMED
File without changes
{teams → bak/get_weather/tools}/__init__.py RENAMED
File without changes
{teams → bak}/get_weather/tools/get_current_time.py RENAMED
File without changes
{teams → bak}/get_weather/tools/get_weather.py RENAMED
File without changes
get_weather_agent.txt ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {'after_agent_callback': None,
2
+ 'after_model_callback': None,
3
+ 'after_tool_callback': None,
4
+ 'before_agent_callback': None,
5
+ 'before_model_callback': <function my_before_model_callback at 0x1169d5e40>,
6
+ 'before_tool_callback': None,
7
+ 'code_executor': None,
8
+ 'description': 'Agent to answer questions about the time and weather in a '
9
+ 'city.',
10
+ 'disallow_transfer_to_parent': False,
11
+ 'disallow_transfer_to_peers': False,
12
+ 'examples': None,
13
+ 'generate_content_config': None,
14
+ 'global_instruction': '',
15
+ 'include_contents': 'default',
16
+ 'input_schema': None,
17
+ 'instruction': 'You are a helpful agent who can answer user questions about '
18
+ 'the time and weather in a city.before you answer, you should '
19
+ "say your name: 'I am weather_time_agent'",
20
+ 'model': 'gemini-2.5-flash-preview-04-17',
21
+ 'name': 'weather_time_agent',
22
+ 'output_key': None,
23
+ 'output_schema': None,
24
+ 'parent_agent': None,
25
+ 'planner': None,
26
+ 'sub_agents': [LlmAgent(name='greeting_agent', description='Handles simple greetings and hellos', parent_agent=LlmAgent(name='weather_time_agent', description='Agent to answer questions about the time and weather in a city.', parent_agent=None, sub_agents=[LlmAgent(name='greeting_agent', description='Handles simple greetings and hellos', parent_agent=LlmAgent(name='weather_time_agent', description='Agent to answer questions about the time and weather in a city.', parent_agent=None, sub_agents=[...], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are a helpful agent who can answer user questions about the time and weather in a city.before you answer, you should say your name: 'I am weather_time_agent'", global_instruction='', tools=[<function get_weather at 0x116afd300>, <function get_current_time at 0x116afd080>], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None), sub_agents=[], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are the Greeting Agent. Your ONLY task is to provide a friendly greeting to the user. Do not engage in any other conversation or tasks.before you answer, you should say your name: 'I am greeting_agent'", global_instruction='', tools=[], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None), LlmAgent(name='farewell_agent', description='Handles simple farewells and goodbyes', parent_agent=LlmAgent(name='weather_time_agent', description='Agent to answer questions about the time and weather in a city.', parent_agent=None, sub_agents=[...], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are a helpful agent who can answer user questions about the time and weather in a city.before you answer, you should say your name: 'I am weather_time_agent'", global_instruction='', tools=[<function get_weather at 0x116afd300>, <function get_current_time at 0x116afd080>], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None), sub_agents=[], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are the Farewell Agent. Your ONLY task is to provide a polite goodbye message. If not about goodbye, just transfer to weather_time_agentDo not perform any other actions.before you answer, you should say your name: 'I am farewell_agent'", global_instruction='', tools=[], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None)], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are a helpful agent who can answer user questions about the time and weather in a city.before you answer, you should say your name: 'I am weather_time_agent'", global_instruction='', tools=[<function get_weather at 0x116afd300>, <function get_current_time at 0x116afd080>], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None), sub_agents=[], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are the Greeting Agent. Your ONLY task is to provide a friendly greeting to the user. Do not engage in any other conversation or tasks.before you answer, you should say your name: 'I am greeting_agent'", global_instruction='', tools=[], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None),
27
+ LlmAgent(name='farewell_agent', description='Handles simple farewells and goodbyes', parent_agent=LlmAgent(name='weather_time_agent', description='Agent to answer questions about the time and weather in a city.', parent_agent=None, sub_agents=[LlmAgent(name='greeting_agent', description='Handles simple greetings and hellos', parent_agent=LlmAgent(name='weather_time_agent', description='Agent to answer questions about the time and weather in a city.', parent_agent=None, sub_agents=[...], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are a helpful agent who can answer user questions about the time and weather in a city.before you answer, you should say your name: 'I am weather_time_agent'", global_instruction='', tools=[<function get_weather at 0x116afd300>, <function get_current_time at 0x116afd080>], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None), sub_agents=[], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are the Greeting Agent. Your ONLY task is to provide a friendly greeting to the user. Do not engage in any other conversation or tasks.before you answer, you should say your name: 'I am greeting_agent'", global_instruction='', tools=[], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None), LlmAgent(name='farewell_agent', description='Handles simple farewells and goodbyes', parent_agent=LlmAgent(name='weather_time_agent', description='Agent to answer questions about the time and weather in a city.', parent_agent=None, sub_agents=[...], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are a helpful agent who can answer user questions about the time and weather in a city.before you answer, you should say your name: 'I am weather_time_agent'", global_instruction='', tools=[<function get_weather at 0x116afd300>, <function get_current_time at 0x116afd080>], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None), sub_agents=[], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are the Farewell Agent. Your ONLY task is to provide a polite goodbye message. If not about goodbye, just transfer to weather_time_agentDo not perform any other actions.before you answer, you should say your name: 'I am farewell_agent'", global_instruction='', tools=[], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None)], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are a helpful agent who can answer user questions about the time and weather in a city.before you answer, you should say your name: 'I am weather_time_agent'", global_instruction='', tools=[<function get_weather at 0x116afd300>, <function get_current_time at 0x116afd080>], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None), sub_agents=[], before_agent_callback=None, after_agent_callback=None, model='gemini-2.5-flash-preview-04-17', instruction="You are the Farewell Agent. Your ONLY task is to provide a polite goodbye message. If not about goodbye, just transfer to weather_time_agentDo not perform any other actions.before you answer, you should say your name: 'I am farewell_agent'", global_instruction='', tools=[], generate_content_config=None, disallow_transfer_to_parent=False, disallow_transfer_to_peers=False, include_contents='default', input_schema=None, output_schema=None, output_key=None, planner=None, code_executor=None, examples=None, before_model_callback=<function my_before_model_callback at 0x1169d5e40>, after_model_callback=None, before_tool_callback=None, after_tool_callback=None)],
28
+ 'tools': [<function get_weather at 0x116afd300>,
29
+ <function get_current_time at 0x116afd080>]}
team_framework/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ # from . import load_team_config
team_framework/load_agents.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from google.adk.agents import Agent
2
+ import os
3
+
4
+ def my_before_model_callback(callback_context, **kwargs):
5
+ os.environ["GOOGLE_API_KEY"]='AIzaSyBYPwMLibOIoM-SQHuWjZ-V4LLmmMxqhm8'
6
+ # os.environ["GOOGLE_API_KEY"] = get_api_key() # 直接设置环境变量
7
+
8
+ def load_agent(item):
9
+ print(f"\nload_agent item: {item['name']}", item)
10
+ _agent = Agent(
11
+ name = item['name'],
12
+ model = item['model'],
13
+ instruction = item['instruction'],
14
+ description = item['description'],
15
+ before_model_callback=my_before_model_callback
16
+ )
17
+ return _agent
18
+
19
+ def load_agents(agents_dict:dict):
20
+ print("\n\n\n######## load_agents\nagents_dict: ", agents_dict)
21
+ ret_agents = {}
22
+ for item in agents_dict:
23
+ ret_agents[item['name']] = load_agent(item)
24
+ # ret_agents.append(load_agent(item))
25
+ print("\n\n\n@@@@@@@@@@@@@@@@@@@@@\nload_agents\nret_agents.greeting_agent: ", ret_agents['greeting_agent'])
26
+ print("\n\n\n@@@@@@@@@@@@@@@@@@@@@\nload_agents\nret_agents[farewell_agent]: ", ret_agents['farewell_agent'])
27
+ return ret_agents
28
+
29
+ def load_root_agent(_root_agent):
30
+ ret_agent = load_agent(_root_agent)
31
+ print("\n\n\n######## load_root_agent\nret_agent: ", ret_agent)
32
+ return ret_agent
team_framework/load_team_config.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .supabase_cli import get_supabase_client
2
+ from supabase import Client
3
+ from google.adk.agents import Agent
4
+
5
+ def load_agent_config(db_item):
6
+ # print('\nload_agent_config...')
7
+ # print('\n\n\n\n\n***************************\ndb_item',db_item)
8
+ agent_config={
9
+ "name": db_item['name'],
10
+ "model": db_item['model'],
11
+ "instruction": db_item['instruction'],
12
+ "tools": db_item['tools'],
13
+ "sub_agents": db_item['sub_agents'],
14
+ "description": db_item['description']
15
+ }
16
+ tools_config=[]
17
+ if db_item['tools']:
18
+ agent_config['tools'] = db_item['tools']
19
+ tools_config = list(set(tools_config + db_item['tools']))
20
+ return { 'agent_config': agent_config, 'tools_config': tools_config}
21
+
22
+ def creat_agent() -> Agent:
23
+ pass
24
+ def load_team_config():
25
+ a_team_config = {
26
+ "agents":[],
27
+ "root_agent": None,
28
+ "tools":[]
29
+ }
30
+
31
+ print("Loading team_config from database...")
32
+ supabase: Client = get_supabase_client()
33
+ if not supabase:
34
+ return {}
35
+ try:
36
+ response = supabase.from_("team_get_weather").select("*").order("sort_id").execute()
37
+ for item in response.data:
38
+ if item['is_root']:
39
+ _agent_config = load_agent_config(item)
40
+ print('_agent_config',_agent_config)
41
+ a_team_config['root_agent'] = _agent_config['agent_config']
42
+ a_team_config['tools'] = list(set(a_team_config['tools'] + _agent_config['tools_config']))
43
+ else:
44
+ _agent_config = load_agent_config(item)
45
+ a_team_config['agents'].append(_agent_config['agent_config'])
46
+ a_team_config['tools'] = list(set(a_team_config['tools'] + _agent_config['tools_config']))
47
+ # print('\n\na_team_config',a_team_config)
48
+ except Exception as e:
49
+ print(f"Error loading API keys from database: {e}")
50
+ a_team_config = {} # Clear cache on error
51
+ return a_team_config
52
+
53
+ """
54
+ a_team_config
55
+ {
56
+ 'agents': [
57
+ {
58
+ 'name': 'farewell_agent',
59
+ 'model': 'gemini-2.5-flash-preview-04-17',
60
+ 'instruction': "You are the Farewell Agent. Your ONLY task is to provide a polite goodbye message.\nIf not about goodbye, just transfer to weather_time_agent.\nDo not perform any other actions.\nBefore you answer, you should say your name: 'I am farewell_agent'",
61
+ 'tools': None,
62
+ 'sub_agents': None,
63
+ 'description': 'Handles simple farewells and goodbyes'
64
+ },
65
+ {
66
+ 'name': 'greeting_agent',
67
+ 'model': 'gemini-2.5-flash-preview-04-17',
68
+ 'instruction': "You are the Greeting Agent. Your ONLY task is to provide a friendly greeting to the user. \nDo not engage in any other conversation or tasks.\nBefore you answer, you should say your name: 'I am greeting_agent'",
69
+ 'tools': None,
70
+ 'sub_agents': None,
71
+ 'description': 'Handles simple greetings and hellos'
72
+ }
73
+ ],
74
+ 'root_agent': {
75
+ 'name': 'weather_time_agent',
76
+ 'model': 'gemini-2.5-flash-preview-04-17', '
77
+ instruction': "You are a helpful agent who can answer user questions about the time and weather in a city.\nBefore you answer, you should say your name: 'I am weather_time_agent'",
78
+ 'tools': [
79
+ 'get_weather',
80
+ 'get_current_time'
81
+ ],
82
+ 'sub_agents': [
83
+ 'greeting_agent',
84
+ 'farewell_agent'
85
+ ],
86
+ 'description': 'Agent to answer questions about the time and weather in a city.'
87
+ },
88
+ 'tools': [
89
+ 'get_weather',
90
+ 'get_current_time'
91
+ ]
92
+ }
93
+ """
teams/get_weather/load_agents.py → team_framework/load_tools.py RENAMED
@@ -1,13 +1,12 @@
1
- import importlib, os
2
- from supabase import create_client, Client
3
- from google.adk.agents import Agent
4
 
5
- def load_agents_from_array(arr:list):
6
  ret = {}
7
  for item in arr:
8
  # 构建正确的模块路径,使用 __name__ 动态获取当前模块的父路径(此处正好为团队名称),并加上 .tools 子目录和工具名称
9
- parent_module_path = '.'.join(__name__.split('.')[:-1])
10
- module_path = f'{parent_module_path}.tools.{item}'
 
11
  try:
12
  module = importlib.import_module(module_path)
13
  # 函数名预期与工具名称相同
@@ -20,40 +19,12 @@ def load_agents_from_array(arr:list):
20
  print(f"在模块 {module_path} 中找不到函数 '{item}': {e}")
21
  return ret
22
 
23
- def get_supabase_client() -> Client:
24
- """Initializes and returns a Supabase client."""
25
- url: str = os.environ.get("SUPABASE_URL")
26
- key: str = os.environ.get("SUPABASE_KEY")
27
- if not url or not key:
28
- print("Supabase URL or Key not found in environment variables.")
29
- return None
30
- return create_client(url, key)
31
 
32
- def load_agents_from_db():
33
- """Loads agents from the database."""
34
- supabase: Client = get_supabase_client()
35
- if not supabase:
36
- return {}
37
-
38
- try:
39
- response = supabase.from_("team_get_weather").select("*").eq("is_root", False).execute()
40
- if response.data and response.data[0]:
41
- ret = []
42
- for item in response.data:
43
- agent = Agent(
44
- name=item['name'],
45
- model=item['model'],
46
- instruction=item['instruction'],
47
- # tools=item['tools'],
48
- description=item['description']
49
- )
50
- ret.append(agent)
51
- return ret
52
- else:
53
- print("Unexpected database response structure or no data found.")
54
- ret = {}
55
-
56
- except Exception as e:
57
- print(f"Error loading agents from database: {e}")
58
- ret = {} # Clear cache on error
59
- return ret
 
1
+ import importlib
 
 
2
 
3
+ def load_tools_from_array(arr:list):
4
  ret = {}
5
  for item in arr:
6
  # 构建正确的模块路径,使用 __name__ 动态获取当前模块的父路径(此处正好为团队名称),并加上 .tools 子目录和工具名称
7
+ # parent_module_path = '.'.join(__name__.split('.')[:-1])
8
+ # module_path = f'{parent_module_path}.tools.{item}'
9
+ module_path = f'teams.get_weather.tools.{item}'
10
  try:
11
  module = importlib.import_module(module_path)
12
  # 函数名预期与工具名称相同
 
19
  print(f"在模块 {module_path} 中找不到函数 '{item}': {e}")
20
  return ret
21
 
22
+ # def load_tools_from_db():
23
+ # tool_arr = ["get_weather", "get_current_time"]
24
+ # return load_tools_from_array(tool_arr)
 
 
 
 
 
25
 
26
+ def load_tools(tools_dict:dict):
27
+ print("\n\n\n######## load_tools\ntools_dict: ", tools_dict)
28
+ # load_tools_from_array(tools_dict)
29
+ return load_tools_from_array(tools_dict)
30
+ return tools_dict
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
team_framework/supabase_cli.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from supabase import create_client, Client
2
+ import os
3
+
4
+ def get_supabase_client() -> Client:
5
+ """Initializes and returns a Supabase client."""
6
+ url: str = os.environ.get("SUPABASE_URL")
7
+ key: str = os.environ.get("SUPABASE_KEY")
8
+ if not url or not key:
9
+ print("Supabase URL or Key not found in environment variables.")
10
+ return None
11
+ return create_client(url, key)
teams/ai_quant/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from . import agent
teams/ai_quant/agent.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from google.adk.agents import Agent
3
+ from supabase import create_client, Client
4
+ from .tools.get_current_time import get_current_time
5
+ from .tools.get_weather import get_weather
6
+ def my_before_model_callback(callback_context, **kwargs):
7
+ # os.environ["GOOGLE_API_KEY"] = get_api_key() # 直接设置环境变量
8
+ os.environ["GOOGLE_API_KEY"] = "AIzaSyDCbN6WDNIEtB8yJmNX40ScechQu6mCZoo" # 直接设置环境变量
9
+
10
+ print('99999999999999999999999999999999999999999')
11
+
12
+ # 从环境变量获取 Supabase 配置
13
+ # 建议将敏感信息通过环境变量传递,而不是直接硬编码或从文件中读取
14
+ # 这里为了演示,直接使用了从 .env 文件读取到的值
15
+ # 在实际生产环境中,请确保通过安全的方式加载配置
16
+ SUPABASE_URL = os.environ.get("SUPABASE_URL", "https://bbvyxjvleoizsipxydsm.supabase.co")
17
+ SUPABASE_KEY = os.environ.get("SUPABASE_KEY", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJidnl4anZsZW9изsipxydsmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDQ1MzkwNjIsImV4cCI6MjA2MDExNTA2Mn0.cbUNhiCHXqIaW4leU_vGTKVI51gLVvsFOVWYS_vJrA4")
18
+ DB_TABLE_NAME = os.environ.get("DB_TABLE_NAME", "team_quant")
19
+
20
+ # 初始化 Supabase 客户端
21
+ supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
22
+
23
+ def get_all_agents_from_db() -> dict:
24
+ """
25
+ 从 Supabase 数据库中提取所有 agent 记录,并形成字典。
26
+ """
27
+ try:
28
+ # 从指定的表中查询所有数据
29
+ response = supabase.table(DB_TABLE_NAME).select("*").order('sort_id', desc=False).execute()
30
+ print('\n\n\n\n\nresponse:\n', response)
31
+
32
+ # 检查响应是否成功
33
+ if response.data:
34
+ # 将查询结果转换为字典,这里假设每条记录都有一个唯一的 'id' 或其他键
35
+ # 如果没有合适的唯一键,可能需要调整字典的构建方式
36
+ agents_dict = {record.get("id"): record for record in response.data}
37
+ print(f"成功从数据库提取 {len(response.data)} 条 agent 记录。")
38
+ return agents_dict
39
+ else:
40
+ print("从数据库提取 agent 记录失败或没有记录。")
41
+ return {}
42
+ except Exception as e:
43
+ print(f"提取 agent 记录时发生错误: {e}")
44
+ return {}
45
+
46
+ # 示例用法 (可选,根据需要决定是否保留)
47
+ # if __name__ == "__main__":
48
+ # all_agents = get_all_agents_from_db()
49
+ # print("提取到的 agent 字典:")
50
+ # print(all_agents)
51
+
52
+ # 从数据库加载所有 agents 数据 (字典形式)
53
+ all_agents_data_dict = get_all_agents_from_db()
54
+ print("\n\n\n\n\n\n\n从数据库加载的 agents 数据 all_agents_data_dict:\n",all_agents_data_dict)
55
+
56
+ # 将字典值转换为列表并按 sort_id 排序
57
+ agent_records = sorted(all_agents_data_dict.values(), key=lambda x: x.get("sort_id", float('inf')))
58
+
59
+ # 初始化 root_ageint_idx 变量
60
+ root_ageint_idx = -1
61
+
62
+ # 查找 root agent 的索引
63
+ if agent_records:
64
+ for index, agent_data in enumerate(agent_records):
65
+ if agent_data.get("is_root", False): # 假设数据库记录包含 is_root 字段
66
+ root_ageint_idx = index
67
+ print(f"找到 root agent 的索引: {root_ageint_idx}")
68
+ break # 假设只有一个 root agent
69
+
70
+ # 创建 Agent 对象并存储到按名称索引的字典中
71
+ agents_by_name = {}
72
+ loaded_agents_list = [] # Keep a list for the final output if needed
73
+ if agent_records:
74
+ for agent_data in agent_records:
75
+ try:
76
+ # 假设数据库记录包含 name, model, instruction, description, sub_agents, sort_id, is_root 字段
77
+ agent_name = agent_data.get("name", f"agent_{agent_data.get('id', 'unknown')}")
78
+ agent = Agent(
79
+ name=agent_name,
80
+ model=agent_data.get("model", "gemini-2.0-flash-exp"),
81
+ instruction=agent_data.get("instruction", ""),
82
+ description=agent_data.get("description", ""),
83
+ # sub_agents will be added in the next step
84
+ # callbacks etc. can be added here if present in data
85
+ )
86
+ # Map tool names from database to actual tool functions
87
+ tool_map = {"get_weather": get_weather, "get_current_time": get_current_time}
88
+ tools_list = [tool_map.get(tool_name) for tool_name in agent_data.get("tools") or [] if tool_name in tool_map]
89
+ agent.tools = tools_list # Use the mapped tool functions
90
+
91
+ agents_by_name[agent_name] = agent
92
+ loaded_agents_list.append(agent) # Add to list if needed later
93
+ print(f"成功创建 agent 对象: {agent.name}")
94
+ except Exception as e:
95
+ print(f"创建 agent 对象时发生错误 (数据: {agent_data}): {e}")
96
+
97
+ # 处理 sub_agents 引用
98
+ if agent_records:
99
+ for agent_data in agent_records:
100
+ agent_name = agent_data.get("name", f"agent_{agent_data.get('id', 'unknown')}")
101
+ current_agent = agents_by_name.get(agent_name)
102
+ if current_agent and "sub_agents" in agent_data and isinstance(agent_data["sub_agents"], list):
103
+ current_agent.sub_agents = []
104
+ for sub_agent_name in agent_data["sub_agents"]:
105
+ sub_agent = agents_by_name.get(sub_agent_name)
106
+ if sub_agent:
107
+ current_agent.sub_agents.append(sub_agent)
108
+ print(f"为 agent '{current_agent.name}' 添加 sub-agent: '{sub_agent.name}'")
109
+ else:
110
+ print(f"警告: 未找到 sub-agent '{sub_agent_name}' (被 agent '{current_agent.name}' 引用)")
111
+
112
+ print(f"总共加载并关联了 {len(agents_by_name)} 个 agents。")
113
+
114
+ # 您现在可以使用 agents_by_name 字典或 loaded_agents_list 列表中的 Agent 对象
115
+ # 例如,如果您需要一个列表:
116
+ loaded_agents = loaded_agents_list
117
+
118
+ # 根据找到的索引设置 root_agent
119
+ root_agent = None
120
+ if 0 <= root_ageint_idx < len(loaded_agents_list):
121
+ root_agent = loaded_agents_list[root_ageint_idx]
122
+ # root_agent.before_model_callback=my_before_model_callback
123
+ print(f"\n\n\n\n\n已设置 root_agent 为: {root_agent.name}")
124
+ else:
125
+ print("警告: 未找到 root agent 或索引无效,使用默认 root_agent。")
126
+ # 如果没有找到 root agent,可以考虑使用一个默认的 root_agent 或者抛出错误
127
+ root_agent = Agent(
128
+ name="default_root_agent",
129
+ model="gemini-2.0-flash-exp",
130
+ instruction="You are a helpful assistant.",
131
+ description="You are a helpful assistant.",
132
+ # before_model_callback=my_before_model_callback,
133
+ tools=[]
134
+ )
135
+
136
+ # 轮询 loaded_agents_list
137
+ for agent in loaded_agents_list:
138
+ agent.before_model_callback=my_before_model_callback
139
+ if agent.sub_agents:
140
+ for sub_agent in agent.sub_agents:
141
+ sub_agent.parent_agent = agent
142
+
143
+ import pprint
144
+ print('\n\n\n\n*************************************\n\nroot_agent dict: \n')
145
+ pprint.pprint(root_agent.__dict__) # 尝试打印对象的字典表示
146
+
147
+
148
+
teams/ai_quant/readme.md ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ - 我要搭建一个google agent development kit 项目
2
+ - 从supabase数据库里的数据表内容,加载agent的配置信息,生成相应的agent实例
3
+ - supabase 数据库配置信息、团队基本信息存储在 .env 文件里
4
+ - 注意1:is_root字段为True的agent,是团队的根agent——root_agent,其他agent为可选子agents,root_agent必须有
5
+ - 注意2:数据库表里:tools字段(jsonb)里["google_search"]表示agent可以使用google_search这个tool;数据库表里:subbase_table字段(jsonb)里["searcher"]表示agent有子agent,名为searcher
6
+
teams/ai_quant/team_quant_rows.sql ADDED
@@ -0,0 +1,3 @@
 
 
 
 
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, '调度员', '量化交易团队成员');
teams/{get_weather → ai_quant}/tools/__init__.py RENAMED
File without changes
teams/ai_quant/tools/get_current_time.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ from zoneinfo import ZoneInfo
3
+ def get_current_time(city: str) -> dict:
4
+ """Returns the current time in a specified city.
5
+
6
+ Args:
7
+ city (str): The name of the city for which to retrieve the current time.
8
+
9
+ Returns:
10
+ dict: status and result or error msg.
11
+ """
12
+
13
+ if city.lower() == "new york":
14
+ tz_identifier = "America/New_York"
15
+ else:
16
+ return {
17
+ "status": "error",
18
+ "error_message": (
19
+ f"Sorry, I don't have timezone information for {city}."
20
+ ),
21
+ }
22
+
23
+ tz = ZoneInfo(tz_identifier)
24
+ now = datetime.datetime.now(tz)
25
+ report = (
26
+ f'The current time in {city} is {now.strftime("%Y-%m-%d %H:%M:%S %Z%z")}'
27
+ )
28
+ return {"status": "success", "report": report}
teams/ai_quant/tools/get_weather.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def get_weather(city: str) -> dict:
2
+ """Retrieves the current weather report for a specified city.
3
+
4
+ Args:
5
+ city (str): The name of the city for which to retrieve the weather report.
6
+
7
+ Returns:
8
+ dict: status and result or error msg.
9
+ """
10
+ if city.lower() == "new york":
11
+ return {
12
+ "status": "success",
13
+ "report": (
14
+ "The weather in New York is sunny with a temperature of 25 degrees"
15
+ " Celsius (77 degrees Fahrenheit)."
16
+ ),
17
+ }
18
+ else:
19
+ return {
20
+ "status": "error",
21
+ "error_message": f"Weather information for '{city}' is not available.",
22
+ }
test.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ d=1
2
+ a={"b":{"c":d}}
3
+ print(a["b"]["c"])
4
+ d=2
5
+ print(a["b"]["c"])