@agent-smith/task 0.1.9 → 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 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;
@@ -47,16 +48,25 @@ class Task {
47
48
  if (conf?.onToolCallEnd) {
48
49
  options.onToolCallEnd = conf.onToolCallEnd;
49
50
  }
50
- const agentToolsList = Object.values(this.agent.tools);
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
+ }
51
61
  if (useTemplates) {
52
62
  tpl = formatTaskTemplate(this.def, model?.template ? model.template : undefined);
53
63
  this.def.inferParams = formatInferParams(this.def.inferParams ?? {}, conf ?? {}, tpl);
54
64
  //tpl.replacePrompt(this.def.prompt);
55
- if (agentToolsList.length > 0) {
65
+ if (hasTools) {
56
66
  if (!tpl?.toolsDef) {
57
67
  throw new Error(`The template ${tpl.name} does not have tools and the task ${this.def.name} specifies some`);
58
68
  }
59
- agentToolsList.forEach((t) => tpl.addTool(t));
69
+ this.def.tools?.forEach((t) => tpl.addTool(t));
60
70
  }
61
71
  ;
62
72
  //finalPrompt = params.prompt;
@@ -72,8 +82,8 @@ class Task {
72
82
  if (model) {
73
83
  this.def.inferParams.model = model;
74
84
  }
75
- if (agentToolsList.length > 0) {
76
- options.tools = agentToolsList;
85
+ if (hasTools) {
86
+ options.tools = this.def.tools;
77
87
  }
78
88
  if (conf?.debug) {
79
89
  console.log("-----------", model.name, "- Template:", tpl.name, "- Ctx:", ctx, "-----------");
@@ -95,6 +105,10 @@ class Task {
95
105
  // cut debug here. TODO: debug log levels
96
106
  options.debug = false;
97
107
  }
108
+ const isRoutingAgent = this.def.description.includes("routing agent");
109
+ if (isRoutingAgent) {
110
+ options.isToolsRouter = true;
111
+ }
98
112
  if (!useTemplates) {
99
113
  if (this.def.template?.system) {
100
114
  options.system = this.def.template.system;
@@ -114,12 +128,14 @@ class Task {
114
128
  //console.log("RAW ANSWER", answer);
115
129
  //console.log("\nHISTORY", this.agent.history);
116
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
+ }
117
137
  //console.log("TASK: ANSWER FINAL:", { answer: answer.result, errors: {}, template: answer.template })
118
138
  return { answer, template: tpl };
119
139
  }
120
- addTools(tools) {
121
- tools.forEach(t => this.agent.tools[t.name] = t);
122
- return this;
123
- }
124
140
  }
125
141
  export { Task };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-smith/task",
3
- "version": "0.1.9",
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",
@@ -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.5",
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",