@agent-smith/task 0.3.3 → 0.4.1

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;
89
- }
90
- else {
91
- this.def.inferParams = formatInferParams(this.def.inferParams ?? {}, conf ?? {});
86
+ this.def.tools?.forEach((t) => tpl.addTool(t));
92
87
  }
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);
@@ -101,21 +100,6 @@ class Task {
101
100
  if (hasTools) {
102
101
  options.tools = this.def.tools;
103
102
  }
104
- if (conf?.debug) {
105
- if (this.agent?.history) {
106
- this.agent.history.forEach(t => {
107
- if (t?.assistant || t?.tools) {
108
- tpl.pushToHistory(t);
109
- }
110
- });
111
- }
112
- console.log("-----------", model.name, "- Template:", tpl.name, "- Ctx:", ctx, "-----------");
113
- console.log(useTemplates ? tpl.prompt(finalPrompt) : finalPrompt);
114
- console.log("----------------------------------------------");
115
- console.log("Infer params:", this.def.inferParams);
116
- console.log("----------------------------------------------");
117
- //options.debug = true
118
- }
119
103
  if (this.agent.lm.providerType == "ollama") {
120
104
  if (!this.def.inferParams?.extra) {
121
105
  this.def.inferParams["extra"] = {};
@@ -135,24 +119,45 @@ class Task {
135
119
  if (isRoutingAgent) {
136
120
  options.isToolsRouter = true;
137
121
  }
138
- if (!useTemplates) {
139
- if (this.def.template?.system) {
140
- options.system = this.def.template.system;
122
+ if (this.def.template?.system) {
123
+ options.system = this.def.template.system;
124
+ }
125
+ if (this.def.template?.afterSystem) {
126
+ if (options?.system) {
127
+ options.system = options.system + this.def.template.afterSystem;
141
128
  }
142
- if (this.def?.shots) {
143
- options.history = options?.history ? [...options.history, ...this.def.shots] : this.def.shots;
129
+ else {
130
+ options.system = this.def.template.afterSystem;
144
131
  }
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);
132
+ }
133
+ if (this.def?.shots) {
134
+ options.history = options?.history ? [...this.def.shots, ...options.history] : this.def.shots;
135
+ }
136
+ if (conf?.debug) {
137
+ if (this.agent?.history) {
138
+ this.agent.history.forEach(t => {
139
+ if (t?.assistant || t?.tools) {
140
+ tpl.pushToHistory(t);
141
+ }
142
+ });
143
+ }
144
+ console.log("-----------", model.name, "- Template:", tpl.name, "- Ctx:", ctx, "-----------");
145
+ if (this.agent.lm.providerType == 'openai') {
146
+ if (options?.system) {
147
+ console.log("SYSTEM:", options.system, "\n");
148
+ }
149
+ }
150
+ console.log(this.agent.lm.providerType != 'openai' ? tpl.prompt(finalPrompt) : finalPrompt);
151
+ console.log("----------------------------------------------");
152
+ console.log("Infer params:", this.def.inferParams);
153
+ console.log("----------------------------------------------");
154
+ //options.debug = true
155
+ }
156
+ //console.log("RUN AGENT (TASK) params:", this.def.inferParams);
157
+ //console.log("RUN AGENT (TASK) options:", options);
158
+ answer = await this.agent.run(finalPrompt, this.def.inferParams, options, tpl);
159
+ if (this.agent.lm.providerType == "openai") {
153
160
  tpl.history = this.agent.history;
154
- //console.log("RAW ANSWER", answer);
155
- //console.log("\nHISTORY", this.agent.history);
156
161
  }
157
162
  // remove task tools from the agent
158
163
  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.1",
4
4
  "description": "A toolkit to create human friendly agents: the language model tasks module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,23 +14,23 @@
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",
19
- "modprompt": "^0.14.2",
20
- "yaml": "^2.8.2"
17
+ "@agent-smith/agent": "^0.4.1",
18
+ "@agent-smith/tfm": "^0.3.1",
19
+ "modprompt": "^0.14.3",
20
+ "yaml": "^2.8.3"
21
21
  },
22
22
  "devDependencies": {
23
- "@locallm/api": "^0.7.3",
23
+ "@locallm/api": "^0.8.0",
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.5.2",
29
+ "openai": "6.33.0",
30
30
  "restmix": "^0.6.1",
31
- "rollup": "^4.59.0",
31
+ "rollup": "^4.60.1",
32
32
  "tslib": "^2.8.1",
33
- "typescript": "^5.9.3"
33
+ "typescript": "^6.0.2"
34
34
  },
35
35
  "files": [
36
36
  "dist"
@@ -48,4 +48,4 @@
48
48
  "registry": "https://registry.npmjs.org/"
49
49
  },
50
50
  "license": "MIT"
51
- }
51
+ }