@agent-smith/agent 0.1.1 → 0.1.3

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.d.ts CHANGED
@@ -8,10 +8,7 @@ declare class Agent {
8
8
  constructor(lm: Lm);
9
9
  run(prompt: string, params: InferenceParams, options?: InferenceOptions, template?: PromptTemplate | string): Promise<InferenceResult>;
10
10
  runAgentNoTemplate(it: number, prompt: string, params: InferenceParams, options?: InferenceOptions): Promise<InferenceResult>;
11
- runAgentWithTemplate(it: number, prompt: string, params: InferenceParams, options: InferenceOptions | undefined, tpl: PromptTemplate): Promise<{
12
- inferenceResult: InferenceResult;
13
- template: PromptTemplate;
14
- }>;
11
+ runAgentWithTemplate(it: number, prompt: string, params: InferenceParams, options: InferenceOptions | undefined, tpl: PromptTemplate): Promise<InferenceResult>;
15
12
  abort(): Promise<void>;
16
13
  }
17
14
  export { Agent, };
package/dist/agent.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { PromptTemplate } from 'modprompt';
2
+ import { splitThinking } from "./utils.js";
2
3
  class Agent {
3
4
  lm;
4
5
  tools = {};
@@ -19,7 +20,8 @@ class Agent {
19
20
  this.tools[t.name] = t;
20
21
  });
21
22
  }
22
- return await this.runAgentNoTemplate(1, prompt, params, options);
23
+ const res = await this.runAgentNoTemplate(1, prompt, params, options);
24
+ return res;
23
25
  }
24
26
  else {
25
27
  if (!template) {
@@ -45,7 +47,8 @@ class Agent {
45
47
  tpl = tpl.addTool(t);
46
48
  });
47
49
  }
48
- return (await this.runAgentWithTemplate(1, prompt, params, options, tpl)).inferenceResult;
50
+ const res = await this.runAgentWithTemplate(1, prompt, params, options, tpl);
51
+ return res;
49
52
  }
50
53
  }
51
54
  async runAgentNoTemplate(it, prompt, params, options = {}) {
@@ -87,7 +90,6 @@ class Agent {
87
90
  options.verbose = true;
88
91
  }
89
92
  options.history = this.history;
90
- console.dir(options.history, { depth: 8 });
91
93
  _res = await this.runAgentNoTemplate(nit, " ", params, options);
92
94
  }
93
95
  else {
@@ -152,18 +154,32 @@ class Agent {
152
154
  return await this.runAgentWithTemplate(it + 1, prompt, params, options, tpl);
153
155
  }
154
156
  else {
157
+ let thinking = "";
158
+ let final = res.text;
159
+ if (tpl?.tags?.think) {
160
+ const { think, finalAnswer } = splitThinking(res.text, tpl.tags.think.start, tpl.tags.think.end);
161
+ thinking = think;
162
+ final = finalAnswer;
163
+ }
155
164
  if (it == 1) {
165
+ if (thinking.length > 0) {
166
+ tpl.pushToHistory({ think: thinking });
167
+ }
156
168
  tpl.pushToHistory({
157
169
  user: prompt.replace("{prompt}", prompt),
158
- assistant: res.text,
170
+ assistant: final,
159
171
  });
160
172
  }
161
173
  else {
174
+ if (thinking.length > 0) {
175
+ tpl.pushToHistory({ think: thinking });
176
+ }
162
177
  tpl.pushToHistory({
163
- assistant: res.text,
178
+ assistant: final,
164
179
  });
165
180
  }
166
- return { inferenceResult: res, template: tpl };
181
+ this.history = tpl.history;
182
+ return res;
167
183
  }
168
184
  }
169
185
  async abort() {
package/dist/main.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { Agent } from "./agent.js";
2
- export { Agent, };
2
+ import { extractBetweenTags, splitThinking } from "./utils.js";
3
+ export { Agent, extractBetweenTags, splitThinking, };
package/dist/main.js CHANGED
@@ -1,2 +1,3 @@
1
1
  import { Agent } from "./agent.js";
2
- export { Agent, };
2
+ import { extractBetweenTags, splitThinking } from "./utils.js";
3
+ export { Agent, extractBetweenTags, splitThinking, };
@@ -0,0 +1,6 @@
1
+ declare function extractBetweenTags(text: string, startTag: string, endTag: string): string;
2
+ declare function splitThinking(text: string, startTag: string, endTag: string): {
3
+ think: string;
4
+ finalAnswer: string;
5
+ };
6
+ export { extractBetweenTags, splitThinking, };
package/dist/utils.js ADDED
@@ -0,0 +1,37 @@
1
+ function extractBetweenTags(text, startTag, endTag) {
2
+ try {
3
+ const startIndex = text.indexOf(startTag);
4
+ if (startIndex === -1)
5
+ return text;
6
+ let contentStart = startIndex + startTag.length;
7
+ let contentEnd;
8
+ if (endTag) {
9
+ contentEnd = text.indexOf(endTag, contentStart);
10
+ if (contentEnd === -1)
11
+ return text;
12
+ }
13
+ else {
14
+ contentEnd = text.indexOf('\n', contentStart);
15
+ if (contentEnd === -1)
16
+ contentEnd = text.length;
17
+ }
18
+ return text.substring(contentStart, contentEnd).trim();
19
+ }
20
+ catch (error) {
21
+ throw new Error(`Error parsing content between tags ${startTag} ${endTag}: ${error}`);
22
+ }
23
+ }
24
+ function splitThinking(text, startTag, endTag) {
25
+ let think = "";
26
+ let answer = "";
27
+ const st = text.split(endTag);
28
+ if (st.length > 1) {
29
+ think = extractBetweenTags(text, startTag, endTag);
30
+ answer = st[1].trim();
31
+ }
32
+ else {
33
+ answer = text;
34
+ }
35
+ return { think: think, finalAnswer: answer };
36
+ }
37
+ export { extractBetweenTags, splitThinking, };
package/package.json CHANGED
@@ -5,21 +5,21 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/synw/agent-smith.git"
7
7
  },
8
- "version": "0.1.1",
8
+ "version": "0.1.3",
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.6.2",
15
- "modprompt": "^0.12.3",
15
+ "modprompt": "^0.12.5",
16
16
  "restmix": "^0.5.0"
17
17
  },
18
18
  "devDependencies": {
19
- "@locallm/types": "^0.4.2",
19
+ "@locallm/types": "^0.5.0",
20
20
  "@rollup/plugin-node-resolve": "^16.0.3",
21
21
  "@rollup/plugin-typescript": "^12.3.0",
22
- "@types/node": "^24.10.0",
22
+ "@types/node": "^24.10.1",
23
23
  "rollup": "^4.53.2",
24
24
  "ts-node": "^10.9.2",
25
25
  "tslib": "2.8.1",