Repository navigation
feat(agent): reasoning_effort config + working-offline example - #937
Merged
Merged
Conversation
Pass agent.reasoning_effort (minimal|low|medium|high, INFER_AGENT_REASONING_EFFORT) through to the SDK request so thinking models can be told to reason less - essential for local models where reasoning tokens dominate turn latency. Empty (the default) leaves requests unchanged; invalid values fail config load.
Fully offline usage: containerized gateway + CLI against a local model server (native Ollama by default for GPU access; containerized Ollama or llama.cpp as CPU-only alternatives). Configured entirely via INFER_* env vars, with prompt-prefix-cache-friendly settings and performance guidance for local models. Also adds missing rows to the root README examples table.
Contributor
|
🎉 This PR is included in version 0.150.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Merged
5 of 6 tasks
edenreich
added a commit
that referenced
this pull request
Jul 21, 2026
… cached-token visibility (#941) ## Summary Closes #938. The agent rebuilt message[0] (system prompt) every user turn with volatile content, so local LLM servers (Ollama, llama.cpp) re-prefilled the entire ~8k-token prompt on every request. This PR keeps the context fresh AND the prefix stable: - **`buildSystemPromptText` is now static** — the five volatile pieces (git context, project tree, memory index, active skill, current date) are removed from the system prompt, making message[0] byte-identical across turns (including day rollover). - **New `volatileTailMessage`** builds a per-request \<system-reminder\> user message from the volatile sections (split into `volatileContextSections`) plus the date, appended at the tail of the outbound payload only: - sync path (`Run`): appended to the request-local slice — covers headless `infer agent`; - streaming path: stashed on `EventDrivenAgent` and appended in `openStream` via `append(slices.Clone(conv), tail)`, so the shared persisted conversation is never mutated — including on reconnects and tool-loop turns. - The tail is **never persisted** and never enters the TUI; mockgateway scenario anchoring already skips \<system-reminder\> user messages. - `agent.context.*` / `memory.enabled` flags keep working — the builders self-gate, a disabled section is absent from the tail. - `infer debug agent system_prompt` still renders the full picture (static prompt + tail), and `--tokens` accounts for the volatile sections. ## Acceptance criteria (from #938) - [x] message[0] byte-identical across turns (unit + integration: `TestStreamSystemPromptStableWithVolatileTail` asserts byte-equality across all 3 requests of a tool-loop session) - [x] Volatile context still reaches the model each turn at the tail (`TestSyncRunAppendsVolatileTail`, `TestVolatileTailMessage`) - [x] Tail not persisted / not rendered (`TestOutboundConversation_AppendsTailWithoutMutatingShared`) - [x] mockgateway anchoring unaffected (existing skip covers it; integration suite green) - [x] `agent.context.*` flags keep working (`TestVolatileTailMessage` gating subtests) - [ ] Manual verification with `examples/working-offline` against local Ollama (the #937 workaround env vars remain valid but are no longer necessary) ## Gateway model metadata + cached-token visibility The caching this PR makes possible is now also observable and priced correctly: - **Cached-token display**: `C.<n>` status-bar segment next to `T.<n>` (hidden at zero) and `Cached: n tokens` in per-request metrics; mockgateway scenarios accept `usage.cached_tokens`. - **Deterministic tools order**: `GetToolDefinitions` sorts by function name, so the outbound tools array (and the system-prompt roster) stays byte-stable across turns and restarts — required for provider KV-cache hits beyond message[0]. - **Gateway model metadata** (SDK v1.23.0 → v1.25.0): `/v1/models` is fetched with `include=context_window,pricing`; gateway-reported context windows and prices are the primary source of truth. The status-bar `Context: %`, the `/model` picker rows and pricing tabs, and cost calculation all use live per-model data. - **Cache-aware cost**: `CalculateCost` bills cached prompt tokens at the gateway `cache_read_per_token` rate (full input rate when unknown); telemetry emits a `cache_read` token datapoint and `infer stats` / `/stats` gain a **Cached** column. ## Removed - **`config.DefaultModelPricing`** (~910 lines): the hardcoded model pricing map, superseded by gateway-sourced pricing. The `config.ModelPricing` type (used only by this map) is also removed. - **`config.ContextMatchers`** (~40 lines): the pattern-based context window matchers, superseded by gateway-sourced context windows. The `config.ModelMatcher` type is also removed. - **Corresponding test coverage**: per-family context window tests (Qwen, Claude, Moonshot, Gemini, Deep Research, Gemma, DeepSeek, Mistral, MiniMax, GLM, Nemotron, GPT-OSS, llama, phi), Ollama Cloud Pro defaults test, and static default price assertions in Google model defaults and Minimax defaults tests — all updated or deleted. - **`config.DefaultContextWindow` (8192 fallback)**: models with no gateway-reported and no user-configured (`context_windows:`) window are now *unknown* — auto-compaction and token-triggered session rollover gate off (manual `/compact` still works), the status-bar context indicator is hidden, and `/context` says compaction is disabled for the model. - **`freeLocalProviders`**: llamacpp/ollama models are no longer assumed free; they resolve as unknown pricing unless declared via `custom_prices:`. - **`IsVisionModel` + the 25-pattern vision table**: the "model may not support vision" chat warning is removed; images are always forwarded and the provider decides. The only remaining curated entries are `knownProModels` (2 lines) — the gateway does not report `requires_pro` yet; moving that server-side (schemas → sdk → gateway) is a drafted follow-up. ## Cross-repo impact - schemas v0.9.0 → sdk v1.25.0 → gateway v0.35.1 already ship the `CompletionUsage` token details and the `/v1/models` metadata this PR consumes. - Gateway follow-up (prepared, not yet pushed): drop `ollama_cloud` from the streaming `stream_options` exception — the #207 rationale is stale (Ollama now supports `include_usage`), and without it ollama_cloud streams carry no usage/cached-token chunk at all. ## Testing `task test`, `task test:e2e`, and `task lint` all green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
agent.reasoning_effort(minimal|low|medium|high, envINFER_AGENT_REASONING_EFFORT): passed through the existingWithOptionson both the streaming and sync LLM paths via the SDK'sReasoningEffortrequest field (already in the pinnedsdk v1.22.0). Empty default = no behavior change; invalid values fail config load inConfig.Validate.examples/working-offline/: run the CLI fully offline — containerized gateway + CLI against a local model server. Native host Ollama is the default (containers can't use the GPU, notably on macOS); containerized Ollama and self-downloading llama.cpp (Gemma 4 E4B) are CPU-only alternatives behind compose profiles. CLI configured purely viaINFER_*env vars, including prompt-prefix-cache-friendly settings (git_context/treedisabled so the model server's prompt cache holds across turns). README covers readiness detection, performance expectations by hardware, and a truly-air-gapped mode. Also adds the missingworking-offline,postgres-storage, anda2a-tracesrows to the root README examples table.Why
Local models invert the cloud cost model: prefilling the agent's ~8k-token prompt dominates turn latency, and thinking models spend most of their time on reasoning tokens. Tested end-to-end on an M4 Pro with qwen3:8b on native Ollama (tool calls verified, file written by the agent).
Verification
task build,go test ./config/ ./internal/agent/...,task lint— all greendocker compose configvalidates; live chat + headless smoke tests against the compose gatewayreasoning_effortvalue fails fast at config load (verified)Cross-repo / docs
inference-gateway/docs:[DOCS] Document agent.reasoning_effort CLI settingagent.reasoning_effort(minimal|low|medium|high, envINFER_AGENT_REASONING_EFFORT) constrains reasoning-model thinking; affected pages: CLI configuration reference. Source PR: this PR.CLIENT_TIMEOUT=600s— to be filed againstinference-gateway/inference-gateway.