-
Notifications
You must be signed in to change notification settings - Fork 9
/
run_skill_chain.py
98 lines (77 loc) · 2.95 KB
/
run_skill_chain.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import time
import logging
import glob
import argparse
from jarvis.agent.jarvis_agent import JarvisAgent
import traceback
def clear_files_in_directory(directory_path):
file_patterns = ["*.yaml", "*.json", "*.txt"]
for pattern in file_patterns:
files_to_delete = glob.glob(os.path.join(directory_path, pattern))
for file_path in files_to_delete:
try:
os.remove(file_path)
logging.info(f"Remove file: {file_path}")
except Exception as e:
logging.info(f"Failed to remove {file_path}: {e}")
def pretty_output(exec_result):
print("\n" + "-" * 50)
print("Skill Execution Summary")
print("-" * 50 + "\n")
print(f"Skill Result: {exec_result.result}")
print(f"Skill Error: {exec_result.error}")
if exec_result.task_infos:
print("\n" + "=" * 50)
print("Detailed Task Infos")
print("=" * 50 + "\n")
for task_info in exec_result.task_infos:
print(f"Subtask: {task_info.task}")
print(f"Result: {task_info.result}")
print(f"Error: {task_info.error}\n")
print("-" * 50 + "\n")
print("End of Execution Summary")
print("-" * 50 + "\n")
def execute(workspace_dir, skill_lib_dir, execution_dir, skills):
os.makedirs(workspace_dir, exist_ok=True)
os.chdir(workspace_dir)
# Logging file name and line number
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - [%(filename)s:%(lineno)d] - %(message)s",
filename="chain_jarvis.log",
)
agent = JarvisAgent(skill_lib_dir)
for index, skill in enumerate(skills):
if index > 0:
logging.info(f"waitting for next skill {skill}")
print(f"waitting for next skill {skill}")
time.sleep(5)
clear_files_in_directory(execution_dir)
logging.info(f"executing skill: {skill}")
print(f"executing skill: {skill}")
try:
exec_result = agent.execute_skill(execution_dir, skill)
except Exception as e:
logging.error(f"Failed to execute skill: {skill}, error: {e}")
logging.error(traceback.format_exc())
return
pretty_output(exec_result)
def run():
parser = argparse.ArgumentParser(
description="CLI for Jarvis Agent Skills Chain Execution"
)
parser.add_argument("--workspace", required=True, help="Workspace directory path")
parser.add_argument(
"--skill_dir", required=True, help="Skill library directory path"
)
parser.add_argument(
"--execution_dir", required=True, help="Execution directory path"
)
parser.add_argument("--skills", required=True, help="Comma separated skills list")
args = parser.parse_args()
# Split comma-separated skills into a list
skills_list = args.skills.split(",")
execute(args.workspace, args.skill_dir, args.execution_dir, skills_list)
if __name__ == "__main__":
run()