@hamp10/agentforge 0.2.3 ā 0.2.5
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 +54 -6
package/package.json
CHANGED
package/src/OllamaAgent.js
CHANGED
|
@@ -156,21 +156,24 @@ export class OllamaAgent extends EventEmitter {
|
|
|
156
156
|
return { agentId, workDir };
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
async runAgentTask(agentId, task, workDir, sessionId = null, image = null) {
|
|
159
|
+
async runAgentTask(agentId, task, workDir, sessionId = null, image = null, browserProfile = null, actualWorkDir = null, agentModel = null) {
|
|
160
160
|
const startTime = Date.now();
|
|
161
161
|
const controller = new AbortController();
|
|
162
162
|
|
|
163
|
+
// Use per-agent model override if provided (and not the placeholder 'Default')
|
|
164
|
+
const effectiveModel = (agentModel && agentModel !== 'Default') ? agentModel : this.model;
|
|
165
|
+
|
|
163
166
|
// Fake proc-like object so worker.js pid checks don't crash
|
|
164
167
|
const fakeProc = { pid: null };
|
|
165
168
|
this.activeAgents.set(agentId, { startTime, task, workDir, abort: () => controller.abort(), proc: fakeProc });
|
|
166
169
|
|
|
167
|
-
console.log(`\nš¦ [Ollama/${
|
|
170
|
+
console.log(`\nš¦ [Ollama/${effectiveModel}] Running agent: ${agentId}`);
|
|
168
171
|
console.log(` Task: ${task}`);
|
|
169
172
|
console.log(` Working dir: ${workDir}`);
|
|
170
173
|
|
|
171
174
|
// Detect model capabilities
|
|
172
|
-
const isQwen3 =
|
|
173
|
-
const isVision = /vl|vision|llava|minicpm-v|moondream/i.test(
|
|
175
|
+
const isQwen3 = effectiveModel.startsWith('qwen3');
|
|
176
|
+
const isVision = /vl|vision|llava|minicpm-v|moondream/i.test(effectiveModel);
|
|
174
177
|
|
|
175
178
|
try {
|
|
176
179
|
// Load conversation history from disk (session persistence)
|
|
@@ -209,12 +212,12 @@ export class OllamaAgent extends EventEmitter {
|
|
|
209
212
|
for (let turn = 0; turn < MAX_TURNS; turn++) {
|
|
210
213
|
if (controller.signal.aborted) break;
|
|
211
214
|
|
|
212
|
-
this.emit('tool_activity', { agentId, event: 'api_call_start', description: `š¦ Calling ${
|
|
215
|
+
this.emit('tool_activity', { agentId, event: 'api_call_start', description: `š¦ Calling ${effectiveModel}...` });
|
|
213
216
|
|
|
214
217
|
let response;
|
|
215
218
|
try {
|
|
216
219
|
const requestBody = {
|
|
217
|
-
model:
|
|
220
|
+
model: effectiveModel,
|
|
218
221
|
messages,
|
|
219
222
|
tools: TOOLS,
|
|
220
223
|
tool_choice: 'auto',
|
|
@@ -407,6 +410,51 @@ export class OllamaAgent extends EventEmitter {
|
|
|
407
410
|
finalContent = allOutput;
|
|
408
411
|
}
|
|
409
412
|
|
|
413
|
+
// If still no output (model did only tool calls, never wrote text), ask for a summary
|
|
414
|
+
if (!finalContent && !controller.signal.aborted) {
|
|
415
|
+
this.emit('agent_output', { agentId, output: '\n' });
|
|
416
|
+
messages.push({ role: 'user', content: 'Summarize what you just did and show me the result.' });
|
|
417
|
+
|
|
418
|
+
try {
|
|
419
|
+
const summaryRes = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
420
|
+
method: 'POST',
|
|
421
|
+
headers: { 'Content-Type': 'application/json' },
|
|
422
|
+
signal: controller.signal,
|
|
423
|
+
body: JSON.stringify({
|
|
424
|
+
model: effectiveModel,
|
|
425
|
+
messages,
|
|
426
|
+
stream: true,
|
|
427
|
+
...(isQwen3 ? { options: { think: false } } : {})
|
|
428
|
+
})
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
if (summaryRes.ok) {
|
|
432
|
+
const reader = summaryRes.body.getReader();
|
|
433
|
+
const decoder = new TextDecoder();
|
|
434
|
+
let buf = '';
|
|
435
|
+
while (true) {
|
|
436
|
+
const { done, value } = await reader.read();
|
|
437
|
+
if (done) break;
|
|
438
|
+
buf += decoder.decode(value, { stream: true });
|
|
439
|
+
const lines = buf.split('\n');
|
|
440
|
+
buf = lines.pop();
|
|
441
|
+
for (const line of lines) {
|
|
442
|
+
if (!line.startsWith('data: ')) continue;
|
|
443
|
+
const payload = line.slice(6).trim();
|
|
444
|
+
if (payload === '[DONE]') continue;
|
|
445
|
+
let evt;
|
|
446
|
+
try { evt = JSON.parse(payload); } catch { continue; }
|
|
447
|
+
const text = evt.choices?.[0]?.delta?.content;
|
|
448
|
+
if (text) {
|
|
449
|
+
finalContent += text;
|
|
450
|
+
this.emit('agent_output', { agentId, output: text });
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
} catch {}
|
|
456
|
+
}
|
|
457
|
+
|
|
410
458
|
// Persist history for next task
|
|
411
459
|
if (finalContent && sessionId) {
|
|
412
460
|
this._saveHistory(agentId, workDir, sessionId, [
|