fix: diagnostic issues

This commit is contained in:
2026-05-31 14:39:37 -05:00
parent 57e6529f97
commit 4a1743126e
2 changed files with 18 additions and 13 deletions
+17 -12
View File
@@ -115,19 +115,22 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
let response: Awaited<ReturnType<typeof ollama.chat>>;
try {
response = await retry(
() => ollama.chat({
model,
messages,
tools,
keep_alive: -1,
think: false,
options: { num_ctx: 262144 },
}),
() =>
ollama.chat({
model,
messages,
tools,
keep_alive: -1,
think: false,
options: { num_ctx: 262144 },
}),
{
delaysMs: [3_000, 8_000],
shouldRetry: (err) => {
const msg = err instanceof Error ? err.message : String(err);
return /unexpected EOF|XML syntax error|ECONNRESET|ETIMEDOUT|fetch failed/i.test(msg);
return /unexpected EOF|XML syntax error|ECONNRESET|ETIMEDOUT|fetch failed/i.test(
msg,
);
},
label: `Ollama turn ${iterations}`,
},
@@ -138,12 +141,14 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
return { success: false, error: `Ollama request failed: ${lastError}` };
}
const promptTokens = (response as Record<string, unknown>).prompt_eval_count as number | undefined;
const evalTokens = (response as Record<string, unknown>).eval_count as number | undefined;
const promptTokens = response.prompt_eval_count;
const evalTokens = response.eval_count;
if (promptTokens !== undefined) {
const total = promptTokens + (evalTokens ?? 0);
const pct = Math.round((total / 262144) * 100);
log.info(` context: ${promptTokens} prompt + ${evalTokens ?? 0} eval = ${total} tokens (${pct}% of limit)`);
log.info(
` context: ${promptTokens} prompt + ${evalTokens ?? 0} eval = ${total} tokens (${pct}% of limit)`,
);
}
const assistantMessage = response.message;