fix(agents): inject num_ctx for Ollama OpenAI-compat API to prevent 4096 token cap#27292
fix(agents): inject num_ctx for Ollama OpenAI-compat API to prevent 4096 token cap#27292Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Conversation
…096 token cap Ollama defaults to num_ctx=4096, so conversations lose history after a few messages. The native "ollama" API already sends num_ctx via the options field, but when users configure api: "openai-completions" the parameter is never sent and the server silently truncates input. 1. Detect Ollama providers using the OpenAI-compat API (by provider name or baseUrl pattern) and wrap the stream function to inject num_ctx into the request payload via onPayload. 2. Fix fallback model resolution to match models by ID instead of blindly using models[0], so the correct contextWindow/maxTokens values are used when the model isn't in the registry. Closes openclaw#27278
Greptile SummaryFixes two related bugs affecting Ollama models configured with Root Cause 1: Missing Root Cause 2: Incorrect fallback model resolution - When a model wasn't found in the registry, the fallback code blindly used The implementation is backward-compatible, follows existing patterns (consistent with Confidence Score: 5/5
Last reviewed commit: d2cd136 |
Summary
api: "openai-completions", causing conversation history to be lost after a few messages. The nativeapi: "ollama"path sendsnum_ctxbut the OpenAI-compat path does not.num_ctxinto the request payload viaonPayload. (2) Fix fallback model resolution to match by model ID instead of blindly usingmodels[0].api: "ollama"path, non-Ollama providers, and the model registry lookup are unaffected.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Ollama models configured with
api: "openai-completions"now respect the configuredcontextWindowvalue. Conversation history is maintained up to the configured limit instead of being silently truncated at 4096 tokens.Security Impact (required)
Testing
npx vitest run src/agents/pi-embedded-runner/run/attempt— 9 tests ✓npx vitest run src/agents/pi-embedded-runner/model— 20 tests ✓Rollback Plan
Revert the single commit. Non-Ollama providers are unaffected. Ollama reverts to the 4096 default.