universal-agent-memory 6.2.0 → 6.2.1
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/cli/tool-calls.d.ts +16 -0
- package/dist/cli/tool-calls.d.ts.map +1 -0
- package/dist/cli/tool-calls.js +374 -0
- package/dist/cli/tool-calls.js.map +1 -0
- package/package.json +2 -1
- package/tools/agents/README.md +224 -0
- package/tools/agents/benchmarks/benchmark_memory_systems.py +637 -0
- package/tools/agents/benchmarks/results/benchmark_20260106_064817.json +170 -0
- package/tools/agents/benchmarks/results/benchmark_20260106_064817.md +51 -0
- package/tools/agents/config/chat_template.jinja +172 -0
- package/tools/agents/scripts/fix_qwen_chat_template.py +314 -0
- package/tools/agents/scripts/memory_migration.py +518 -0
- package/tools/agents/scripts/migrate_memory_to_qdrant.py +113 -0
- package/tools/agents/scripts/query_memory.py +189 -0
- package/tools/agents/scripts/qwen_tool_call_test.py +419 -0
- package/tools/agents/scripts/qwen_tool_call_wrapper.py +517 -0
- package/tools/agents/scripts/start-services.sh +96 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* UAM Tool Call Setup - Qwen3.5 Tool Call Fixes
|
|
4
|
+
*
|
|
5
|
+
* Manages chat templates, wrapper scripts, and testing for Qwen3.5 tool calling
|
|
6
|
+
* Improves tool call performance from ~40% to ~88% for long-running tasks (5+ tool calls)
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* uam tool-calls setup Install chat templates for llama.cpp and OpenCode
|
|
10
|
+
* uam tool-calls test Run reliability test suite
|
|
11
|
+
* uam tool-calls status Check current configuration
|
|
12
|
+
* uam tool-calls fix Apply template fixes to existing templates
|
|
13
|
+
*/
|
|
14
|
+
export { toolCallsCommand };
|
|
15
|
+
declare function toolCallsCommand(): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=tool-calls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-calls.d.ts","sourceRoot":"","sources":["../../src/cli/tool-calls.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;GAWG;AAoXH,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,iBAAe,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA2B/C"}
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* UAM Tool Call Setup - Qwen3.5 Tool Call Fixes
|
|
4
|
+
*
|
|
5
|
+
* Manages chat templates, wrapper scripts, and testing for Qwen3.5 tool calling
|
|
6
|
+
* Improves tool call performance from ~40% to ~88% for long-running tasks (5+ tool calls)
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* uam tool-calls setup Install chat templates for llama.cpp and OpenCode
|
|
10
|
+
* uam tool-calls test Run reliability test suite
|
|
11
|
+
* uam tool-calls status Check current configuration
|
|
12
|
+
* uam tool-calls fix Apply template fixes to existing templates
|
|
13
|
+
*/
|
|
14
|
+
import { execSync } from 'child_process';
|
|
15
|
+
import { existsSync, mkdirSync, copyFileSync } from 'fs';
|
|
16
|
+
import { join, dirname } from 'path';
|
|
17
|
+
import { fileURLToPath } from 'url';
|
|
18
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
19
|
+
const __dirname = dirname(__filename);
|
|
20
|
+
const UAM_ROOT = join(__dirname, '..');
|
|
21
|
+
const AGENTS_CONFIG = join(UAM_ROOT, 'tools', 'agents', 'config');
|
|
22
|
+
const AGENTS_SCRIPTS = join(UAM_ROOT, 'tools', 'agents', 'scripts');
|
|
23
|
+
function getLlamaCppPath() {
|
|
24
|
+
// Default: ~/llama.cpp
|
|
25
|
+
return process.env.LLAMA_CPP_PATH || join(process.env.HOME || '', 'llama.cpp');
|
|
26
|
+
}
|
|
27
|
+
function getOpencodePath() {
|
|
28
|
+
// Default: ~/.opencode
|
|
29
|
+
return process.env.OPencode_PATH || join(process.env.HOME || '', '.opencode');
|
|
30
|
+
}
|
|
31
|
+
function ensureDir(dir) {
|
|
32
|
+
if (!existsSync(dir)) {
|
|
33
|
+
mkdirSync(dir, { recursive: true });
|
|
34
|
+
console.log(`✓ Created directory: ${dir}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function copyTemplate(src, dest) {
|
|
38
|
+
ensureDir(dirname(dest));
|
|
39
|
+
copyFileSync(src, dest);
|
|
40
|
+
console.log(`✓ Copied template: ${src} -> ${dest}`);
|
|
41
|
+
}
|
|
42
|
+
function printSetupInstructions() {
|
|
43
|
+
console.log(`
|
|
44
|
+
${'='.repeat(70)}
|
|
45
|
+
Qwen3.5 Tool Call Setup - Installation Complete
|
|
46
|
+
${'='.repeat(70)}
|
|
47
|
+
|
|
48
|
+
The following components have been installed:
|
|
49
|
+
|
|
50
|
+
1. Chat Template (chat_template.jinja)
|
|
51
|
+
- Location: ${AGENTS_CONFIG}/chat_template.jinja
|
|
52
|
+
- Fix: Added conditional wrapper for tool_call.arguments
|
|
53
|
+
- Performance: Improves from ~40% to ~88% for 5+ tool calls
|
|
54
|
+
|
|
55
|
+
2. Python Scripts
|
|
56
|
+
- fix_qwen_chat_template.py: Apply fixes to existing templates
|
|
57
|
+
- qwen_tool_call_wrapper.py: Retry logic and validation
|
|
58
|
+
- qwen_tool_call_test.py: Reliability test suite
|
|
59
|
+
|
|
60
|
+
3. Integration Points
|
|
61
|
+
- llama.cpp: Use --chat-template-file and --jinja flags
|
|
62
|
+
- OpenCode: Copy to ~/.opencode/agent/chat_template.jinja
|
|
63
|
+
|
|
64
|
+
${'='.repeat(70)}
|
|
65
|
+
NEXT STEPS:
|
|
66
|
+
${'='.repeat(70)}
|
|
67
|
+
|
|
68
|
+
A. For llama.cpp (local model server):
|
|
69
|
+
|
|
70
|
+
1. Stop your existing llama-server if running:
|
|
71
|
+
pkill llama-server
|
|
72
|
+
|
|
73
|
+
2. Start with the fixed template:
|
|
74
|
+
${'='.repeat(60)}
|
|
75
|
+
cd ${getLlamaCppPath()}
|
|
76
|
+
./llama-server \\
|
|
77
|
+
--model ~/models/Qwen3.5-35B-Instruct-Q4_K_M.gguf \\
|
|
78
|
+
--chat-template-file ${AGENTS_CONFIG}/chat_template.jinja \\
|
|
79
|
+
--jinja \\
|
|
80
|
+
--port 8080 \\
|
|
81
|
+
--ctx-size 262144 \\
|
|
82
|
+
--batch-size 4096 \\
|
|
83
|
+
--threads $(nproc) \\
|
|
84
|
+
--tensor-split auto
|
|
85
|
+
${'='.repeat(60)}
|
|
86
|
+
|
|
87
|
+
B. For OpenCode:
|
|
88
|
+
|
|
89
|
+
1. Copy template to OpenCode agent config:
|
|
90
|
+
${'='.repeat(60)}
|
|
91
|
+
mkdir -p ~/.opencode/agent
|
|
92
|
+
cp ${AGENTS_CONFIG}/chat_template.jinja ~/.opencode/agent/
|
|
93
|
+
|
|
94
|
+
2. Update .opencode/config.json to enable jinja:
|
|
95
|
+
{
|
|
96
|
+
"provider": "llama.cpp",
|
|
97
|
+
"model": "qwen35-a3b-iq4xs",
|
|
98
|
+
"chatTemplate": "jinja",
|
|
99
|
+
"baseURL": "http://localhost:8080/v1"
|
|
100
|
+
}
|
|
101
|
+
${'='.repeat(60)}
|
|
102
|
+
|
|
103
|
+
C. Test the setup:
|
|
104
|
+
|
|
105
|
+
1. Run the test suite:
|
|
106
|
+
${'='.repeat(60)}
|
|
107
|
+
cd ${AGENTS_SCRIPTS}
|
|
108
|
+
python3 qwen_tool_call_test.py --verbose
|
|
109
|
+
${'='.repeat(60)}
|
|
110
|
+
|
|
111
|
+
2. Expected results:
|
|
112
|
+
- Single tool call: ~98% success rate
|
|
113
|
+
- 2-3 tool calls: ~92% success rate
|
|
114
|
+
- 5+ tool calls: ~88% success rate
|
|
115
|
+
|
|
116
|
+
D. Verify template is loaded:
|
|
117
|
+
|
|
118
|
+
1. Check llama.cpp server logs for:
|
|
119
|
+
"Chat template loaded successfully"
|
|
120
|
+
|
|
121
|
+
2. Test with a simple tool call:
|
|
122
|
+
curl -X POST http://localhost:8080/v1/chat/completions \\
|
|
123
|
+
-H "Content-Type: application/json" \\
|
|
124
|
+
-d '{
|
|
125
|
+
"model": "qwen35-a3b-iq4xs",
|
|
126
|
+
"messages": [{"role": "user", "content": "Read /etc/hosts"}],
|
|
127
|
+
"tools": [{"type": "function", "function": {"name": "read_file"}}]
|
|
128
|
+
}'
|
|
129
|
+
|
|
130
|
+
${'='.repeat(70)}
|
|
131
|
+
TROUBLESHOOTING:
|
|
132
|
+
${'='.repeat(70)}
|
|
133
|
+
|
|
134
|
+
Issue: Tool calls fail after 1-2 attempts
|
|
135
|
+
Solution: Verify template was loaded with --chat-template-file flag
|
|
136
|
+
|
|
137
|
+
Issue: Template not found
|
|
138
|
+
Solution: Check path exists: ls -la ${AGENTS_CONFIG}/chat_template.jinja
|
|
139
|
+
|
|
140
|
+
Issue: OpenCode still using old template
|
|
141
|
+
Solution: Restart OpenCode after copying template
|
|
142
|
+
|
|
143
|
+
Issue: Python scripts not found
|
|
144
|
+
Solution: Ensure you're in the scripts directory: cd ${AGENTS_SCRIPTS}
|
|
145
|
+
|
|
146
|
+
${'='.repeat(70)}
|
|
147
|
+
For more information, see:
|
|
148
|
+
- docs/qwen35-tool-call-fixes.md
|
|
149
|
+
- tools/agents/scripts/README.md
|
|
150
|
+
${'='.repeat(70)}
|
|
151
|
+
`);
|
|
152
|
+
}
|
|
153
|
+
async function setup() {
|
|
154
|
+
console.log('='.repeat(70));
|
|
155
|
+
console.log('UAM Tool Call Setup - Qwen3.5 Tool Call Fixes');
|
|
156
|
+
console.log('='.repeat(70));
|
|
157
|
+
console.log();
|
|
158
|
+
// Copy templates
|
|
159
|
+
const templateSrc = join(__dirname, '..', '..', 'tools', 'agents', 'config', 'chat_template.jinja');
|
|
160
|
+
const templateDest = join(AGENTS_CONFIG, 'chat_template.jinja');
|
|
161
|
+
try {
|
|
162
|
+
copyTemplate(templateSrc, templateDest);
|
|
163
|
+
// Copy Python scripts
|
|
164
|
+
const scripts = [
|
|
165
|
+
'fix_qwen_chat_template.py',
|
|
166
|
+
'qwen_tool_call_wrapper.py',
|
|
167
|
+
'qwen_tool_call_test.py',
|
|
168
|
+
];
|
|
169
|
+
for (const script of scripts) {
|
|
170
|
+
const src = join(__dirname, '..', '..', 'tools', 'agents', 'scripts', script);
|
|
171
|
+
const dest = join(AGENTS_SCRIPTS, script);
|
|
172
|
+
if (existsSync(src)) {
|
|
173
|
+
copyTemplate(src, dest);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
console.log(`⚠ Script not found: ${src}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
console.log();
|
|
180
|
+
printSetupInstructions();
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
console.error('❌ Error during setup:', error);
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async function test() {
|
|
188
|
+
console.log('='.repeat(70));
|
|
189
|
+
console.log('Running Qwen3.5 Tool Call Reliability Tests');
|
|
190
|
+
console.log('='.repeat(70));
|
|
191
|
+
console.log();
|
|
192
|
+
const scriptsDir = AGENTS_SCRIPTS;
|
|
193
|
+
if (!existsSync(scriptsDir)) {
|
|
194
|
+
console.error(`❌ Scripts directory not found: ${scriptsDir}`);
|
|
195
|
+
console.log('Run: uam tool-calls setup');
|
|
196
|
+
process.exit(1);
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
execSync(`cd ${scriptsDir} && python3 fix_qwen_chat_template.py ${AGENTS_CONFIG}/chat_template.jinja`, { encoding: 'utf-8', stdio: 'inherit' });
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
console.log();
|
|
203
|
+
console.log('⚠ Test completed with some failures');
|
|
204
|
+
console.log('Review the output above for details.');
|
|
205
|
+
process.exit(1);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function status() {
|
|
209
|
+
console.log('='.repeat(70));
|
|
210
|
+
console.log('Qwen3.5 Tool Call Configuration Status');
|
|
211
|
+
console.log('='.repeat(70));
|
|
212
|
+
console.log();
|
|
213
|
+
// Check template
|
|
214
|
+
const templatePath = join(AGENTS_CONFIG, 'chat_template.jinja');
|
|
215
|
+
if (existsSync(templatePath)) {
|
|
216
|
+
const stat = await import('fs').then((m) => m.statSync(templatePath));
|
|
217
|
+
console.log(`✓ Chat template: ${templatePath}`);
|
|
218
|
+
console.log(` Modified: ${stat.mtime.toISOString()}`);
|
|
219
|
+
console.log(` Size: ${stat.size} bytes`);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
console.log(`✗ Chat template not found: ${templatePath}`);
|
|
223
|
+
console.log(' Run: uam tool-calls setup');
|
|
224
|
+
}
|
|
225
|
+
console.log();
|
|
226
|
+
// Check Python scripts
|
|
227
|
+
const scripts = [
|
|
228
|
+
'fix_qwen_chat_template.py',
|
|
229
|
+
'qwen_tool_call_wrapper.py',
|
|
230
|
+
'qwen_tool_call_test.py',
|
|
231
|
+
];
|
|
232
|
+
console.log('Python scripts:');
|
|
233
|
+
for (const script of scripts) {
|
|
234
|
+
const scriptPath = join(AGENTS_SCRIPTS, script);
|
|
235
|
+
if (existsSync(scriptPath)) {
|
|
236
|
+
const stat = await import('fs').then((m) => m.statSync(scriptPath));
|
|
237
|
+
console.log(` ✓ ${script} (${stat.size} bytes)`);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
console.log(` ✗ ${script} - not found`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
console.log();
|
|
244
|
+
// Check llama.cpp
|
|
245
|
+
const llamaCppPath = getLlamaCppPath();
|
|
246
|
+
if (existsSync(llamaCppPath)) {
|
|
247
|
+
console.log(`✓ llama.cpp path: ${llamaCppPath}`);
|
|
248
|
+
const llamaServer = join(llamaCppPath, 'llama-server');
|
|
249
|
+
if (existsSync(llamaServer)) {
|
|
250
|
+
console.log(` ✓ llama-server found`);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
console.log(` ⚠ llama-server not found at ${llamaServer}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
console.log(`⚠ llama.cpp not found at: ${llamaCppPath}`);
|
|
258
|
+
console.log(' Set LLAMA_CPP_PATH env var if different location');
|
|
259
|
+
}
|
|
260
|
+
console.log();
|
|
261
|
+
// Check OpenCode
|
|
262
|
+
const opencodePath = getOpencodePath();
|
|
263
|
+
const opencodeTemplate = join(opencodePath, 'agent', 'chat_template.jinja');
|
|
264
|
+
if (existsSync(opencodeTemplate)) {
|
|
265
|
+
const stat = await import('fs').then((m) => m.statSync(opencodeTemplate));
|
|
266
|
+
console.log(`✓ OpenCode template: ${opencodeTemplate}`);
|
|
267
|
+
console.log(` Modified: ${stat.mtime.toISOString()}`);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
console.log(`⚠ OpenCode template not found: ${opencodeTemplate}`);
|
|
271
|
+
console.log(' Run: uam tool-calls setup (will copy to ~/.opencode/agent/)');
|
|
272
|
+
}
|
|
273
|
+
console.log();
|
|
274
|
+
console.log('='.repeat(70));
|
|
275
|
+
}
|
|
276
|
+
async function fix() {
|
|
277
|
+
console.log('='.repeat(70));
|
|
278
|
+
console.log('Applying Template Fixes');
|
|
279
|
+
console.log('='.repeat(70));
|
|
280
|
+
console.log();
|
|
281
|
+
const scriptsDir = AGENTS_SCRIPTS;
|
|
282
|
+
if (!existsSync(scriptsDir)) {
|
|
283
|
+
console.error(`❌ Scripts directory not found: ${scriptsDir}`);
|
|
284
|
+
console.log('Run: uam tool-calls setup');
|
|
285
|
+
process.exit(1);
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
execSync(`cd ${scriptsDir} && python3 qwen_tool_call_test.py --verbose`, {
|
|
289
|
+
encoding: 'utf-8',
|
|
290
|
+
stdio: 'inherit',
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
console.log();
|
|
295
|
+
console.log('⚠ Fix script completed');
|
|
296
|
+
process.exit(1);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
async function main() {
|
|
300
|
+
const command = process.argv[2];
|
|
301
|
+
switch (command) {
|
|
302
|
+
case 'setup':
|
|
303
|
+
await setup();
|
|
304
|
+
break;
|
|
305
|
+
case 'test':
|
|
306
|
+
await test();
|
|
307
|
+
break;
|
|
308
|
+
case 'status':
|
|
309
|
+
await status();
|
|
310
|
+
break;
|
|
311
|
+
case 'fix':
|
|
312
|
+
await fix();
|
|
313
|
+
break;
|
|
314
|
+
case undefined:
|
|
315
|
+
case 'help':
|
|
316
|
+
default:
|
|
317
|
+
console.log(`
|
|
318
|
+
UAM Tool Call Setup - Qwen3.5 Tool Call Fixes
|
|
319
|
+
|
|
320
|
+
Usage:
|
|
321
|
+
uam tool-calls <command> [options]
|
|
322
|
+
|
|
323
|
+
Commands:
|
|
324
|
+
setup Install chat templates and Python scripts
|
|
325
|
+
test Run reliability test suite
|
|
326
|
+
status Check current configuration
|
|
327
|
+
fix Apply template fixes to existing templates
|
|
328
|
+
help Show this help message
|
|
329
|
+
|
|
330
|
+
Performance Improvement:
|
|
331
|
+
Single tool call: ~95% -> ~98%
|
|
332
|
+
2-3 tool calls: ~70% -> ~92%
|
|
333
|
+
5+ tool calls: ~40% -> ~88%
|
|
334
|
+
Long context (50K+): ~30% -> ~85%
|
|
335
|
+
|
|
336
|
+
Examples:
|
|
337
|
+
uam tool-calls setup
|
|
338
|
+
uam tool-calls test --verbose
|
|
339
|
+
uam tool-calls status
|
|
340
|
+
uam tool-calls fix
|
|
341
|
+
`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
main().catch(console.error);
|
|
345
|
+
export { toolCallsCommand };
|
|
346
|
+
async function toolCallsCommand() {
|
|
347
|
+
// Default to help if no subcommand
|
|
348
|
+
console.log(`
|
|
349
|
+
UAM Tool Call Setup - Qwen3.5 Tool Call Fixes
|
|
350
|
+
|
|
351
|
+
Usage:
|
|
352
|
+
uam tool-calls <command> [options]
|
|
353
|
+
|
|
354
|
+
Commands:
|
|
355
|
+
setup Install chat templates and Python scripts
|
|
356
|
+
test Run reliability test suite
|
|
357
|
+
status Check current configuration
|
|
358
|
+
fix Apply template fixes to existing templates
|
|
359
|
+
help Show this help message
|
|
360
|
+
|
|
361
|
+
Performance Improvement:
|
|
362
|
+
Single tool call: ~95% -> ~98%
|
|
363
|
+
2-3 tool calls: ~70% -> ~92%
|
|
364
|
+
5+ tool calls: ~40% -> ~88%
|
|
365
|
+
Long context (50K+): ~30% -> ~85%
|
|
366
|
+
|
|
367
|
+
Examples:
|
|
368
|
+
uam tool-calls setup
|
|
369
|
+
uam tool-calls test --verbose
|
|
370
|
+
uam tool-calls status
|
|
371
|
+
uam tool-calls fix
|
|
372
|
+
`);
|
|
373
|
+
}
|
|
374
|
+
//# sourceMappingURL=tool-calls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-calls.js","sourceRoot":"","sources":["../../src/cli/tool-calls.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AACvC,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC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C;;;;;;;;;;;;;;;;;;;;;;;;CAwBb,CAAC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "universal-agent-memory",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.1",
|
|
4
4
|
"description": "Universal AI agent memory system - CLAUDE.md templates, memory, worktrees for Claude Code, Factory.AI, VSCode, OpenCode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -85,6 +85,7 @@
|
|
|
85
85
|
"files": [
|
|
86
86
|
"dist",
|
|
87
87
|
"templates",
|
|
88
|
+
"tools/agents",
|
|
88
89
|
"README.md",
|
|
89
90
|
"LICENSE"
|
|
90
91
|
]
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# Qwen3.5 Tool Call Fixes
|
|
2
|
+
|
|
3
|
+
This directory contains tools and configurations for fixing Qwen3.5 tool calling issues that cause ~40% success rate on long-running tasks (5+ tool calls) to improve to ~88%.
|
|
4
|
+
|
|
5
|
+
## Performance Improvement
|
|
6
|
+
|
|
7
|
+
| Scenario | Without Fixes | With Fixes |
|
|
8
|
+
| ------------------- | ------------- | ---------- |
|
|
9
|
+
| Single tool call | ~95% | ~98% |
|
|
10
|
+
| 2-3 tool calls | ~70% | ~92% |
|
|
11
|
+
| 5+ tool calls | ~40% | ~88% |
|
|
12
|
+
| Long context (50K+) | ~30% | ~85% |
|
|
13
|
+
|
|
14
|
+
## Files
|
|
15
|
+
|
|
16
|
+
### `config/chat_template.jinja`
|
|
17
|
+
|
|
18
|
+
The core fix: a patched Jinja2 template for Qwen3.5 that adds conditional wrappers around tool call argument iteration.
|
|
19
|
+
|
|
20
|
+
**Key Fix (line 138-144):**
|
|
21
|
+
|
|
22
|
+
```jinja2
|
|
23
|
+
{%- if tool_call.arguments is mapping %}
|
|
24
|
+
{%- for args_name, args_value in tool_call.arguments|items %}
|
|
25
|
+
{{- '<parameter=' + args_name + '>\n' }}
|
|
26
|
+
{%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
|
|
27
|
+
{{- args_value }}
|
|
28
|
+
{{- '\n</parameter>\n' }}
|
|
29
|
+
{%- endfor %}
|
|
30
|
+
{%- endif %}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This prevents template parsing failures after the first 1-2 tool calls.
|
|
34
|
+
|
|
35
|
+
### `scripts/fix_qwen_chat_template.py`
|
|
36
|
+
|
|
37
|
+
Python script to automatically apply the template fix to existing chat templates.
|
|
38
|
+
|
|
39
|
+
**Usage:**
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
python3 fix_qwen_chat_template.py [template_file]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### `scripts/qwen_tool_call_wrapper.py`
|
|
46
|
+
|
|
47
|
+
OpenAI-compatible client with automatic retry logic and validation for Qwen3.5 tool calls.
|
|
48
|
+
|
|
49
|
+
**Features:**
|
|
50
|
+
|
|
51
|
+
- Automatic retry with exponential backoff
|
|
52
|
+
- Prompt correction for failed tool calls
|
|
53
|
+
- Metrics tracking and monitoring
|
|
54
|
+
- Thinking mode disablement
|
|
55
|
+
- Template validation
|
|
56
|
+
|
|
57
|
+
**Usage:**
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from qwen_tool_call_wrapper import Qwen35ToolCallClient
|
|
61
|
+
|
|
62
|
+
client = Qwen35ToolCallClient()
|
|
63
|
+
response = client.chat_with_tools(
|
|
64
|
+
messages=[{"role": "user", "content": "Call read_file with path='/etc/hosts'"}],
|
|
65
|
+
tools=[...]
|
|
66
|
+
)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### `scripts/qwen_tool_call_test.py`
|
|
70
|
+
|
|
71
|
+
Reliability test suite for validating Qwen3.5 tool call performance.
|
|
72
|
+
|
|
73
|
+
**Usage:**
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
python3 qwen_tool_call_test.py --verbose
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Tests:**
|
|
80
|
+
|
|
81
|
+
1. Single tool call (baseline)
|
|
82
|
+
2. Two consecutive tool calls
|
|
83
|
+
3. Three tool calls
|
|
84
|
+
4. Five tool calls (stress test)
|
|
85
|
+
5. Reasoning content interference
|
|
86
|
+
6. Invalid format recovery
|
|
87
|
+
|
|
88
|
+
## Installation
|
|
89
|
+
|
|
90
|
+
### Option 1: Using UAM CLI (Recommended)
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
uam tool-calls setup
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
This will:
|
|
97
|
+
|
|
98
|
+
1. Copy `chat_template.jinja` to `tools/agents/config/`
|
|
99
|
+
2. Copy Python scripts to `tools/agents/scripts/`
|
|
100
|
+
3. Print setup instructions for llama.cpp and OpenCode
|
|
101
|
+
|
|
102
|
+
### Option 2: Manual Installation
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Copy template
|
|
106
|
+
mkdir -p tools/agents/config
|
|
107
|
+
cp tools/agents/config/chat_template.jinja tools/agents/config/
|
|
108
|
+
|
|
109
|
+
# Copy scripts
|
|
110
|
+
mkdir -p tools/agents/scripts
|
|
111
|
+
cp tools/agents/scripts/*.py tools/agents/scripts/
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Integration
|
|
115
|
+
|
|
116
|
+
### llama.cpp
|
|
117
|
+
|
|
118
|
+
**Start llama-server with the fixed template:**
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
./llama-server \
|
|
122
|
+
--model ~/models/Qwen3.5-35B-Instruct-Q4_K_M.gguf \
|
|
123
|
+
--chat-template-file tools/agents/config/chat_template.jinja \
|
|
124
|
+
--jinja \
|
|
125
|
+
--port 8080 \
|
|
126
|
+
--ctx-size 262144 \
|
|
127
|
+
--batch-size 4096 \
|
|
128
|
+
--threads $(nproc)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Key flags:**
|
|
132
|
+
|
|
133
|
+
- `--chat-template-file`: Path to the fixed template
|
|
134
|
+
- `--jinja`: Enable Jinja2 template processing
|
|
135
|
+
|
|
136
|
+
### OpenCode
|
|
137
|
+
|
|
138
|
+
**1. Copy template to OpenCode agent config:**
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
mkdir -p ~/.opencode/agent
|
|
142
|
+
cp tools/agents/config/chat_template.jinja ~/.opencode/agent/
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**2. Update `.opencode/config.json`:**
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"provider": "llama.cpp",
|
|
150
|
+
"model": "qwen35-a3b-iq4xs",
|
|
151
|
+
"chatTemplate": "jinja",
|
|
152
|
+
"baseURL": "http://localhost:8080/v1"
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**3. Restart OpenCode**
|
|
157
|
+
|
|
158
|
+
## Verification
|
|
159
|
+
|
|
160
|
+
### Check Setup
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
uam tool-calls status
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Run Tests
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
python3 tools/agents/scripts/qwen_tool_call_test.py --verbose
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Expected results:
|
|
173
|
+
|
|
174
|
+
- Single tool call: ~98% success rate
|
|
175
|
+
- 2-3 tool calls: ~92% success rate
|
|
176
|
+
- 5+ tool calls: ~88% success rate
|
|
177
|
+
|
|
178
|
+
### Test Tool Call Manually
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
curl -X POST http://localhost:8080/v1/chat/completions \
|
|
182
|
+
-H "Content-Type: application/json" \
|
|
183
|
+
-d '{
|
|
184
|
+
"model": "qwen35-a3b-iq4xs",
|
|
185
|
+
"messages": [{"role": "user", "content": "Read /etc/hosts"}],
|
|
186
|
+
"tools": [{"type": "function", "function": {"name": "read_file"}}]
|
|
187
|
+
}'
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Troubleshooting
|
|
191
|
+
|
|
192
|
+
### Issue: Tool calls fail after 1-2 attempts
|
|
193
|
+
|
|
194
|
+
**Solution:** Verify template was loaded with `--chat-template-file` flag
|
|
195
|
+
|
|
196
|
+
### Issue: Template not found
|
|
197
|
+
|
|
198
|
+
**Solution:** Check path exists:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
ls -la tools/agents/config/chat_template.jinja
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Issue: OpenCode still using old template
|
|
205
|
+
|
|
206
|
+
**Solution:** Restart OpenCode after copying template
|
|
207
|
+
|
|
208
|
+
### Issue: Python scripts not found
|
|
209
|
+
|
|
210
|
+
**Solution:** Ensure you're in the scripts directory:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
cd tools/agents/scripts
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## References
|
|
217
|
+
|
|
218
|
+
- **Original Issue:** Hugging Face Discussion #4 - Qwen3.5 tool call failures
|
|
219
|
+
- **Source:** pay2u project - Qwen3.5 35B A3B tool call fixes
|
|
220
|
+
- **Performance Data:** Factory.AI droid `qwen35-tool-call-optimized.md`
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
MIT License - Same as universal-agent-memory
|