fix: disable think and keep alive until manual unload
This commit is contained in:
+23
-5
@@ -117,11 +117,9 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
|
|||||||
model,
|
model,
|
||||||
messages,
|
messages,
|
||||||
tools,
|
tools,
|
||||||
keep_alive: "10m",
|
keep_alive: -1,
|
||||||
options: {
|
think: false,
|
||||||
think: true,
|
options: { num_ctx: 262144 },
|
||||||
num_ctx: 262144,
|
|
||||||
} as Record<string, unknown>,
|
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const lastError = err instanceof Error ? err.message : String(err);
|
const lastError = err instanceof Error ? err.message : String(err);
|
||||||
@@ -162,6 +160,16 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
|
|||||||
} else {
|
} else {
|
||||||
log.info("» agent finished (no tool calls)");
|
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 {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
output: assistantMessage.content || undefined,
|
output: assistantMessage.content || undefined,
|
||||||
@@ -239,6 +247,16 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.warning(`» agent hit max iterations (${MAX_ITERATIONS})`);
|
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 {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: `Agent exceeded maximum iterations (${MAX_ITERATIONS})`,
|
error: `Agent exceeded maximum iterations (${MAX_ITERATIONS})`,
|
||||||
|
|||||||
Reference in New Issue
Block a user