feat: add configurable context_window action input

This commit is contained in:
2026-06-01 11:25:02 -05:00
parent efbf42f3e0
commit eb8871d6d2
3 changed files with 18 additions and 4 deletions
+5 -4
View File
@@ -119,6 +119,7 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
}
const model = ctx.model ?? process.env.OLLAMA_MODEL ?? DEFAULT_MODEL;
const numCtx = ctx.payload.contextWindow ?? 262144;
log.info(`» connecting to Ollama at ${ollamaHost}, model ${model}`);
@@ -170,7 +171,7 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
tools,
keep_alive: -1,
think: false,
options: { num_ctx: 262144, temperature: 0.1 },
options: { num_ctx: numCtx, temperature: 0.1 },
}),
{
delaysMs: [3_000, 8_000],
@@ -196,11 +197,11 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
if (promptTokens !== undefined) {
const total = promptTokens + (evalTokens ?? 0);
const pct = Math.round((total / 262144) * 100);
const pct = Math.round((total / numCtx) * 100);
log.info(
` context: ${promptTokens} prompt + ${evalTokens ?? 0} eval = ${total} tokens (${pct}% of limit)`,
` context: ${promptTokens} prompt + ${evalTokens ?? 0} eval = ${total} tokens (${pct}% of ${numCtx} limit)`,
);
if (promptTokens > 200_000) {
if (promptTokens > numCtx * 0.77) {
messages = pruneToolMessages(messages);
}
}