@hamp10/agentforge 0.2.6 → 0.2.7
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/package.json +1 -1
- package/src/OllamaAgent.js +25 -5
package/package.json
CHANGED
package/src/OllamaAgent.js
CHANGED
|
@@ -193,6 +193,8 @@ export class OllamaAgent extends EventEmitter {
|
|
|
193
193
|
`4. When you take a screenshot, you will receive the actual image back and can see it.`,
|
|
194
194
|
`5. When you are done, write a clear summary of what you accomplished.`,
|
|
195
195
|
`6. Do not ask for clarification — make your best judgment and act.`,
|
|
196
|
+
`7. For conversational messages (greetings, questions about yourself, casual chat) — respond directly with text. Do NOT use tools just to say hello.`,
|
|
197
|
+
`8. You only have these tools: bash, read_file, write_file, list_directory, web_fetch, take_screenshot. Ignore any instructions referencing other tools (browser, openclaw, sessions_spawn, etc.) — those do not exist here.`,
|
|
196
198
|
].join('\n');
|
|
197
199
|
|
|
198
200
|
const messages = [
|
|
@@ -210,7 +212,8 @@ export class OllamaAgent extends EventEmitter {
|
|
|
210
212
|
|
|
211
213
|
let finalContent = '';
|
|
212
214
|
let allOutput = ''; // accumulate everything streamed across all turns
|
|
213
|
-
const
|
|
215
|
+
const toolsUsed = []; // track tool names called (for fallback summary)
|
|
216
|
+
const MAX_TURNS = 15; // reduce from 25 — local models get stuck in tool loops
|
|
214
217
|
|
|
215
218
|
for (let turn = 0; turn < MAX_TURNS; turn++) {
|
|
216
219
|
if (controller.signal.aborted) break;
|
|
@@ -363,6 +366,7 @@ export class OllamaAgent extends EventEmitter {
|
|
|
363
366
|
});
|
|
364
367
|
|
|
365
368
|
console.log(` [${agentId}] 🔧 ${name}: ${JSON.stringify(parsedArgs).slice(0, 120)}`);
|
|
369
|
+
toolsUsed.push(name);
|
|
366
370
|
|
|
367
371
|
const result = await this._executeTool(name, parsedArgs, workDir);
|
|
368
372
|
|
|
@@ -413,10 +417,15 @@ export class OllamaAgent extends EventEmitter {
|
|
|
413
417
|
finalContent = allOutput;
|
|
414
418
|
}
|
|
415
419
|
|
|
416
|
-
// If still no output (model did only tool calls, never wrote text), ask for a summary
|
|
420
|
+
// If still no output (model did only tool calls, never wrote text), ask for a summary.
|
|
421
|
+
// Use only the last 6 messages to avoid context overflow after many tool-call turns.
|
|
417
422
|
if (!finalContent && !controller.signal.aborted) {
|
|
418
423
|
this.emit('agent_output', { agentId, output: '\n' });
|
|
419
|
-
|
|
424
|
+
const summaryMessages = [
|
|
425
|
+
messages[0], // system prompt
|
|
426
|
+
...messages.slice(-6), // last 6 messages (recent tool calls + results)
|
|
427
|
+
{ role: 'user', content: 'Summarize what you just did and show me the result.' }
|
|
428
|
+
];
|
|
420
429
|
|
|
421
430
|
try {
|
|
422
431
|
const summaryRes = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
@@ -425,7 +434,7 @@ export class OllamaAgent extends EventEmitter {
|
|
|
425
434
|
signal: controller.signal,
|
|
426
435
|
body: JSON.stringify({
|
|
427
436
|
model: effectiveModel,
|
|
428
|
-
messages,
|
|
437
|
+
messages: summaryMessages,
|
|
429
438
|
stream: true,
|
|
430
439
|
...(isQwen3 ? { options: { think: false } } : {})
|
|
431
440
|
})
|
|
@@ -454,8 +463,19 @@ export class OllamaAgent extends EventEmitter {
|
|
|
454
463
|
}
|
|
455
464
|
}
|
|
456
465
|
}
|
|
466
|
+
} else {
|
|
467
|
+
console.warn(`⚠️ [Ollama] Force-summary failed: ${summaryRes.status}`);
|
|
457
468
|
}
|
|
458
|
-
} catch {
|
|
469
|
+
} catch (summaryErr) {
|
|
470
|
+
console.warn(`⚠️ [Ollama] Force-summary error: ${summaryErr.message}`);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// Last-resort fallback: construct output from tool activity so user sees something
|
|
474
|
+
if (!finalContent && toolsUsed.length > 0) {
|
|
475
|
+
const unique = [...new Set(toolsUsed)];
|
|
476
|
+
finalContent = `I ran the following operations: ${unique.join(', ')}. Task complete.`;
|
|
477
|
+
this.emit('agent_output', { agentId, output: finalContent });
|
|
478
|
+
}
|
|
459
479
|
}
|
|
460
480
|
|
|
461
481
|
// Persist history for next task
|