Skip to main content

rtb_ai/
thinking.rs

1//! Anthropic extended-thinking configuration.
2//!
3//! Setting [`crate::ChatRequest::thinking`] to a `Some(...)` value
4//! enables Anthropic's extended-thinking mode — the model produces a
5//! private chain-of-thought (surfaced as
6//! [`crate::ChatStreamEvent::ThinkingToken`] on the streaming path)
7//! before the user-facing reply. Available only on the
8//! Anthropic-direct path; silently ignored on other providers.
9
10use serde::{Deserialize, Serialize};
11
12/// How much the model is allowed to "think" before replying.
13#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
14#[serde(tag = "kind", rename_all = "snake_case")]
15#[non_exhaustive]
16pub enum ThinkingMode {
17    /// Hard-cap the thinking-token budget per turn. Anthropic
18    /// recommends ≥ 1024 tokens for any meaningful reasoning.
19    Budget {
20        /// Maximum thinking tokens. The model may use fewer.
21        max_tokens: u32,
22    },
23}
24
25impl ThinkingMode {
26    /// Convenience constructor.
27    #[must_use]
28    pub const fn budget(max_tokens: u32) -> Self {
29        Self::Budget { max_tokens }
30    }
31}