refactor: improve run-agent/run-agent scripts (#160)
This commit is contained in:
@@ -106,15 +106,10 @@ async function loadEnv(filePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function run(agentName, agentPath, agentFunc, agentData) {
|
async function run(agentName, agentPath, agentFunc, agentData) {
|
||||||
let mod;
|
|
||||||
if (os.platform() === "win32") {
|
if (os.platform() === "win32") {
|
||||||
agentPath = `file://${agentPath}`;
|
agentPath = `file://${agentPath}`;
|
||||||
}
|
}
|
||||||
try {
|
const mod = await import(agentPath);
|
||||||
mod = await import(agentPath);
|
|
||||||
} catch {
|
|
||||||
throw new Error(`Unable to load agent tools at '${agentPath}'`);
|
|
||||||
}
|
|
||||||
if (!mod || !mod[agentFunc]) {
|
if (!mod || !mod[agentFunc]) {
|
||||||
throw new Error(`Not module function '${agentFunc}' at '${agentPath}'`);
|
throw new Error(`Not module function '${agentFunc}' at '${agentPath}'`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,14 +94,11 @@ def load_env(file_path):
|
|||||||
|
|
||||||
|
|
||||||
def run(agent_name, agent_path, agent_func, agent_data):
|
def run(agent_name, agent_path, agent_func, agent_data):
|
||||||
try:
|
|
||||||
spec = importlib.util.spec_from_file_location(
|
spec = importlib.util.spec_from_file_location(
|
||||||
os.path.basename(agent_path), agent_path
|
os.path.basename(agent_path), agent_path
|
||||||
)
|
)
|
||||||
mod = importlib.util.module_from_spec(spec)
|
mod = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(mod)
|
spec.loader.exec_module(mod)
|
||||||
except:
|
|
||||||
raise Exception(f"Unable to load agent tools at '{agent_path}'")
|
|
||||||
|
|
||||||
if not hasattr(mod, agent_func):
|
if not hasattr(mod, agent_func):
|
||||||
raise Exception(f"Not module function '{agent_func}' at '{agent_path}'")
|
raise Exception(f"Not module function '{agent_func}' at '{agent_path}'")
|
||||||
|
|||||||
+1
-6
@@ -93,15 +93,10 @@ async function loadEnv(filePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function run(toolName, toolPath, toolFunc, toolData) {
|
async function run(toolName, toolPath, toolFunc, toolData) {
|
||||||
let mod;
|
|
||||||
if (os.platform() === "win32") {
|
if (os.platform() === "win32") {
|
||||||
toolPath = `file://${toolPath}`;
|
toolPath = `file://${toolPath}`;
|
||||||
}
|
}
|
||||||
try {
|
const mod = await import(toolPath);
|
||||||
mod = await import(toolPath);
|
|
||||||
} catch {
|
|
||||||
throw new Error(`Unable to load tool at '${toolPath}'`);
|
|
||||||
}
|
|
||||||
if (!mod || !mod[toolFunc]) {
|
if (!mod || !mod[toolFunc]) {
|
||||||
throw new Error(`Not module function '${toolFunc}' at '${toolPath}'`);
|
throw new Error(`Not module function '${toolFunc}' at '${toolPath}'`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,14 +89,11 @@ def load_env(file_path):
|
|||||||
|
|
||||||
|
|
||||||
def run(tool_name, tool_path, tool_func, tool_data):
|
def run(tool_name, tool_path, tool_func, tool_data):
|
||||||
try:
|
|
||||||
spec = importlib.util.spec_from_file_location(
|
spec = importlib.util.spec_from_file_location(
|
||||||
os.path.basename(tool_path), tool_path
|
os.path.basename(tool_path), tool_path
|
||||||
)
|
)
|
||||||
mod = importlib.util.module_from_spec(spec)
|
mod = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(mod)
|
spec.loader.exec_module(mod)
|
||||||
except:
|
|
||||||
raise Exception(f"Unable to load tool at '{tool_path}'")
|
|
||||||
|
|
||||||
if not hasattr(mod, tool_func):
|
if not hasattr(mod, tool_func):
|
||||||
raise Exception(f"Not module function '{tool_func}' at '{tool_path}'")
|
raise Exception(f"Not module function '{tool_func}' at '{tool_path}'")
|
||||||
|
|||||||
Reference in New Issue
Block a user