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,
XHigh,
Max,
}
#[derive(Clone, Serialize, Deserialize)]
pub struct AnthropicConfig {
#[serde(skip_serializing, default)]
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, skip_serializing_if = "std::ops::Not::not")]
pub allow_insecure_http: bool,
#[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>,
}
impl std::fmt::Debug for AnthropicConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AnthropicConfig")
.field("api_key", &"[REDACTED]")
.field("model", &self.model)
.field("max_tokens", &self.max_tokens)
.field("base_url", &self.base_url)
.field("allow_insecure_http", &self.allow_insecure_http)
.field("prompt_caching", &self.prompt_caching)
.field("thinking", &self.thinking)
.field("effort", &self.effort)
.field("fast_mode", &self.fast_mode)
.field("citations", &self.citations)
.field("inference_geo", &self.inference_geo)
.field("context_management", &self.context_management)
.field("service_tier", &self.service_tier)
.field("beta_features", &self.beta_features)
.field("api_version", &self.api_version)
.field("tool_search", &self.tool_search)
.finish()
}
}
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: crate::catalog::ANTHROPIC_DEFAULT.to_string(),
max_tokens: default_max_tokens(),
base_url: None,
allow_insecure_http: false,
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 allow_insecure_http(mut self) -> Self {
self.allow_insecure_http = true;
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
}
}