Vendored
+17
-5
@@ -70,9 +70,13 @@ function loadedCtxSize() {
|
||||
return (loaded && loaded.ctxSize) || 8192;
|
||||
}
|
||||
|
||||
function toolResultCap() {
|
||||
function toolResultCap(budget) {
|
||||
const ctx = loadedCtxSize();
|
||||
return Math.min(8000, Math.max(1200, Math.floor(ctx * 0.35)));
|
||||
const voice = !!(budget && budget.voice);
|
||||
const max = voice ? 2000 : 8000;
|
||||
const ratio = voice ? 0.1 : 0.35;
|
||||
const min = voice ? 600 : 1200;
|
||||
return Math.min(max, Math.max(min, Math.floor(ctx * ratio)));
|
||||
}
|
||||
|
||||
function emitCompactDone(emit, session, jobId, toolDefs, ctxSize, beforeUsage, method) {
|
||||
@@ -440,6 +444,7 @@ async function runTurn(ctx) {
|
||||
const budget = toolBudget.fromPayload(payload, origin);
|
||||
let lastText = '';
|
||||
let goalNudges = 0;
|
||||
let toolNudges = 0;
|
||||
|
||||
async function runOneTool(item, turn) {
|
||||
const name = item.name;
|
||||
@@ -535,7 +540,7 @@ async function runTurn(ctx) {
|
||||
if (out && out.type === 'goal_blocked') {
|
||||
session.goal.status = 'blocked';
|
||||
emitUpdate(emit, session.id, jobId, { type: 'goal_update', goal: goalMod.snapshot(session.goal) });
|
||||
const rendered = truncate.renderToolResult(out, toolResultCap());
|
||||
const rendered = truncate.renderToolResult(out, toolResultCap(budget));
|
||||
pushHistory(session, { role: 'tool', name, content: rendered, tool_call_id: toolCallId });
|
||||
emitUpdate(emit, session.id, jobId, { type: 'tool_result', toolCallId, name, result: rendered.slice(0, 4000) });
|
||||
return { reason: 'goal_blocked', text: out.blocked_reason || lastText, turns: turn + 1 };
|
||||
@@ -545,7 +550,7 @@ async function runTurn(ctx) {
|
||||
const skipVerify = payload && payload.verify === false;
|
||||
const verdict = skipVerify ? { achieved: true, gaps: [] } : await verifyGoal(session, tracker, lastText);
|
||||
if (verdict.achieved) {
|
||||
const rendered = truncate.renderToolResult({ ok: true, achieved: true }, toolResultCap());
|
||||
const rendered = truncate.renderToolResult({ ok: true, achieved: true }, toolResultCap(budget));
|
||||
pushHistory(session, { role: 'tool', name, content: rendered, tool_call_id: toolCallId });
|
||||
emitUpdate(emit, session.id, jobId, { type: 'tool_result', toolCallId, name, result: rendered });
|
||||
emitUpdate(emit, session.id, jobId, { type: 'goal_update', goal: goalMod.snapshot(session.goal) });
|
||||
@@ -563,7 +568,7 @@ async function runTurn(ctx) {
|
||||
} catch (err) {
|
||||
out = { error: err.message };
|
||||
}
|
||||
const rendered = truncate.renderToolResult(out, toolResultCap());
|
||||
const rendered = truncate.renderToolResult(out, toolResultCap(budget));
|
||||
pushHistory(session, { role: 'tool', name, content: rendered, tool_call_id: toolCallId });
|
||||
emitUpdate(
|
||||
emit,
|
||||
@@ -679,6 +684,8 @@ async function runTurn(ctx) {
|
||||
tools: toolDefs,
|
||||
toolDialect: catalog.toolDialectFor(session.model),
|
||||
desktopVision: payload && payload.desktopVision === false ? false : undefined,
|
||||
timeoutMs: budget.completeTimeoutMs,
|
||||
idleMs: budget.completeIdleMs,
|
||||
},
|
||||
(ev) => {
|
||||
if (ev.type === 'contentDelta') {
|
||||
@@ -743,6 +750,11 @@ async function runTurn(ctx) {
|
||||
pushHistory(session, { role: 'user', content: goalMod.continuation(session.goal) });
|
||||
continue;
|
||||
}
|
||||
if (toolNudges < 2 && toolBudget.shouldNudgeToolCall([result && result.text, result && result.thinking].filter(Boolean).join('\n'), budget)) {
|
||||
toolNudges += 1;
|
||||
pushHistory(session, { role: 'user', content: toolBudget.continueToolMessage() });
|
||||
continue;
|
||||
}
|
||||
return endTurn(emit, session, jobId, tracker, {
|
||||
type: 'end',
|
||||
reason: 'stop',
|
||||
|
||||
Reference in New Issue
Block a user