@agent-smith/task 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/task.js CHANGED
@@ -23,7 +23,7 @@ class Task {
23
23
  }
24
24
  let model = this.def.model;
25
25
  let ctx = this.def.ctx;
26
- const useTemplates = this.agent.lm.providerType !== "openai";
26
+ //const useTemplates = this.agent.lm.providerType !== "openai";
27
27
  if (conf) {
28
28
  if (conf?.model) {
29
29
  model = conf.model;
@@ -39,7 +39,8 @@ class Task {
39
39
  if (this.agent.lm.providerType == "ollama") {
40
40
  await this.agent.lm.loadModel(model.name, ctx);
41
41
  }
42
- this.def = applyVariables(this.def, params);
42
+ //console.log("PARAMS", params);
43
+ //console.log("DEF PR", this.def.prompt);
43
44
  let tpl = new PromptTemplate("none");
44
45
  const options = {};
45
46
  if (conf?.onToolCall) {
@@ -73,24 +74,22 @@ class Task {
73
74
  });
74
75
  }
75
76
  }
76
- if (useTemplates) {
77
- this.def.model = model;
78
- tpl = formatTaskTemplate(this.def, model?.template ? model.template : undefined);
79
- this.def.inferParams = formatInferParams(this.def.inferParams ?? {}, conf ?? {}, tpl);
80
- //tpl.replacePrompt(this.def.prompt);
81
- if (hasTools) {
82
- if (!tpl?.toolsDef) {
83
- throw new Error(`The template ${tpl.name} does not have tools and the task ${this.def.name} specifies some`);
84
- }
85
- this.def.tools?.forEach((t) => tpl.addTool(t));
77
+ applyVariables(this.def, params);
78
+ this.def.model = model;
79
+ tpl = formatTaskTemplate(this.def, model?.template ? model.template : undefined);
80
+ this.def.inferParams = formatInferParams(this.def.inferParams ?? {}, conf ?? {}, tpl);
81
+ //tpl.replacePrompt(this.def.prompt);
82
+ if (hasTools) {
83
+ if (!tpl?.toolsDef) {
84
+ throw new Error(`The template ${tpl.name} does not have tools and the task ${this.def.name} specifies some`);
86
85
  }
87
- ;
88
- //finalPrompt = params.prompt;
86
+ this.def.tools?.forEach((t) => tpl.addTool(t));
89
87
  }
90
- else {
91
- this.def.inferParams = formatInferParams(this.def.inferParams ?? {}, conf ?? {});
92
- }
93
- //console.log("DEF", this.def);
88
+ ;
89
+ //finalPrompt = params.prompt;
90
+ /*console.log("-------------------------");
91
+ console.log("DEF", this.def);
92
+ console.log("-------------------------");*/
94
93
  //console.log("P", params.prompt);
95
94
  const finalPrompt = this.def.prompt.replace("{prompt}", params.prompt);
96
95
  //console.log("FP", finalPrompt);
@@ -110,7 +109,7 @@ class Task {
110
109
  });
111
110
  }
112
111
  console.log("-----------", model.name, "- Template:", tpl.name, "- Ctx:", ctx, "-----------");
113
- console.log(useTemplates ? tpl.prompt(finalPrompt) : finalPrompt);
112
+ console.log(this.agent.lm.providerType != 'openai' ? tpl.prompt(finalPrompt) : finalPrompt);
114
113
  console.log("----------------------------------------------");
115
114
  console.log("Infer params:", this.def.inferParams);
116
115
  console.log("----------------------------------------------");
@@ -135,24 +134,17 @@ class Task {
135
134
  if (isRoutingAgent) {
136
135
  options.isToolsRouter = true;
137
136
  }
138
- if (!useTemplates) {
139
- if (this.def.template?.system) {
140
- options.system = this.def.template.system;
141
- }
142
- if (this.def?.shots) {
143
- options.history = options?.history ? [...options.history, ...this.def.shots] : this.def.shots;
144
- }
145
- //console.log("RUN AGENT (TASK) params:", this.def.inferParams);
146
- //console.log("RUN AGENT (TASK) options:", options);
147
- answer = await this.agent.run(finalPrompt, this.def.inferParams, options);
148
- }
149
- else {
150
- //console.log("RUN AGENT (TASK) params:", this.def.inferParams);
151
- //console.log("RUN AGENT (TASK) options:", options);
152
- answer = await this.agent.run(finalPrompt, this.def.inferParams, options, tpl);
137
+ if (this.def.template?.system) {
138
+ options.system = this.def.template.system;
139
+ }
140
+ if (this.def?.shots) {
141
+ options.history = options?.history ? [...this.def.shots, ...options.history] : this.def.shots;
142
+ }
143
+ //console.log("RUN AGENT (TASK) params:", this.def.inferParams);
144
+ //console.log("RUN AGENT (TASK) options:", options);
145
+ answer = await this.agent.run(finalPrompt, this.def.inferParams, options, tpl);
146
+ if (this.agent.lm.providerType == "openai") {
153
147
  tpl.history = this.agent.history;
154
- //console.log("RAW ANSWER", answer);
155
- //console.log("\nHISTORY", this.agent.history);
156
148
  }
157
149
  // remove task tools from the agent
158
150
  if (hasTools) {
package/dist/variables.js CHANGED
@@ -35,10 +35,14 @@ function applyVariables(taskDef, taskInput) {
35
35
  }
36
36
  // apply variables
37
37
  for (const [k, v] of Object.entries(taskInput)) {
38
+ //console.log("APPLY", k, v);
38
39
  taskDef.prompt = taskDef.prompt.replaceAll(`{${k}}`, v);
39
40
  if (taskDef.template?.system) {
40
41
  taskDef.template.system = taskDef.template.system.replaceAll(`{${k}}`, v);
41
42
  }
43
+ if (taskDef.template?.afterSystem) {
44
+ taskDef.template.afterSystem = taskDef.template.afterSystem.replaceAll(`{${k}}`, v);
45
+ }
42
46
  if (taskDef?.shots) {
43
47
  const nshots = new Array();
44
48
  taskDef.shots.forEach(s => {
@@ -51,6 +55,7 @@ function applyVariables(taskDef, taskInput) {
51
55
  taskDef.shots = nshots;
52
56
  }
53
57
  }
58
+ //console.log("TD FINAL", taskDef);
54
59
  return taskDef;
55
60
  }
56
61
  export { applyVariables, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-smith/task",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "description": "A toolkit to create human friendly agents: the language model tasks module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,8 +14,8 @@
14
14
  "docs": "typedoc --entryPointStrategy expand"
15
15
  },
16
16
  "dependencies": {
17
- "@agent-smith/agent": "^0.3.3",
18
- "@agent-smith/tfm": "^0.2.0",
17
+ "@agent-smith/agent": "^0.4.0",
18
+ "@agent-smith/tfm": "^0.3.0",
19
19
  "modprompt": "^0.14.2",
20
20
  "yaml": "^2.8.2"
21
21
  },
@@ -23,10 +23,10 @@
23
23
  "@locallm/api": "^0.7.3",
24
24
  "@locallm/types": "^0.7.1",
25
25
  "@rollup/plugin-node-resolve": "^16.0.3",
26
- "@rollup/plugin-terser": "^0.1.0",
26
+ "@rollup/plugin-terser": "^1.0.0",
27
27
  "@rollup/plugin-typescript": "^12.3.0",
28
- "@types/node": "^25.3.1",
29
- "openai": "6.25.0",
28
+ "@types/node": "^25.3.5",
29
+ "openai": "6.27.0",
30
30
  "restmix": "^0.6.1",
31
31
  "rollup": "^4.59.0",
32
32
  "tslib": "^2.8.1",
@@ -48,4 +48,4 @@
48
48
  "registry": "https://registry.npmjs.org/"
49
49
  },
50
50
  "license": "MIT"
51
- }
51
+ }