@agent-smith/task 0.1.8 → 0.2.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.d.ts +0 -2
- package/dist/task.js +37 -13
- package/package.json +3 -3
package/dist/task.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ToolSpec } from '@locallm/types';
|
|
2
1
|
import { Agent } from "@agent-smith/agent";
|
|
3
2
|
import { TaskConf, TaskDef, TaskInput, TaskOutput } from "./interfaces.js";
|
|
4
3
|
declare class Task {
|
|
@@ -7,6 +6,5 @@ declare class Task {
|
|
|
7
6
|
constructor(agent: Agent, def: TaskDef);
|
|
8
7
|
static fromYaml(agent: Agent, txt: string): Task;
|
|
9
8
|
run(params: TaskInput, conf?: TaskConf): Promise<TaskOutput>;
|
|
10
|
-
addTools(tools: Array<ToolSpec>): Task;
|
|
11
9
|
}
|
|
12
10
|
export { Task };
|
package/dist/task.js
CHANGED
|
@@ -15,10 +15,11 @@ class Task {
|
|
|
15
15
|
return new Task(agent, data);
|
|
16
16
|
}
|
|
17
17
|
async run(params, conf) {
|
|
18
|
+
//console.log("TASK DEF", this.def);
|
|
18
19
|
//console.log("TASK CONF", conf);
|
|
19
20
|
//console.log("TOOLS", this.agent.tools);
|
|
20
21
|
if (!params?.prompt) {
|
|
21
|
-
throw new Error(`Task ${this.def.name}: no prompt parameter provided. Parameters: ${params}`);
|
|
22
|
+
throw new Error(`Task ${this.def.name}: no prompt parameter provided. Parameters: ${JSON.stringify(params, null, 2)}`);
|
|
22
23
|
}
|
|
23
24
|
let model = this.def.model;
|
|
24
25
|
let ctx = this.def.ctx;
|
|
@@ -40,32 +41,49 @@ class Task {
|
|
|
40
41
|
}
|
|
41
42
|
this.def = applyVariables(this.def, params);
|
|
42
43
|
let tpl = new PromptTemplate("none");
|
|
43
|
-
let finalPrompt;
|
|
44
44
|
const options = {};
|
|
45
|
-
|
|
45
|
+
if (conf?.onToolCall) {
|
|
46
|
+
options.onToolCall = conf.onToolCall;
|
|
47
|
+
}
|
|
48
|
+
if (conf?.onToolCallEnd) {
|
|
49
|
+
options.onToolCallEnd = conf.onToolCallEnd;
|
|
50
|
+
}
|
|
51
|
+
let hasTools = false;
|
|
52
|
+
// add task tools to the agent
|
|
53
|
+
if (this.def?.tools) {
|
|
54
|
+
if (this.def?.tools.length > 0) {
|
|
55
|
+
hasTools = true;
|
|
56
|
+
this.def.tools.forEach(t => {
|
|
57
|
+
this.agent.tools[t.name] = t;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
46
61
|
if (useTemplates) {
|
|
47
62
|
tpl = formatTaskTemplate(this.def, model?.template ? model.template : undefined);
|
|
48
63
|
this.def.inferParams = formatInferParams(this.def.inferParams ?? {}, conf ?? {}, tpl);
|
|
49
64
|
//tpl.replacePrompt(this.def.prompt);
|
|
50
|
-
if (
|
|
65
|
+
if (hasTools) {
|
|
51
66
|
if (!tpl?.toolsDef) {
|
|
52
67
|
throw new Error(`The template ${tpl.name} does not have tools and the task ${this.def.name} specifies some`);
|
|
53
68
|
}
|
|
54
|
-
|
|
69
|
+
this.def.tools?.forEach((t) => tpl.addTool(t));
|
|
55
70
|
}
|
|
56
71
|
;
|
|
57
|
-
finalPrompt = params.prompt;
|
|
72
|
+
//finalPrompt = params.prompt;
|
|
58
73
|
}
|
|
59
74
|
else {
|
|
60
75
|
this.def.inferParams = formatInferParams(this.def.inferParams ?? {}, conf ?? {});
|
|
61
|
-
finalPrompt = this.def.prompt.replace("{prompt}", params.prompt);
|
|
62
76
|
}
|
|
77
|
+
//console.log("DEF", this.def);
|
|
78
|
+
//console.log("P", params.prompt);
|
|
79
|
+
const finalPrompt = this.def.prompt.replace("{prompt}", params.prompt);
|
|
80
|
+
//console.log("FP", finalPrompt);
|
|
63
81
|
// model
|
|
64
82
|
if (model) {
|
|
65
83
|
this.def.inferParams.model = model;
|
|
66
84
|
}
|
|
67
|
-
if (
|
|
68
|
-
options.tools =
|
|
85
|
+
if (hasTools) {
|
|
86
|
+
options.tools = this.def.tools;
|
|
69
87
|
}
|
|
70
88
|
if (conf?.debug) {
|
|
71
89
|
console.log("-----------", model.name, "- Template:", tpl.name, "- Ctx:", ctx, "-----------");
|
|
@@ -87,6 +105,10 @@ class Task {
|
|
|
87
105
|
// cut debug here. TODO: debug log levels
|
|
88
106
|
options.debug = false;
|
|
89
107
|
}
|
|
108
|
+
const isRoutingAgent = this.def.description.includes("routing agent");
|
|
109
|
+
if (isRoutingAgent) {
|
|
110
|
+
options.isToolsRouter = true;
|
|
111
|
+
}
|
|
90
112
|
if (!useTemplates) {
|
|
91
113
|
if (this.def.template?.system) {
|
|
92
114
|
options.system = this.def.template.system;
|
|
@@ -106,12 +128,14 @@ class Task {
|
|
|
106
128
|
//console.log("RAW ANSWER", answer);
|
|
107
129
|
//console.log("\nHISTORY", this.agent.history);
|
|
108
130
|
}
|
|
131
|
+
// remove task tools from the agent
|
|
132
|
+
if (hasTools) {
|
|
133
|
+
this.def.tools?.forEach(t => {
|
|
134
|
+
delete this.agent.tools[t.name];
|
|
135
|
+
});
|
|
136
|
+
}
|
|
109
137
|
//console.log("TASK: ANSWER FINAL:", { answer: answer.result, errors: {}, template: answer.template })
|
|
110
138
|
return { answer, template: tpl };
|
|
111
139
|
}
|
|
112
|
-
addTools(tools) {
|
|
113
|
-
tools.forEach(t => this.agent.tools[t.name] = t);
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
140
|
}
|
|
117
141
|
export { Task };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-smith/task",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A toolkit to create human friendly agents: the language model tasks module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"docs": "typedoc --entryPointStrategy expand"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@agent-smith/agent": "^0.1.
|
|
17
|
+
"@agent-smith/agent": "^0.1.8",
|
|
18
18
|
"@agent-smith/tfm": "^0.2.0",
|
|
19
19
|
"modprompt": "^0.12.6",
|
|
20
20
|
"yaml": "^2.8.2"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@locallm/api": "^0.7.3",
|
|
24
24
|
"openai": "6.15.0",
|
|
25
|
-
"@locallm/types": "^0.6.
|
|
25
|
+
"@locallm/types": "^0.6.7",
|
|
26
26
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
27
27
|
"@rollup/plugin-terser": "^0.4.4",
|
|
28
28
|
"@rollup/plugin-typescript": "^12.3.0",
|