Add reasoning/thinking support for OpenAI and Anthropic providers#24
Open
freddiev4 wants to merge 2 commits into
Open
Add reasoning/thinking support for OpenAI and Anthropic providers#24freddiev4 wants to merge 2 commits into
freddiev4 wants to merge 2 commits into
Conversation
- Add `ReasoningConfig` dataclass (effort for OpenAI, budget_tokens for Anthropic) - OpenAI: detect o-series models (o1/o3/o4-mini) and use `reasoning_effort` instead of temperature; skip `tool_choice` for compatibility - Anthropic: enable extended thinking via `thinking` param with forced temperature=1 (API requirement); normalise `thinking`/`redacted_thinking` content blocks and carry them through in `ChatMessage.thinking` - Session: store `thinking_blocks` on assistant `Message` so they are round-tripped verbatim in subsequent turns (Anthropic requirement) - `AgentConfig`: add `reasoning: ReasoningConfig | None` field threaded through to `_call_model()` - Export `ReasoningConfig` from the public `rune` package https://claude.ai/code/session_01Bv6PGmH4CY6hjYEmYpAs8i
62 tests covering: - parse_model_string and ReasoningConfig dataclass - OpenAI o-series model detection (base names and date-suffixed variants) - OpenAI chat(): reasoning_effort routing, temperature/tool_choice omission - Anthropic chat(): thinking param injection, forced temperature=1 - Anthropic _normalise(): thinking/redacted_thinking block extraction and round-trip storage via _thinking_blocks attribute - Anthropic _convert_messages(): thinking block replay in assistant turns - create_provider factory routing - Message.thinking_blocks field and to_api_format() serialisation - Session.add_assistant_message() with thinking_blocks - Session save/load round-trip including thinking_blocks - Backward-compatible load for sessions without thinking_blocks https://claude.ai/code/session_01Bv6PGmH4CY6hjYEmYpAs8i
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.
ReasoningConfigdataclass (effort for OpenAI, budget_tokens for Anthropic)reasoning_effortinstead of temperature; skip
tool_choicefor compatibilitythinkingparam with forcedtemperature=1 (API requirement); normalise
thinking/redacted_thinkingcontent blocks and carry them through in
ChatMessage.thinkingthinking_blockson assistantMessageso they areround-tripped verbatim in subsequent turns (Anthropic requirement)
AgentConfig: addreasoning: ReasoningConfig | Nonefield threadedthrough to
_call_model()ReasoningConfigfrom the publicrunepackagehttps://claude.ai/code/session_01Bv6PGmH4CY6hjYEmYpAs8i