fix: disable think and keep alive until manual unload

This commit is contained in:
2026-05-31 12:43:38 -05:00
parent f88377cd1d
commit 41dbd09cc0
+23 -5
View File
@@ -117,11 +117,9 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
model,
messages,
tools,
keep_alive: "10m",
options: {
think: true,
num_ctx: 262144,
} as Record<string, unknown>,
keep_alive: -1,
think: false,
options: { num_ctx: 262144 },
});
} catch (err) {
const lastError = err instanceof Error ? err.message : String(err);
@@ -162,6 +160,16 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
} else {
log.info("» agent finished (no tool calls)");
}
// unload the model from memory immediately since we're done with it, to free up resources for future runs. see #829.
try {
await ollama.generate({ model, keep_alive: 0, prompt: "" });
log.info(`» unloaded model ${model} from Ollama`);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
log.warning(`» failed to unload model ${model}: ${msg}`);
}
return {
success: true,
output: assistantMessage.content || undefined,
@@ -239,6 +247,16 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
}
log.warning(`» agent hit max iterations (${MAX_ITERATIONS})`);
// unload the model from memory immediately since we're done with it, to free up resources for future runs. see #829.
try {
await ollama.generate({ model, keep_alive: 0, prompt: "" });
log.info(`» unloaded model ${model} from Ollama`);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
log.warning(`» failed to unload model ${model}: ${msg}`);
}
return {
success: false,
error: `Agent exceeded maximum iterations (${MAX_ITERATIONS})`,