Skip to content

feat(agent): reasoning_effort config + working-offline example - #937

Merged
edenreich merged 2 commits into
mainfrom
feat/working-offline-example
Jul 19, 2026
Merged

edenreich merged 2 commits into
mainfrom
feat/working-offline-example

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

What

  • agent.reasoning_effort (minimal|low|medium|high, env INFER_AGENT_REASONING_EFFORT): passed through the existing WithOptions on both the streaming and sync LLM paths via the SDK's ReasoningEffort request field (already in the pinned sdk v1.22.0). Empty default = no behavior change; invalid values fail config load in Config.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 via INFER_* env vars, including prompt-prefix-cache-friendly settings (git_context/tree disabled 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 missing working-offline, postgres-storage, and a2a-traces rows 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 green
  • docker compose config validates; live chat + headless smoke tests against the compose gateway
  • Invalid reasoning_effort value fails fast at config load (verified)

Cross-repo / docs

  • No schema or gateway changes; SDK already carries the field.
  • Docs ticket for the new config key to be filed against inference-gateway/docs:
    • Title: [DOCS] Document agent.reasoning_effort CLI setting
    • Body: New CLI config agent.reasoning_effort (minimal|low|medium|high, env INFER_AGENT_REASONING_EFFORT) constrains reasoning-model thinking; affected pages: CLI configuration reference. Source PR: this PR.
  • Separate gateway finding (not in this PR): non-streaming requests time out after 30s despite CLIENT_TIMEOUT=600s — to be filed against inference-gateway/inference-gateway.

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.
@edenreich
edenreich requested a review from a team as a code owner July 19, 2026 01:37
@edenreich
edenreich merged commit cadd230 into main Jul 19, 2026
1 check passed
@edenreich
edenreich deleted the feat/working-offline-example branch July 19, 2026 10:20
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.150.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Jul 19, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant