@sisu-ai/mw-tool-calling 9.0.5 → 11.0.0
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/README.md +30 -1
- package/dist/index.js +50 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -88,6 +88,22 @@ agent.use(toolCalling);
|
|
|
88
88
|
agent.use(iterativeToolCalling);
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
## Tool Execution Records
|
|
92
|
+
|
|
93
|
+
Each executed tool call is appended to `ctx.state.toolExecutions`:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
type ToolExecutionRecord = {
|
|
97
|
+
aliasName: string;
|
|
98
|
+
canonicalName: string;
|
|
99
|
+
callId?: string;
|
|
100
|
+
args: unknown;
|
|
101
|
+
result: unknown;
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
This is useful for diagnostics and post-run inspection without manually parsing `tool` messages.
|
|
106
|
+
|
|
91
107
|
# Community & Support
|
|
92
108
|
|
|
93
109
|
Discover what you can do through examples or documentation. Check it out at https://github.com/finger-gun/sisu. Example projects live under [`examples/`](https://github.com/finger-gun/sisu/tree/main/examples) in the repo.
|
|
@@ -133,9 +149,9 @@ Discover what you can do through examples or documentation. Check it out at http
|
|
|
133
149
|
- [@sisu-ai/tool-azure-blob](packages/tools/azure-blob/README.md)
|
|
134
150
|
- [@sisu-ai/tool-extract-urls](packages/tools/extract-urls/README.md)
|
|
135
151
|
- [@sisu-ai/tool-github-projects](packages/tools/github-projects/README.md)
|
|
152
|
+
- [@sisu-ai/tool-rag](packages/tools/rag/README.md)
|
|
136
153
|
- [@sisu-ai/tool-summarize-text](packages/tools/summarize-text/README.md)
|
|
137
154
|
- [@sisu-ai/tool-terminal](packages/tools/terminal/README.md)
|
|
138
|
-
- [@sisu-ai/tool-vec-chroma](packages/tools/vec-chroma/README.md)
|
|
139
155
|
- [@sisu-ai/tool-web-fetch](packages/tools/web-fetch/README.md)
|
|
140
156
|
- [@sisu-ai/tool-web-search-duckduckgo](packages/tools/web-search-duckduckgo/README.md)
|
|
141
157
|
- [@sisu-ai/tool-web-search-google](packages/tools/web-search-google/README.md)
|
|
@@ -143,6 +159,19 @@ Discover what you can do through examples or documentation. Check it out at http
|
|
|
143
159
|
- [@sisu-ai/tool-wikipedia](packages/tools/wikipedia/README.md)
|
|
144
160
|
</details>
|
|
145
161
|
|
|
162
|
+
<details>
|
|
163
|
+
<summary>All RAG packages</summary>
|
|
164
|
+
|
|
165
|
+
- [@sisu-ai/rag-core](packages/rag/core/README.md)
|
|
166
|
+
</details>
|
|
167
|
+
|
|
168
|
+
<details>
|
|
169
|
+
<summary>All vector packages</summary>
|
|
170
|
+
|
|
171
|
+
- [@sisu-ai/vector-core](packages/vector/core/README.md)
|
|
172
|
+
- [@sisu-ai/vector-chroma](packages/vector/chroma/README.md)
|
|
173
|
+
</details>
|
|
174
|
+
|
|
146
175
|
<details>
|
|
147
176
|
<summary>All examples</summary>
|
|
148
177
|
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
function pushToolExecution(ctx, record) {
|
|
2
|
+
const existing = ctx.state.toolExecutions;
|
|
3
|
+
if (Array.isArray(existing)) {
|
|
4
|
+
existing.push(record);
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
ctx.state.toolExecutions = [record];
|
|
8
|
+
}
|
|
1
9
|
/**
|
|
2
10
|
* Apply user-configured aliases to tools before passing to adapter.
|
|
3
11
|
* Creates new tool objects with aliased names while keeping originals in registry.
|
|
@@ -36,6 +44,28 @@ function hasParseSchema(schema) {
|
|
|
36
44
|
const maybeSchema = schema;
|
|
37
45
|
return typeof maybeSchema.parse === "function";
|
|
38
46
|
}
|
|
47
|
+
function normalizeToolArguments(args) {
|
|
48
|
+
if (typeof args !== "string") {
|
|
49
|
+
return args;
|
|
50
|
+
}
|
|
51
|
+
let current = args;
|
|
52
|
+
for (let i = 0; i < 2; i++) {
|
|
53
|
+
if (typeof current !== "string") {
|
|
54
|
+
return current;
|
|
55
|
+
}
|
|
56
|
+
const trimmed = current.trim();
|
|
57
|
+
if (!trimmed) {
|
|
58
|
+
return args;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
current = JSON.parse(trimmed);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return current;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return current;
|
|
68
|
+
}
|
|
39
69
|
export const toolCalling = async (ctx, next) => {
|
|
40
70
|
await next();
|
|
41
71
|
const toolList = ctx.tools.list();
|
|
@@ -93,9 +123,10 @@ export const toolCalling = async (ctx, next) => {
|
|
|
93
123
|
let result = cache.get(key);
|
|
94
124
|
if (result === undefined) {
|
|
95
125
|
const schema = tool.schema;
|
|
126
|
+
const normalizedArgs = normalizeToolArguments(call.arguments);
|
|
96
127
|
const args = hasParseSchema(schema)
|
|
97
|
-
? schema.parse(
|
|
98
|
-
:
|
|
128
|
+
? schema.parse(normalizedArgs)
|
|
129
|
+
: normalizedArgs;
|
|
99
130
|
ctx.log.debug?.("[tool-calling] invoking tool", {
|
|
100
131
|
aliasName: call.name,
|
|
101
132
|
canonicalName: canonicalName,
|
|
@@ -125,6 +156,13 @@ export const toolCalling = async (ctx, next) => {
|
|
|
125
156
|
...(call.id ? { tool_call_id: call.id } : { name: call.name }),
|
|
126
157
|
};
|
|
127
158
|
ctx.messages.push(toolMsg);
|
|
159
|
+
pushToolExecution(ctx, {
|
|
160
|
+
aliasName: call.name,
|
|
161
|
+
canonicalName,
|
|
162
|
+
callId: call.id,
|
|
163
|
+
args: lastArgsByName.get(call.name),
|
|
164
|
+
result,
|
|
165
|
+
});
|
|
128
166
|
ctx.log.debug?.("[tool-calling] tool result appended", {
|
|
129
167
|
name: call.name,
|
|
130
168
|
id: call.id,
|
|
@@ -190,9 +228,10 @@ export const iterativeToolCalling = async (ctx, next) => {
|
|
|
190
228
|
let result = cache.get(key);
|
|
191
229
|
if (result === undefined) {
|
|
192
230
|
const schema = tool.schema;
|
|
231
|
+
const normalizedArgs = normalizeToolArguments(call.arguments);
|
|
193
232
|
const args = hasParseSchema(schema)
|
|
194
|
-
? schema.parse(
|
|
195
|
-
:
|
|
233
|
+
? schema.parse(normalizedArgs)
|
|
234
|
+
: normalizedArgs;
|
|
196
235
|
ctx.log.debug?.("[iterative-tool-calling] invoking tool", {
|
|
197
236
|
aliasName: call.name,
|
|
198
237
|
canonicalName: canonicalName,
|
|
@@ -224,6 +263,13 @@ export const iterativeToolCalling = async (ctx, next) => {
|
|
|
224
263
|
...(call.id ? { tool_call_id: call.id } : { name: call.name }),
|
|
225
264
|
};
|
|
226
265
|
ctx.messages.push(toolMsg);
|
|
266
|
+
pushToolExecution(ctx, {
|
|
267
|
+
aliasName: call.name,
|
|
268
|
+
canonicalName,
|
|
269
|
+
callId: call.id,
|
|
270
|
+
args: lastArgsByName.get(call.name),
|
|
271
|
+
result,
|
|
272
|
+
});
|
|
227
273
|
}
|
|
228
274
|
continue; // next round may call more tools
|
|
229
275
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sisu-ai/mw-tool-calling",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@sisu-ai/core": "^2.
|
|
15
|
+
"@sisu-ai/core": "^2.5.0"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|