use adk_anthropic::ToolSearchConfig;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ThinkingMode {
Enabled {
budget_tokens: u32,
},
Adaptive,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Effort {
Low,
Medium,
High,
Max,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnthropicConfig {
pub api_key: String,
pub model: String,
#[serde(default = "default_max_tokens")]
pub max_tokens: u32,
#[serde(skip_serializing_if = "Option::is_none")]
pub base_url: Option<String>,
#[serde(default = "default_prompt_caching")]
pub prompt_caching: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub thinking: Option<ThinkingMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub effort: Option<Effort>,
#[serde(default)]
pub fast_mode: bool,
#[serde(default)]
pub citations: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub inference_geo: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub context_management: Option<adk_anthropic::ContextManagement>,
#[serde(skip_serializing_if = "Option::is_none")]
pub service_tier: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub beta_features: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub api_version: Option<String>,
#[serde(skip)]
pub tool_search: Option<ToolSearchConfig>,
}
fn default_max_tokens() -> u32 {
4096
}
fn default_prompt_caching() -> bool {
true
}
impl Default for AnthropicConfig {
fn default() -> Self {
Self {
api_key: String::new(),
model: "claude-sonnet-4-6".to_string(),
max_tokens: default_max_tokens(),
base_url: None,
prompt_caching: true,
thinking: None,
effort: None,
fast_mode: false,
citations: false,
inference_geo: None,
context_management: None,
service_tier: None,
beta_features: Vec::new(),
api_version: None,
tool_search: None,
}
}
}
impl AnthropicConfig {
pub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self {
Self { api_key: api_key.into(), model: model.into(), ..Default::default() }
}
pub fn with_max_tokens(mut self, max_tokens: u32) -> Self {
self.max_tokens = max_tokens;
self
}
pub fn with_base_url(mut self, base_url: impl Into<String>) -> Self {
self.base_url = Some(base_url.into());
self
}
pub fn with_prompt_caching(mut self, enabled: bool) -> Self {
self.prompt_caching = enabled;
self
}
pub fn with_thinking_mode(mut self, mode: ThinkingMode) -> Self {
self.thinking = Some(mode);
self
}
pub fn with_thinking(mut self, budget_tokens: u32) -> Self {
self.thinking = Some(ThinkingMode::Enabled { budget_tokens });
self
}
pub fn with_effort(mut self, effort: Effort) -> Self {
self.effort = Some(effort);
self
}
pub fn with_fast_mode(mut self, enabled: bool) -> Self {
self.fast_mode = enabled;
self
}
pub fn with_citations(mut self, enabled: bool) -> Self {
self.citations = enabled;
self
}
pub fn with_inference_geo(mut self, geo: impl Into<String>) -> Self {
self.inference_geo = Some(geo.into());
self
}
pub fn with_service_tier(mut self, tier: impl Into<String>) -> Self {
self.service_tier = Some(tier.into());
self
}
pub fn with_context_management(mut self, cm: adk_anthropic::ContextManagement) -> Self {
self.context_management = Some(cm);
self
}
pub fn with_beta_feature(mut self, feature: impl Into<String>) -> Self {
self.beta_features.push(feature.into());
self
}
pub fn with_api_version(mut self, version: impl Into<String>) -> Self {
self.api_version = Some(version.into());
self
}
pub fn with_tool_search(mut self, config: ToolSearchConfig) -> Self {
self.tool_search = Some(config);
self
}
}