@agent-smith/agent 0.1.0 → 0.1.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.d.ts +5 -2
- package/dist/agent.js +21 -6
- package/dist/main.d.ts +2 -1
- package/dist/main.js +2 -1
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +37 -0
- package/package.json +5 -5
package/dist/agent.d.ts
CHANGED
|
@@ -6,10 +6,13 @@ declare class Agent {
|
|
|
6
6
|
tools: Record<string, ToolSpec>;
|
|
7
7
|
history: Array<HistoryTurn>;
|
|
8
8
|
constructor(lm: Lm);
|
|
9
|
-
run(prompt: string, params: InferenceParams, options?: InferenceOptions, template?: PromptTemplate | string): Promise<
|
|
9
|
+
run(prompt: string, params: InferenceParams, options?: InferenceOptions, template?: PromptTemplate | string): Promise<{
|
|
10
|
+
result: InferenceResult;
|
|
11
|
+
template: PromptTemplate;
|
|
12
|
+
}>;
|
|
10
13
|
runAgentNoTemplate(it: number, prompt: string, params: InferenceParams, options?: InferenceOptions): Promise<InferenceResult>;
|
|
11
14
|
runAgentWithTemplate(it: number, prompt: string, params: InferenceParams, options: InferenceOptions | undefined, tpl: PromptTemplate): Promise<{
|
|
12
|
-
|
|
15
|
+
result: InferenceResult;
|
|
13
16
|
template: PromptTemplate;
|
|
14
17
|
}>;
|
|
15
18
|
abort(): Promise<void>;
|
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
|
-
|
|
23
|
+
const res = await this.runAgentNoTemplate(1, prompt, params, options);
|
|
24
|
+
return { result: res, template: new PromptTemplate("none") };
|
|
23
25
|
}
|
|
24
26
|
else {
|
|
25
27
|
if (!template) {
|
|
@@ -45,7 +47,7 @@ class Agent {
|
|
|
45
47
|
tpl = tpl.addTool(t);
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
|
-
return (await this.runAgentWithTemplate(1, prompt, params, options, tpl))
|
|
50
|
+
return (await this.runAgentWithTemplate(1, prompt, params, options, tpl));
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
async runAgentNoTemplate(it, prompt, params, options = {}) {
|
|
@@ -87,7 +89,6 @@ class Agent {
|
|
|
87
89
|
options.verbose = true;
|
|
88
90
|
}
|
|
89
91
|
options.history = this.history;
|
|
90
|
-
console.dir(options.history, { depth: 8 });
|
|
91
92
|
_res = await this.runAgentNoTemplate(nit, " ", params, options);
|
|
92
93
|
}
|
|
93
94
|
else {
|
|
@@ -152,18 +153,32 @@ class Agent {
|
|
|
152
153
|
return await this.runAgentWithTemplate(it + 1, prompt, params, options, tpl);
|
|
153
154
|
}
|
|
154
155
|
else {
|
|
156
|
+
let thinking = "";
|
|
157
|
+
let final = res.text;
|
|
158
|
+
if (tpl?.tags?.think) {
|
|
159
|
+
const { think, finalAnswer } = splitThinking(res.text, tpl.tags.think.start, tpl.tags.think.end);
|
|
160
|
+
thinking = think;
|
|
161
|
+
final = finalAnswer;
|
|
162
|
+
}
|
|
155
163
|
if (it == 1) {
|
|
164
|
+
if (thinking.length > 0) {
|
|
165
|
+
tpl.pushToHistory({ think: thinking });
|
|
166
|
+
}
|
|
156
167
|
tpl.pushToHistory({
|
|
157
168
|
user: prompt.replace("{prompt}", prompt),
|
|
158
|
-
assistant:
|
|
169
|
+
assistant: final,
|
|
159
170
|
});
|
|
160
171
|
}
|
|
161
172
|
else {
|
|
173
|
+
if (thinking.length > 0) {
|
|
174
|
+
tpl.pushToHistory({ think: thinking });
|
|
175
|
+
}
|
|
162
176
|
tpl.pushToHistory({
|
|
163
|
-
assistant:
|
|
177
|
+
assistant: final,
|
|
164
178
|
});
|
|
165
179
|
}
|
|
166
|
-
|
|
180
|
+
this.history = tpl.history;
|
|
181
|
+
return { result: res, template: tpl };
|
|
167
182
|
}
|
|
168
183
|
}
|
|
169
184
|
async abort() {
|
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
package/dist/utils.d.ts
ADDED
|
@@ -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.
|
|
8
|
+
"version": "0.1.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
|
-
"@locallm/api": "^0.6.
|
|
15
|
-
"modprompt": "^0.12.
|
|
14
|
+
"@locallm/api": "^0.6.2",
|
|
15
|
+
"modprompt": "^0.12.5",
|
|
16
16
|
"restmix": "^0.5.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@locallm/types": "^0.
|
|
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.
|
|
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",
|