acecalisto3 commited on
Commit
05ae2f5
·
verified ·
1 Parent(s): b92f398

Update appaaa.py

Browse files
Files changed (1) hide show
  1. appaaa.py +130 -28
appaaa.py CHANGED
@@ -2,29 +2,29 @@ import os
2
  import time
3
  import random
4
  import logging
 
5
  from pathlib import Path
 
6
 
7
  # Set up logging
8
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
9
  logger = logging.getLogger(__name__)
10
 
11
- # Define the root directory for the application
12
  ROOT_DIR = Path(__file__).parent / "app"
13
  AGENTS_DIR = ROOT_DIR / "agents"
14
  TOOLS_DIR = ROOT_DIR / "tools"
15
  TOOLKIT_DIR = ROOT_DIR / "toolkit"
16
  AGENT_POOL_DIR = ROOT_DIR / "agent_pool"
17
 
18
- # Create directories if they do not exist
19
  AGENTS_DIR.mkdir(parents=True, exist_ok=True)
20
  TOOLS_DIR.mkdir(parents=True, exist_ok=True)
21
  TOOLKIT_DIR.mkdir(parents=True, exist_ok=True)
22
  AGENT_POOL_DIR.mkdir(parents=True, exist_ok=True)
23
 
24
- # Function to generate a new agent
25
  def generate_agent(agent_name: str) -> str:
26
- logger.info(f"Starting to generate agent: {agent_name}")
27
- time.sleep(1) # Simulate some processing time
28
  agent_code = f"""
29
  class {agent_name}:
30
  def __init__(self):
@@ -33,50 +33,152 @@ class {agent_name}:
33
  def run(self):
34
  print("Running {agent_name}...")
35
  """
36
- agent_file_path = AGENTS_DIR / f"{agent_name}.py"
37
- with open(agent_file_path, 'w') as f:
38
  f.write(agent_code)
39
- logger.info(f"Successfully generated agent: {agent_name} at {agent_file_path}")
40
 
41
- # Add the agent to the agent pool
42
- with open(AGENT_POOL_DIR / "agent_pool.txt", 'a') as pool_file:
43
- pool_file.write(f"{agent_name}\n")
44
 
45
- return agent_file_path
46
 
47
- # Function to generate a new tool
48
  def generate_tool(tool_name: str) -> str:
49
- logger.info(f"Starting to generate tool: {tool_name}")
50
- time.sleep(1) # Simulate some processing time
51
  tool_code = f"""
52
  def {tool_name}():
53
  print("Executing tool: {tool_name}")
54
  """
55
- tool_file_path = TOOLS_DIR / f"{tool_name}.py"
56
- with open(tool_file_path, 'w') as f:
57
  f.write(tool_code)
58
- logger.info(f"Successfully generated tool: {tool_name} at {tool_file_path}")
59
 
60
- # Add the tool to the toolkit
61
- with open(TOOLKIT_DIR / "toolkit.txt", 'a') as toolkit_file:
62
- toolkit_file.write(f"{tool_name}\n")
63
 
64
- return tool_file_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- # Main loop to continuously generate agents and tools
67
  def main():
68
- logger.info("Starting the agent/tool generation process...")
 
 
 
69
  while True:
70
- # Randomly decide to generate an agent or a tool
71
  if random.choice([True, False]):
72
  agent_name = f"Agent{random.randint(1, 1000)}"
73
  generate_agent(agent_name)
74
  else:
75
  tool_name = f"Tool{random.randint(1, 1000)}"
76
  generate_tool(tool_name)
77
-
78
- # Sleep for a while before generating the next agent/tool
79
- time.sleep(5) # Adjust the sleep time as needed
80
 
81
  if __name__ == "__main__":
82
  main()
 
2
  import time
3
  import random
4
  import logging
5
+ import importlib.util
6
  from pathlib import Path
7
+ import threading
8
 
9
  # Set up logging
10
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
11
  logger = logging.getLogger(__name__)
12
 
13
+ # Define directories
14
  ROOT_DIR = Path(__file__).parent / "app"
15
  AGENTS_DIR = ROOT_DIR / "agents"
16
  TOOLS_DIR = ROOT_DIR / "tools"
17
  TOOLKIT_DIR = ROOT_DIR / "toolkit"
18
  AGENT_POOL_DIR = ROOT_DIR / "agent_pool"
19
 
20
+ # Create directories
21
  AGENTS_DIR.mkdir(parents=True, exist_ok=True)
22
  TOOLS_DIR.mkdir(parents=True, exist_ok=True)
23
  TOOLKIT_DIR.mkdir(parents=True, exist_ok=True)
24
  AGENT_POOL_DIR.mkdir(parents=True, exist_ok=True)
25
 
 
26
  def generate_agent(agent_name: str) -> str:
27
+ logger.info(f"Generating agent: {agent_name}")
 
28
  agent_code = f"""
29
  class {agent_name}:
30
  def __init__(self):
 
33
  def run(self):
34
  print("Running {agent_name}...")
35
  """
36
+ agent_path = AGENTS_DIR / f"{agent_name}.py"
37
+ with open(agent_path, 'w') as f:
38
  f.write(agent_code)
 
39
 
40
+ with open(AGENT_POOL_DIR / "agent_pool.txt", 'a') as f:
41
+ f.write(f"{agent_name}\n")
 
42
 
43
+ return agent_path
44
 
 
45
  def generate_tool(tool_name: str) -> str:
46
+ logger.info(f"Generating tool: {tool_name}")
 
47
  tool_code = f"""
48
  def {tool_name}():
49
  print("Executing tool: {tool_name}")
50
  """
51
+ tool_path = TOOLS_DIR / f"{tool_name}.py"
52
+ with open(tool_path, 'w') as f:
53
  f.write(tool_code)
 
54
 
55
+ with open(TOOLKIT_DIR / "toolkit.txt", 'a') as f:
56
+ f.write(f"{tool_name}\n")
 
57
 
58
+ return tool_path
59
+
60
+ def get_agents():
61
+ agent_pool = AGENT_POOL_DIR / "agent_pool.txt"
62
+ if not agent_pool.exists():
63
+ return []
64
+ with open(agent_pool, 'r') as f:
65
+ return [line.strip() for line in f.readlines()]
66
+
67
+ def get_tools():
68
+ toolkit = TOOLKIT_DIR / "toolkit.txt"
69
+ if not toolkit.exists():
70
+ return []
71
+ with open(toolkit, 'r') as f:
72
+ return [line.strip() for line in f.readlines()]
73
+
74
+ def display_agents():
75
+ agents = get_agents()
76
+ print("\n=== Agent Catalog ===")
77
+ for idx, agent in enumerate(agents, 1):
78
+ print(f"{idx}. {agent}")
79
+ print("=====================")
80
+ return agents
81
+
82
+ def display_tools():
83
+ tools = get_tools()
84
+ print("\n=== Tool Inventory ===")
85
+ for idx, tool in enumerate(tools, 1):
86
+ print(f"{idx}. {tool}")
87
+ print("======================")
88
+ return tools
89
+
90
+ def summon_agent(agent_name):
91
+ agent_file = AGENTS_DIR / f"{agent_name}.py"
92
+ if not agent_file.exists():
93
+ print(f"Agent {agent_name} not found!")
94
+ return
95
+
96
+ try:
97
+ spec = importlib.util.spec_from_file_location(agent_name, agent_file)
98
+ module = importlib.util.module_from_spec(spec)
99
+ spec.loader.exec_module(module)
100
+ agent_class = getattr(module, agent_name)
101
+ agent_instance = agent_class()
102
+ agent_instance.run()
103
+ except Exception as e:
104
+ print(f"Error summoning agent: {str(e)}")
105
+
106
+ def summon_tool(tool_name):
107
+ tool_file = TOOLS_DIR / f"{tool_name}.py"
108
+ if not tool_file.exists():
109
+ print(f"Tool {tool_name} not found!")
110
+ return
111
+
112
+ try:
113
+ spec = importlib.util.spec_from_file_location(tool_name, tool_file)
114
+ module = importlib.util.module_from_spec(spec)
115
+ spec.loader.exec_module(module)
116
+ tool_func = getattr(module, tool_name)
117
+ tool_func()
118
+ except Exception as e:
119
+ print(f"Error executing tool: {str(e)}")
120
+
121
+ def user_interface():
122
+ while True:
123
+ print("\nMain Menu:")
124
+ print("1. List Agents")
125
+ print("2. List Tools")
126
+ print("3. Summon Agent")
127
+ print("4. Execute Tool")
128
+ print("5. Exit")
129
+
130
+ choice = input("Select an option (1-5): ").strip()
131
+
132
+ if choice == '1':
133
+ display_agents()
134
+ elif choice == '2':
135
+ display_tools()
136
+ elif choice == '3':
137
+ agents = get_agents()
138
+ if not agents:
139
+ print("No agents available!")
140
+ continue
141
+ display_agents()
142
+ try:
143
+ num = int(input("Enter agent number: "))
144
+ if 1 <= num <= len(agents):
145
+ summon_agent(agents[num-1])
146
+ else:
147
+ print("Invalid number!")
148
+ except ValueError:
149
+ print("Please enter a valid number!")
150
+ elif choice == '4':
151
+ tools = get_tools()
152
+ if not tools:
153
+ print("No tools available!")
154
+ continue
155
+ display_tools()
156
+ try:
157
+ num = int(input("Enter tool number: "))
158
+ if 1 <= num <= len(tools):
159
+ summon_tool(tools[num-1])
160
+ else:
161
+ print("Invalid number!")
162
+ except ValueError:
163
+ print("Please enter a valid number!")
164
+ elif choice == '5':
165
+ os._exit(0)
166
+ else:
167
+ print("Invalid option!")
168
 
 
169
  def main():
170
+ logger.info("Starting autonomous generation system...")
171
+ ui_thread = threading.Thread(target=user_interface, daemon=True)
172
+ ui_thread.start()
173
+
174
  while True:
 
175
  if random.choice([True, False]):
176
  agent_name = f"Agent{random.randint(1, 1000)}"
177
  generate_agent(agent_name)
178
  else:
179
  tool_name = f"Tool{random.randint(1, 1000)}"
180
  generate_tool(tool_name)
181
+ time.sleep(5)
 
 
182
 
183
  if __name__ == "__main__":
184
  main()