Elffuss BraidHub

kikocis/Based-Agent public

01638627d2bc 路 2.5 KiBRawPermalink
1import shlex
2import argparse
3from src.swarm.swarm import Swarm
4from src.tasks.task import Task
5from configs.general import test_root, test_file, engine_name, persist
6from src.validator import validate_all_tools, validate_all_assistants
7from src.arg_parser import parse_args
8
9
10def main():
11 args = parse_args()
12 try:
13 validate_all_tools(engine_name)
14 validate_all_assistants()
15 except:
16 raise Exception("Validation failed")
17
18 swarm = Swarm(
19 engine_name=engine_name, persist=persist)
20
21 if args.test is not None:
22 test_files = args.test
23 if len(test_files) == 0:
24 test_file_paths = [f"{test_root}/{test_file}"]
25 else:
26 test_file_paths = [f"{test_root}/{file}" for file in test_files]
27 swarm = Swarm(engine_name='local')
28 swarm.deploy(test_mode=True, test_file_paths=test_file_paths)
29
30 elif args.input:
31 # Interactive mode for adding tasks
32 while True:
33 print("Enter a task (or 'exit' to quit):")
34 task_input = input()
35
36 # Check for exit command
37 if task_input.lower() == 'exit':
38 break
39
40 # Use shlex to parse the task description and arguments
41 task_args = shlex.split(task_input)
42 task_parser = argparse.ArgumentParser()
43 task_parser.add_argument("description", type=str, nargs='?', default="")
44 task_parser.add_argument("--iterate", action="store_true", help="Set the iterate flag for the new task.")
45 task_parser.add_argument("--evaluate", action="store_true", help="Set the evaluate flag for the new task.")
46 task_parser.add_argument("--assistant", type=str, default="user_interface", help="Specify the assistant for the new task.")
47
48 # Parse task arguments
49 task_parsed_args = task_parser.parse_args(task_args)
50
51 # Create and add the new task
52 new_task = Task(description=task_parsed_args.description,
53 iterate=task_parsed_args.iterate,
54 evaluate=task_parsed_args.evaluate,
55 assistant=task_parsed_args.assistant)
56 swarm.add_task(new_task)
57
58 # Deploy Swarm with the new task
59 swarm.deploy()
60 swarm.tasks.clear()
61
62 else:
63 # Load predefined tasks if any
64 # Deploy the Swarm for predefined tasks
65 swarm.load_tasks()
66 swarm.deploy()
67
68 print("\n\n馃嵂馃悵馃嵂 Swarm operations complete 馃嵂馃悵馃嵂\n\n")
69
70
71if __name__ == "__main__":
72 main()