Skip to content

Commit

Permalink
Fix in job execution
Browse files Browse the repository at this point in the history
- Updated `cmds.ts` to pass options to `executeJobCmd` and `executeActionCmd`.
- Modified `execute_job.ts` to accept options for `job.runTask` calls.
- Added option handling to `execute_task.ts`.
- Bumped version number in `package.json`.
  • Loading branch information
synw committed Oct 16, 2024
1 parent b0c2190 commit c3640b6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/cli/bin/cmd/clicmds/cmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ function initAliases(): Record<string, Cmd> {
_cmds[alias.name] = {
cmd: (args: Array<string> = [], options: any = {}, quiet = false) => executeActionCmd([alias.name, ...args], options, quiet),
description: "action: " + alias.name,
args: "arguments: \n-args: other arguments if any for the action"
//args: "arguments: \n-args: other arguments if any for the action"
}
break;
case "job":
_cmds[alias.name] = {
cmd: (args: Array<string> = [], options: any) => _executeJobCmd([alias.name, ...args], options),
description: "job: " + alias.name,
args: "arguments: \n-args: other arguments if any for the job"
//args: "arguments: \n-args: other arguments if any for the job"
}
}
});
Expand Down Expand Up @@ -162,7 +162,7 @@ async function _executeJobCmd(args: Array<string> = [], options: any): Promise<a
return
}
const name = args.shift()!;
const res = await executeJobCmd(name, args);
const res = await executeJobCmd(name, args, options);
return res
//console.log("ENDRES", t);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/cmd/lib/execute_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function executeActionCmd(args: Array<string> = [], options: any = {}, qui
throw new Error(`Action ext ${ext} not implemented`)
break;
}
const res = await act.run(args);
const res = await act.run(args, options);
if (!quiet) {
console.log(res.data);
}
Expand Down
34 changes: 24 additions & 10 deletions packages/cli/bin/cmd/lib/execute_job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FeatureType } from '../../interfaces.js';
import { formatMode } from '../../state/state.js';
import { initTaskVars, readTask } from './utils.js';

async function executeJobCmd(name: string, args: Array<any> = []): Promise<Record<string, any>> {
async function executeJobCmd(name: string, args: Array<any> = [], options: any = {}): Promise<Record<string, any>> {
const { job, found } = await _dispatchReadJob(name);
//console.log("F", found);
if (!found) {
Expand All @@ -22,19 +22,24 @@ async function executeJobCmd(name: string, args: Array<any> = []): Promise<Recor
brain.backendsForModelsInfo();
let i = 0;
for (const [name, task] of Object.entries(job.tasks)) {
//console.log("TASK RUN", name, job.tasks[name], params, task.type);
//console.log("JOB TASK", name, task.type, "/", args, "/", options);
if (task.type == "task") {
//const pr = params.shift()!;
let conf: Record<string, any> = {};
let vars: Record<string, any> = {};
if (i == 0) {
const tv = initTaskVars(args);
//console.log("TV", tv);
conf = tv.conf;
vars = i == 0 ? tv.vars : params;
/*if (i == 0) {
const tv = initTaskVars(args);
console.log("TV", tv);
conf = tv.conf;
vars = tv.vars;
} else {
conf = {};
vars = params;
}
}*/
const { found, path } = getFeatureSpec(name, "task" as FeatureType);
if (!found) {
return { ok: false, data: {}, error: `Task ${name} not found` };
Expand All @@ -46,18 +51,27 @@ async function executeJobCmd(name: string, args: Array<any> = []): Promise<Recor
}
const taskSpec = taskBuilder.readFromYaml(tres.ymlTask);
//const task = taskBuilder.fromYaml(tres.ymlTask);
const ex = brain.getOrCreateExpertForModel(taskSpec.model.name, taskSpec.template.name);
let m = taskSpec.model.name;
let t = taskSpec.template.name;
if (conf?.model) {
m = conf.model
}
if (conf?.template) {
t = conf.template
}
//console.log("CONF", conf);
const ex = brain.getOrCreateExpertForModel(m, t);
//console.log("EFM", ex?.name);
if (!ex) {
throw new Error("No expert found for model " + taskSpec.model.name)
throw new Error("No expert found for model " + m)
}
ex.checkStatus();
ex.backend.setOnToken((t) => {
process.stdout.write(t)
});
conf["expert"] = ex;
try {
//console.log("Running", name, task.type, vars);
//console.log("Running", name, vars, "/", conf);
res = await job.runTask(name, vars, conf);
if ("text" in res) {
if (formatMode.value == "markdown") {
Expand All @@ -74,12 +88,12 @@ async function executeJobCmd(name: string, args: Array<any> = []): Promise<Recor
try {
if (i == 0) {
//console.log("Running", name, args);
res = await job.runTask(name, args);
res = await job.runTask(name, args, options);
} else {
//console.log("Running", name, params);
res = await job.runTask(name, params);
res = await job.runTask(name, params, options);
}
//console.log("RES", res);
//console.log("RES", res.data);
params = res.data;
}
catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/bin/cmd/lib/execute_task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ async function executeTaskCmd(args: Array<string> = [], options: any = {}): Prom
const taskSpec = taskBuilder.readFromYaml(res.ymlTask);
const task = taskBuilder.fromYaml(res.ymlTask);
const { conf, vars } = initTaskVars(args);
//console.log("Conf", conf)
//console.log("Vars", vars)
let m = taskSpec.model.name;
let t = taskSpec.template.name;
if (conf?.model) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@agent-smith/cli",
"description": "Agent Smith: terminal client for language model agents",
"repository": "https://github.com/synw/agent-smith",
"version": "0.0.15",
"version": "0.0.17",
"scripts": {
"buildrl": "rm -rf dist/* && rollup -c",
"build": "rm -rf dist/* && tsc",
Expand Down

0 comments on commit c3640b6

Please sign in to comment.