@agent-smith/agent 0.0.1 → 0.0.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 +2 -1
- package/dist/agent.js +39 -16
- package/package.json +6 -3
package/dist/agent.d.ts
CHANGED
|
@@ -6,11 +6,12 @@ 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): Promise<InferenceResult>;
|
|
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
11
|
runAgentWithTemplate(it: number, prompt: string, params: InferenceParams, options: InferenceOptions | undefined, tpl: PromptTemplate): Promise<{
|
|
12
12
|
inferenceResult: InferenceResult;
|
|
13
13
|
template: PromptTemplate;
|
|
14
14
|
}>;
|
|
15
|
+
abort(): Promise<void>;
|
|
15
16
|
}
|
|
16
17
|
export { Agent, };
|
package/dist/agent.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PromptTemplate } from 'modprompt';
|
|
1
2
|
class Agent {
|
|
2
3
|
lm;
|
|
3
4
|
tools = {};
|
|
@@ -6,23 +7,41 @@ class Agent {
|
|
|
6
7
|
this.lm = lm;
|
|
7
8
|
}
|
|
8
9
|
async run(prompt, params, options = {}, template) {
|
|
9
|
-
|
|
10
|
-
if (options?.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
});
|
|
10
|
+
let tpl;
|
|
11
|
+
if (options?.debug) {
|
|
12
|
+
console.log("Agent inference params:", params);
|
|
13
|
+
console.log("Agent options:", options);
|
|
14
|
+
console.log("Agent template:", template);
|
|
15
|
+
console.log("Prompt:", prompt);
|
|
17
16
|
}
|
|
18
17
|
if (this.lm.providerType == "openai") {
|
|
19
18
|
return await this.runAgentNoTemplate(1, prompt, params, options);
|
|
20
19
|
}
|
|
21
20
|
else {
|
|
22
21
|
if (!template) {
|
|
23
|
-
|
|
22
|
+
if (params?.template) {
|
|
23
|
+
tpl = new PromptTemplate(params.template);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error(`A template is required for provider ${this.lm.provider.name}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
if (typeof template == "string") {
|
|
31
|
+
tpl = new PromptTemplate(template);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
tpl = template;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this.tools = {};
|
|
38
|
+
if (options?.tools) {
|
|
39
|
+
options.tools.forEach(t => {
|
|
40
|
+
this.tools[t.name] = t;
|
|
41
|
+
tpl = tpl.addTool(t);
|
|
42
|
+
});
|
|
24
43
|
}
|
|
25
|
-
return (await this.runAgentWithTemplate(1, prompt, params, options,
|
|
44
|
+
return (await this.runAgentWithTemplate(1, prompt, params, options, tpl)).inferenceResult;
|
|
26
45
|
}
|
|
27
46
|
}
|
|
28
47
|
async runAgentNoTemplate(it, prompt, params, options = {}) {
|
|
@@ -72,17 +91,18 @@ class Agent {
|
|
|
72
91
|
return _res;
|
|
73
92
|
}
|
|
74
93
|
async runAgentWithTemplate(it, prompt, params, options = {}, tpl) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
console.log("Provider:", this.lm.provider);
|
|
95
|
+
if (this.lm.providerType == "ollama") {
|
|
96
|
+
if (!params?.model) {
|
|
97
|
+
throw new Error("A model inference parameters is required for provider Ollama");
|
|
98
|
+
}
|
|
99
|
+
await this.lm.loadModel(params.model.name, params.model.ctx);
|
|
80
100
|
}
|
|
101
|
+
let res = await this.lm.infer(tpl.prompt(prompt), params, options);
|
|
81
102
|
const { isToolCall, toolsCall, error } = tpl.processAnswer(res.text);
|
|
82
103
|
if (error) {
|
|
83
104
|
throw new Error(`error processing tool call answer:\n, ${error}`);
|
|
84
105
|
}
|
|
85
|
-
console.log("\nProcessed answer", isToolCall, toolsCall, error);
|
|
86
106
|
const toolResults = new Array();
|
|
87
107
|
if (isToolCall) {
|
|
88
108
|
for (const toolCall of toolsCall) {
|
|
@@ -139,5 +159,8 @@ class Agent {
|
|
|
139
159
|
return { inferenceResult: res, template: tpl };
|
|
140
160
|
}
|
|
141
161
|
}
|
|
162
|
+
async abort() {
|
|
163
|
+
this.lm.abort();
|
|
164
|
+
}
|
|
142
165
|
}
|
|
143
166
|
export { Agent, };
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-smith/agent",
|
|
3
3
|
"description": "Agent Smith: agent runtime",
|
|
4
|
-
"repository":
|
|
5
|
-
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/synw/agent-smith.git"
|
|
7
|
+
},
|
|
8
|
+
"version": "0.0.3",
|
|
6
9
|
"scripts": {
|
|
7
10
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
11
|
"build": "rm -rf dist/* && tsc"
|
|
@@ -15,7 +18,7 @@
|
|
|
15
18
|
"@locallm/types": "^0.4.2",
|
|
16
19
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
17
20
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
18
|
-
"@types/node": "^24.
|
|
21
|
+
"@types/node": "^24.4.0",
|
|
19
22
|
"rollup": "^4.50.1",
|
|
20
23
|
"ts-node": "^10.9.2",
|
|
21
24
|
"tslib": "2.8.1",
|