@agent-smith/agent 0.1.6 → 0.1.8
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 +41 -16
- package/package.json +2 -2
package/dist/agent.js
CHANGED
|
@@ -58,7 +58,9 @@ class Agent {
|
|
|
58
58
|
async runAgentNoTemplate(it, prompt, params, options = {}) {
|
|
59
59
|
options.history = this.history;
|
|
60
60
|
const res = await this.lm.infer(prompt, params, options);
|
|
61
|
-
|
|
61
|
+
if (it == 1) {
|
|
62
|
+
this.history.push({ user: prompt });
|
|
63
|
+
}
|
|
62
64
|
let _res = res;
|
|
63
65
|
if (res?.toolCalls) {
|
|
64
66
|
const toolsResults = new Array();
|
|
@@ -73,11 +75,17 @@ class Agent {
|
|
|
73
75
|
canRun = await tool.canRun(tool);
|
|
74
76
|
}
|
|
75
77
|
if (canRun) {
|
|
78
|
+
if (options?.onToolCall) {
|
|
79
|
+
options.onToolCall(tc);
|
|
80
|
+
}
|
|
76
81
|
const toolCallResult = await tool.execute(tc.arguments);
|
|
77
82
|
if (options?.debug || options?.verbose) {
|
|
78
83
|
console.log("[x] Executed tool", tool.name + ":", toolCallResult);
|
|
79
84
|
}
|
|
80
|
-
toolsResults.push({ call: tc, response: toolCallResult });
|
|
85
|
+
toolsResults.push({ call: tc, response: JSON.stringify(toolCallResult) });
|
|
86
|
+
if (options?.onToolCallEnd) {
|
|
87
|
+
options.onToolCallEnd(toolCallResult);
|
|
88
|
+
}
|
|
81
89
|
}
|
|
82
90
|
else {
|
|
83
91
|
if (options?.debug || options?.verbose) {
|
|
@@ -90,11 +98,7 @@ class Agent {
|
|
|
90
98
|
options.tools = Object.values(this.tools);
|
|
91
99
|
}
|
|
92
100
|
const nit = it + 1;
|
|
93
|
-
|
|
94
|
-
options.debug = false;
|
|
95
|
-
options.verbose = true;
|
|
96
|
-
}
|
|
97
|
-
_res = await this.runAgentNoTemplate(nit, " ", params, options);
|
|
101
|
+
_res = await this.runAgentNoTemplate(nit, "", params, options);
|
|
98
102
|
}
|
|
99
103
|
else {
|
|
100
104
|
this.history.push({ assistant: res.text });
|
|
@@ -132,17 +136,38 @@ class Agent {
|
|
|
132
136
|
const buf = new Array(`wrong tool call ${toolCall.name} from the model:`, JSON.stringify(toolCall, null, " "), `It does not exist in the tools list:. Available tools:`, JSON.stringify(Object.keys(this.tools), null, " "));
|
|
133
137
|
throw new Error(buf.join("\n"));
|
|
134
138
|
}
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
let canRun = true;
|
|
140
|
+
if (tool?.canRun) {
|
|
141
|
+
canRun = await tool.canRun(tool);
|
|
137
142
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
if (!canRun) {
|
|
144
|
+
if (options?.debug || options?.verbose) {
|
|
145
|
+
console.log("[-] Tool", tool.name, "execution refused");
|
|
146
|
+
}
|
|
147
|
+
toolResults.push({
|
|
148
|
+
call: toolCall,
|
|
149
|
+
response: "tool execution denied"
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
if (options?.onToolCall) {
|
|
154
|
+
options.onToolCall(toolCall);
|
|
155
|
+
}
|
|
156
|
+
if (options?.debug === true) {
|
|
157
|
+
console.log("\n=> Calling tool", tool.name + ":", toolCall.arguments);
|
|
158
|
+
}
|
|
159
|
+
const toolResp = await tool.execute(toolCall.arguments);
|
|
160
|
+
if (options?.debug) {
|
|
161
|
+
console.log("[x] Executed tool", tool.name + ":", toolResp);
|
|
162
|
+
}
|
|
163
|
+
toolResults.push({
|
|
164
|
+
call: toolCall,
|
|
165
|
+
response: toolResp
|
|
166
|
+
});
|
|
167
|
+
if (options?.onToolCallEnd) {
|
|
168
|
+
options.onToolCallEnd(toolResp);
|
|
169
|
+
}
|
|
141
170
|
}
|
|
142
|
-
toolResults.push({
|
|
143
|
-
call: toolCall,
|
|
144
|
-
response: toolResp
|
|
145
|
-
});
|
|
146
171
|
}
|
|
147
172
|
if (it == 1) {
|
|
148
173
|
this.history.push({
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
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.8",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
11
11
|
"build": "rm -rf dist/* && tsc"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"restmix": "^0.6.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@locallm/types": "^0.6.
|
|
19
|
+
"@locallm/types": "^0.6.5",
|
|
20
20
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
21
21
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
22
22
|
"@types/node": "^25.0.3",
|