@agent-smith/agent 0.3.0 → 0.3.2

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/agent.js CHANGED
@@ -148,8 +148,32 @@ class Agent {
148
148
  throw new Error(`error processing model answer:\n, ${error}`);
149
149
  }
150
150
  if (assistant) {
151
- if (options?.onAssistant) {
152
- options.onAssistant(assistant);
151
+ if (tpl.tags?.think?.start) {
152
+ let t = res.text;
153
+ if (toolsCall.length > 0) {
154
+ if (tpl?.tags?.toolCall?.start) {
155
+ t = res.text.split(tpl.tags.toolCall.start)[0].trim();
156
+ }
157
+ else {
158
+ console.warn("Model called tools but not tool call tags found in template");
159
+ }
160
+ }
161
+ const { think, finalAnswer } = splitThinking(t, tpl.tags.think.start, tpl.tags.think.end);
162
+ if (think.length > 0) {
163
+ if (options?.onThink) {
164
+ options.onThink(think);
165
+ }
166
+ }
167
+ if (finalAnswer.length > 0) {
168
+ if (options?.onAssistant) {
169
+ options.onAssistant(finalAnswer);
170
+ }
171
+ }
172
+ }
173
+ else {
174
+ if (options?.onAssistant) {
175
+ options.onAssistant(assistant);
176
+ }
153
177
  }
154
178
  }
155
179
  const toolResults = new Array();
@@ -210,13 +234,23 @@ class Agent {
210
234
  if (options?.onToolsTurnEnd) {
211
235
  options.onToolsTurnEnd(toolResults);
212
236
  }
237
+ let thinking = "";
238
+ let final = "";
239
+ if (tpl?.tags?.think) {
240
+ const { think, finalAnswer } = splitThinking(res.text, tpl.tags.think.start, tpl.tags.think.end);
241
+ thinking = think;
242
+ final = finalAnswer;
243
+ }
213
244
  if (it == 1) {
214
245
  const t = {
215
246
  user: prompt,
216
247
  tools: toolResults,
217
248
  };
218
249
  if (assistant) {
219
- t.assistant = assistant;
250
+ t.assistant = final;
251
+ }
252
+ if (thinking.length > 0) {
253
+ t.think = thinking;
220
254
  }
221
255
  this.history.push(t);
222
256
  }
@@ -225,7 +259,10 @@ class Agent {
225
259
  tools: toolResults,
226
260
  };
227
261
  if (assistant) {
228
- t.assistant = assistant;
262
+ t.assistant = final;
263
+ }
264
+ if (thinking.length > 0) {
265
+ t.think = thinking;
229
266
  }
230
267
  this.history.push(t);
231
268
  }
package/dist/utils.js CHANGED
@@ -26,7 +26,7 @@ function splitThinking(text, startTag, endTag) {
26
26
  let answer = "";
27
27
  const st = text.split(endTag);
28
28
  if (st.length > 1) {
29
- think = extractBetweenTags(text, startTag, endTag);
29
+ think = extractBetweenTags(text, startTag, endTag).trim();
30
30
  answer = st[1].trim();
31
31
  }
32
32
  else {
package/package.json CHANGED
@@ -5,22 +5,22 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/synw/agent-smith.git"
7
7
  },
8
- "version": "0.3.0",
8
+ "version": "0.3.2",
9
9
  "scripts": {
10
10
  "buildrl": "rm -rf dist/* && rollup -c",
11
11
  "build": "rm -rf dist/* && tsc"
12
12
  },
13
13
  "dependencies": {
14
14
  "@locallm/api": "^0.7.3",
15
- "modprompt": "^0.14.0",
15
+ "modprompt": "^0.14.1",
16
16
  "restmix": "^0.6.1"
17
17
  },
18
18
  "devDependencies": {
19
- "@locallm/types": "^0.7.0",
19
+ "@locallm/types": "^0.7.1",
20
20
  "@rollup/plugin-node-resolve": "^16.0.3",
21
21
  "@rollup/plugin-typescript": "^12.3.0",
22
22
  "@types/node": "^25.3.0",
23
- "openai": "^6.22.0",
23
+ "openai": "^6.24.0",
24
24
  "rollup": "^4.59.0",
25
25
  "ts-node": "^10.9.2",
26
26
  "tslib": "2.8.1",