@sisu-ai/mw-tool-calling 9.0.4 → 10.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 +61 -6
- 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.
|
|
@@ -29,6 +37,35 @@ function applyAliasesToTools(tools, aliasMap) {
|
|
|
29
37
|
}
|
|
30
38
|
return { aliasedTools, reverseMap };
|
|
31
39
|
}
|
|
40
|
+
function hasParseSchema(schema) {
|
|
41
|
+
if (!schema || typeof schema !== "object") {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const maybeSchema = schema;
|
|
45
|
+
return typeof maybeSchema.parse === "function";
|
|
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
|
+
}
|
|
32
69
|
export const toolCalling = async (ctx, next) => {
|
|
33
70
|
await next();
|
|
34
71
|
const toolList = ctx.tools.list();
|
|
@@ -85,9 +122,11 @@ export const toolCalling = async (ctx, next) => {
|
|
|
85
122
|
const key = keyOf(call);
|
|
86
123
|
let result = cache.get(key);
|
|
87
124
|
if (result === undefined) {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
125
|
+
const schema = tool.schema;
|
|
126
|
+
const normalizedArgs = normalizeToolArguments(call.arguments);
|
|
127
|
+
const args = hasParseSchema(schema)
|
|
128
|
+
? schema.parse(normalizedArgs)
|
|
129
|
+
: normalizedArgs;
|
|
91
130
|
ctx.log.debug?.("[tool-calling] invoking tool", {
|
|
92
131
|
aliasName: call.name,
|
|
93
132
|
canonicalName: canonicalName,
|
|
@@ -117,6 +156,13 @@ export const toolCalling = async (ctx, next) => {
|
|
|
117
156
|
...(call.id ? { tool_call_id: call.id } : { name: call.name }),
|
|
118
157
|
};
|
|
119
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
|
+
});
|
|
120
166
|
ctx.log.debug?.("[tool-calling] tool result appended", {
|
|
121
167
|
name: call.name,
|
|
122
168
|
id: call.id,
|
|
@@ -181,9 +227,11 @@ export const iterativeToolCalling = async (ctx, next) => {
|
|
|
181
227
|
const key = keyOf(call);
|
|
182
228
|
let result = cache.get(key);
|
|
183
229
|
if (result === undefined) {
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
230
|
+
const schema = tool.schema;
|
|
231
|
+
const normalizedArgs = normalizeToolArguments(call.arguments);
|
|
232
|
+
const args = hasParseSchema(schema)
|
|
233
|
+
? schema.parse(normalizedArgs)
|
|
234
|
+
: normalizedArgs;
|
|
187
235
|
ctx.log.debug?.("[iterative-tool-calling] invoking tool", {
|
|
188
236
|
aliasName: call.name,
|
|
189
237
|
canonicalName: canonicalName,
|
|
@@ -215,6 +263,13 @@ export const iterativeToolCalling = async (ctx, next) => {
|
|
|
215
263
|
...(call.id ? { tool_call_id: call.id } : { name: call.name }),
|
|
216
264
|
};
|
|
217
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
|
+
});
|
|
218
273
|
}
|
|
219
274
|
continue; // next round may call more tools
|
|
220
275
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sisu-ai/mw-tool-calling",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.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.4.0"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|