Skip to content

feat(chat): add /effort command for runtime anthropic reasoning effort - #963

Merged
edenreich merged 8 commits into
mainfrom
feat/effort-command
Jul 28, 2026
Merged

edenreich merged 8 commits into
mainfrom
feat/effort-command

Conversation

@edenreich

@edenreich edenreich commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #962 (base branch feat/942-anthropic-messages-adapter).

What

New /effort chat command that switches the reasoning effort level at runtime for Anthropic models, delivered on the wire as output_config.effort over the native POST /v1/messages path. /effort with no argument shows the current level and the available ones; /effort <level> switches it for subsequent requests. Levels autocomplete (low | medium | high | xhigh | max). Non-Anthropic models are rejected with not supported.

The CLI hardcodes low as its Anthropic default (config.DefaultAnthropicEffort) - deliberately below the API default of high - so every /v1/messages request carries an explicit output_config.effort. A status-bar indicator (Effort: <level>, own config toggle chat.status_bar.indicators.effort) shows the level in effect next to the model, for Anthropic models only.

How

  • agent.reasoning_effort config remains the startup seed; the accepted set is extended with xhigh and max (config.ReasoningEffortLevels is now the single source for validation, the setter, and the shortcut).
  • domain.AgentService gains SetReasoningEffort/GetReasoningEffort; AgentServiceImpl guards the level with an RWMutex and both request paths re-read it per request, so a mid-session switch applies to the next turn.
  • The AnthropicMessages adapter maps the captured reasoning_effort onto output_config.effort in buildMessagesRequest (minimal maps to low - Anthropic's scale starts at low; unset and unknown values fall back to the hardcoded low default).
  • The status bar reads the live level through a narrow effortSource interface and gates on the current model's provider prefix, so the indicator follows /model switches and mid-session /effort changes.
  • Non-Anthropic providers clamp xhigh/max to high on the chat-completions path as a safety net (relevant when effort was set on an Anthropic model and the user then /model-switches away).
  • Fixes a builder-chain drop on the sync path: Run restarted the chain from the bare client when tools were present (s.client.WithTools), silently discarding MaxTokens, ReasoningEffort and SkipMCP; it now chains like the streaming path.
  • SDK bumped v1.29.0 -> v1.30.0 (types-only sync with schemas v0.16.0, brings MessagesOutputConfig).

Tests

  • Shortcut unit tests: show current/default, lowercased set on Anthropic model, not supported rejection on non-Anthropic, invalid-level error, arg bounds.
  • Agent unit tests: setter validation/reset, per-provider effort mapping (Anthropic passthrough incl. minimal, clamping elsewhere).
  • Adapter table test: output_config.effort on the marshaled request for every level, minimal -> low, absent when unset or unknown.
  • Integration (tests/integration/agent_messages_test.go): runtime switch to xhigh lands on both recorded /v1/messages bodies of a tool round-trip.
  • task test, task test:e2e, task lint, task fmt all green.

Cross-repo impact

…le adapter

Anthropic prompt caching never engaged because every request went through
the OpenAI-compatible /v1/chat/completions endpoint, which cannot carry
cache_control breakpoints. The agent's SDK client is now wrapped in an
AnthropicMessages adapter that sends anthropic/* models to the gateway's
native POST /v1/messages passthrough and translates the Anthropic SSE
stream back into OpenAI-shaped chunks, leaving the downstream stream
processing, tool-call accumulation and TUI untouched. Non-Anthropic
providers delegate verbatim; removing the integration is deleting the
adapter files and reverting one container line.

The adapter places three cache breakpoints: the system prompt, the last
tool definition, and a rolling breakpoint on the newest non-volatile
content block, skipping the injected <system-reminder> tail so it never
consumes a cache slot. Cache-read tokens surface through the existing
cached-tokens path; cache-creation tokens flow through a new side channel
into session stats, cost calculation (billed at the gateway-advertised
cache_write_per_token rate) and telemetry.

The mock gateway now serves POST /v1/messages with native Anthropic SSE
and an anthropic-cache scenario, so the whole path is covered hermetically
by unit, integration and e2e tests.

Closes #942
…le adapter

Anthropic prompt caching never engaged because every request went through
the OpenAI-compatible /v1/chat/completions endpoint, which cannot carry
cache_control breakpoints. The agent's SDK client is now wrapped in an
AnthropicMessages adapter that sends anthropic/* models to the gateway's
native POST /v1/messages passthrough and translates the Anthropic SSE
stream back into OpenAI-shaped chunks, leaving the downstream stream
processing, tool-call accumulation and TUI untouched. Non-Anthropic
providers delegate verbatim; removing the integration is deleting the
adapter files and reverting one container line.

The adapter places three cache breakpoints: the system prompt, the last
tool definition, and a rolling breakpoint on the newest non-volatile
content block, skipping the injected <system-reminder> tail so it never
consumes a cache slot. Cache-read tokens surface through the existing
cached-tokens path; cache-creation tokens flow through a new side channel
into session stats, cost calculation (billed at the gateway-advertised
cache_write_per_token rate) and telemetry.

The mock gateway now serves POST /v1/messages with native Anthropic SSE
and an anthropic-cache scenario, so the whole path is covered hermetically
by unit, integration and e2e tests.

Closes #942
@edenreich
edenreich marked this pull request as ready for review July 28, 2026 15:43
@edenreich
edenreich requested a review from a team as a code owner July 28, 2026 15:43
Comment thread internal/agent/agent.go Resolved
Base automatically changed from feat/942-anthropic-messages-adapter to main July 28, 2026 16:02
@edenreich
edenreich merged commit f7a9ef7 into main Jul 28, 2026
1 check passed
@edenreich
edenreich deleted the feat/effort-command branch July 28, 2026 16:18
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.154.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 28, 2026
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