Skip to content

Commit fad2c60

Browse files
authored
refactor: improve run-agent/run-agent scripts (#160)
1 parent e4f85a0 commit fad2c60

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed

scripts/run-agent.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,10 @@ async function loadEnv(filePath) {
106106
}
107107

108108
async function run(agentName, agentPath, agentFunc, agentData) {
109-
let mod;
110109
if (os.platform() === "win32") {
111110
agentPath = `file://${agentPath}`;
112111
}
113-
try {
114-
mod = await import(agentPath);
115-
} catch {
116-
throw new Error(`Unable to load agent tools at '${agentPath}'`);
117-
}
112+
const mod = await import(agentPath);
118113
if (!mod || !mod[agentFunc]) {
119114
throw new Error(`Not module function '${agentFunc}' at '${agentPath}'`);
120115
}

scripts/run-agent.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,11 @@ def load_env(file_path):
9494

9595

9696
def run(agent_name, agent_path, agent_func, agent_data):
97-
try:
98-
spec = importlib.util.spec_from_file_location(
99-
os.path.basename(agent_path), agent_path
100-
)
101-
mod = importlib.util.module_from_spec(spec)
102-
spec.loader.exec_module(mod)
103-
except:
104-
raise Exception(f"Unable to load agent tools at '{agent_path}'")
97+
spec = importlib.util.spec_from_file_location(
98+
os.path.basename(agent_path), agent_path
99+
)
100+
mod = importlib.util.module_from_spec(spec)
101+
spec.loader.exec_module(mod)
105102

106103
if not hasattr(mod, agent_func):
107104
raise Exception(f"Not module function '{agent_func}' at '{agent_path}'")

scripts/run-tool.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,10 @@ async function loadEnv(filePath) {
9393
}
9494

9595
async function run(toolName, toolPath, toolFunc, toolData) {
96-
let mod;
9796
if (os.platform() === "win32") {
9897
toolPath = `file://${toolPath}`;
9998
}
100-
try {
101-
mod = await import(toolPath);
102-
} catch {
103-
throw new Error(`Unable to load tool at '${toolPath}'`);
104-
}
99+
const mod = await import(toolPath);
105100
if (!mod || !mod[toolFunc]) {
106101
throw new Error(`Not module function '${toolFunc}' at '${toolPath}'`);
107102
}

scripts/run-tool.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,11 @@ def load_env(file_path):
8989

9090

9191
def run(tool_name, tool_path, tool_func, tool_data):
92-
try:
93-
spec = importlib.util.spec_from_file_location(
94-
os.path.basename(tool_path), tool_path
95-
)
96-
mod = importlib.util.module_from_spec(spec)
97-
spec.loader.exec_module(mod)
98-
except:
99-
raise Exception(f"Unable to load tool at '{tool_path}'")
92+
spec = importlib.util.spec_from_file_location(
93+
os.path.basename(tool_path), tool_path
94+
)
95+
mod = importlib.util.module_from_spec(spec)
96+
spec.loader.exec_module(mod)
10097

10198
if not hasattr(mod, tool_func):
10299
raise Exception(f"Not module function '{tool_func}' at '{tool_path}'")

0 commit comments

Comments
 (0)