utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | 1a54c8a2006bcbc449ea0c620095029e3825481c7ee84ffd27626b14a097c6cf |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-08-18 23:31 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-08-18 23:31 +02:00 |
| Parents | 82d7f6361a73 |
2 files changed
added tests/retry-test.mjs +36 −0
| @@ -0,0 +1,36 @@ | ||
| 1 | +// ¿El agente REINTENTA tras un error en vez de rendirse? | |
| 2 | +// Proveedor de guion: 1ª vez pide code.read de un fichero que no existe (falla); | |
| 3 | +// 2ª vez, viendo el ERROR + la pista en el historial, corrige y lee el bueno. | |
| 4 | +import { chromium } from 'playwright'; | |
| 5 | +const b = await chromium.launch({ channel: 'chrome', headless: true }); | |
| 6 | +const p = await (await b.newContext()).newPage(); | |
| 7 | +await p.goto('https://code.elffuss.utopiaia.com/', { waitUntil: 'domcontentloaded' }); | |
| 8 | +await p.waitForTimeout(1200); | |
| 9 | +const r = await p.evaluate(async () => { | |
| 10 | + const { Agent } = await import('/js/agent.js?v=' + Date.now()); | |
| 11 | + const code = await import('/js/tools/code.js'); | |
| 12 | + const raiz = await navigator.storage.getDirectory(); | |
| 13 | + for await (const [n] of raiz.entries()) await raiz.removeEntry(n, { recursive: true }).catch(()=>{}); | |
| 14 | + const w = await (await raiz.getFileHandle('bueno.js', { create: true })).createWritable(); | |
| 15 | + await w.write('export const x = 42;'); await w.close(); | |
| 16 | + await code.openProject(raiz); | |
| 17 | + // proveedor: falla la 1ª, y si ve ERROR en el historial reintenta con el bueno | |
| 18 | + let llamadas = 0; const vistos = []; | |
| 19 | + const guion = { chat: async (history) => { | |
| 20 | + llamadas++; | |
| 21 | + const huboError = history.some(m => /ERROR|Reanaliza/.test(m.content || '')); | |
| 22 | + vistos.push(huboError ? 'vio-error' : 'primera'); | |
| 23 | + if (!huboError) return '```tool\n{"tool":"code.read","args":{"path":"noexiste.js"}}\n```'; | |
| 24 | + if (llamadas <= 3) return '```tool\n{"tool":"code.read","args":{"path":"bueno.js"}}\n```'; | |
| 25 | + return 'Ya está, leído bueno.js.'; | |
| 26 | + }}; | |
| 27 | + const ev = []; | |
| 28 | + await new Agent(guion).handle('lee el fichero', e => ev.push(e.type + (e.tool ? ':' + e.tool : ''))); | |
| 29 | + return { llamadas, vistos, tipos: [...new Set(ev)], reintentó: vistos.includes('vio-error') }; | |
| 30 | +}); | |
| 31 | +console.log(' llamadas al modelo:', r.llamadas, '·', r.vistos.join(' → ')); | |
| 32 | +console.log(' eventos:', r.tipos.join(', ')); | |
| 33 | +console.log(r.reintentó ? '\n✅ reintenta: tras el ERROR, el modelo recibe la pista y corrige (no se rinde)' | |
| 34 | + : '\n❌ no reintentó'); | |
| 35 | +await b.close(); | |
| 36 | +process.exit(r.reintentó ? 0 : 1); |
modified web/js/agent.js +3 −1
| @@ -289,7 +289,9 @@ | ||
| 289 | 289 | catch (e) { result = 'ERROR: ' + e.message; onEvent({ type: 'tool_error', tool: call.tool, text: e.message }); } |
| 290 | 290 | const resultStr = typeof result === 'string' ? result : JSON.stringify(result); |
| 291 | 291 | onEvent({ type: 'tool_result', tool: call.tool, result: resultStr }); |
| 292 | - results.push(`[resultado ${call.tool}]\n${resultStr}`); | |
| 292 | + const pista = resultStr.startsWith('ERROR') | |
| 293 | + ? '\n(Reanaliza este error y reintenta con la corrección; no te rindas.)' : ''; | |
| 294 | + results.push(`[resultado ${call.tool}]\n${resultStr}${pista}`); | |
| 293 | 295 | } |
| 294 | 296 | this.history.push({ role: 'user', content: results.join('\n\n'), ts: Date.now() }); |
| 295 | 297 | } |