Repository navigation
feat(chat): add /effort command for runtime anthropic reasoning effort - #963
Merged
Merged
Conversation
…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
marked this pull request as ready for review
July 28, 2026 15:43
edenreich
commented
Jul 28, 2026
Co-authored-by: Eden Reich <[email protected]>
Contributor
|
🎉 This PR is included in version 0.154.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Stacked on #962 (base branch
feat/942-anthropic-messages-adapter).What
New
/effortchat command that switches the reasoning effort level at runtime for Anthropic models, delivered on the wire asoutput_config.effortover the nativePOST /v1/messagespath./effortwith 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 withnot supported.The CLI hardcodes
lowas its Anthropic default (config.DefaultAnthropicEffort) - deliberately below the API default ofhigh- so every/v1/messagesrequest carries an explicitoutput_config.effort. A status-bar indicator (Effort: <level>, own config togglechat.status_bar.indicators.effort) shows the level in effect next to the model, for Anthropic models only.How
agent.reasoning_effortconfig remains the startup seed; the accepted set is extended withxhighandmax(config.ReasoningEffortLevelsis now the single source for validation, the setter, and the shortcut).domain.AgentServicegainsSetReasoningEffort/GetReasoningEffort;AgentServiceImplguards the level with an RWMutex and both request paths re-read it per request, so a mid-session switch applies to the next turn.AnthropicMessagesadapter maps the capturedreasoning_effortontooutput_config.effortinbuildMessagesRequest(minimalmaps tolow- Anthropic's scale starts atlow; unset and unknown values fall back to the hardcodedlowdefault).effortSourceinterface and gates on the current model's provider prefix, so the indicator follows/modelswitches and mid-session/effortchanges.xhigh/maxtohighon the chat-completions path as a safety net (relevant when effort was set on an Anthropic model and the user then/model-switches away).Runrestarted the chain from the bare client when tools were present (s.client.WithTools), silently discardingMaxTokens,ReasoningEffortandSkipMCP; it now chains like the streaming path.MessagesOutputConfig).Tests
not supportedrejection on non-Anthropic, invalid-level error, arg bounds.minimal, clamping elsewhere).output_config.efforton the marshaled request for every level,minimal -> low, absent when unset or unknown.tests/integration/agent_messages_test.go): runtime switch toxhighlands on both recorded/v1/messagesbodies of a tool round-trip.task test,task test:e2e,task lint,task fmtall green.Cross-repo impact
schemasfeat(openapi): add output_config effort to CreateMessagesRequest schemas#161 (merged, v0.16.0) addedoutput_config.efforttoCreateMessagesRequest.sdkfeat: sync generated types with schemas v0.16.0 sdk#148 (merged, v1.30.0) synced the generated types./v1/messagesforwards bodies verbatim.[DOCS]issue for inference-gateway/docs covering/effortand the extendedagent.reasoning_effortvalues.