File size: 1,815 Bytes
02f5e5f
 
 
 
 
8cbefa9
02f5e5f
 
 
8cbefa9
02f5e5f
 
 
 
8cbefa9
02f5e5f
 
 
8cbefa9
02f5e5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import time
import random
import logging
from pathlib import Path

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Define the root directory for the application
ROOT_DIR = Path(__file__).parent
AGENTS_DIR = ROOT_DIR / "agents"
TOOLS_DIR = ROOT_DIR / "tools"

# Create directories if they do not exist
AGENTS_DIR.mkdir(exist_ok=True)
TOOLS_DIR.mkdir(exist_ok=True)

# Function to generate a new agent
def generate_agent(agent_name: str) -> str:
    agent_code = f"""
class {agent_name}:
    def __init__(self):
        self.name = '{agent_name}'

    def run(self):
        print("Running {agent_name}...")
"""
    agent_file_path = AGENTS_DIR / f"{agent_name}.py"
    with open(agent_file_path, 'w') as f:
        f.write(agent_code)
    logger.info(f"Generated agent: {agent_name} at {agent_file_path}")
    return agent_file_path

# Function to generate a new tool
def generate_tool(tool_name: str) -> str:
    tool_code = f"""
def {tool_name}():
    print("Executing tool: {tool_name}")
"""
    tool_file_path = TOOLS_DIR / f"{tool_name}.py"
    with open(tool_file_path, 'w') as f:
        f.write(tool_code)
    logger.info(f"Generated tool: {tool_name} at {tool_file_path}")
    return tool_file_path

# Main loop to continuously generate agents and tools
def main():
    while True:
        # Randomly decide to generate an agent or a tool
        if random.choice([True, False]):
            agent_name = f"Agent{random.randint(1, 1000)}"
            generate_agent(agent_name)
        else:
            tool_name = f"Tool{random.randint(1, 1000)}"
            generate_tool(tool_name)

        # Sleep for a while before generating the next agent/tool
        time.sleep(5)  # Adjust the sleep time as needed

if __name__ == "__main__":
    main()