use adk_core::{AdkError, Result, Tool, ToolContext, ToolEffect};
use async_trait::async_trait;
use serde_json::{Value, json};
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct AnthropicAdvisorTool {
model: String,
max_uses: Option<u32>,
max_tokens: Option<u32>,
caching_ttl: Option<&'static str>,
}
impl AnthropicAdvisorTool {
pub fn new(model: impl Into<String>) -> Self {
Self { model: model.into(), max_uses: None, max_tokens: None, caching_ttl: None }
}
pub fn with_max_uses(mut self, max_uses: u32) -> Self {
self.max_uses = Some(max_uses);
self
}
pub fn with_max_tokens(mut self, max_tokens: u32) -> Self {
self.max_tokens = Some(max_tokens);
self
}
pub fn with_caching(mut self, one_hour: bool) -> Self {
self.caching_ttl = Some(if one_hour { "1h" } else { "5m" });
self
}
}
#[async_trait]
impl Tool for AnthropicAdvisorTool {
fn name(&self) -> &str {
"advisor"
}
fn description(&self) -> &str {
"Consults a stronger Claude model for guidance mid-task (server-side)."
}
fn is_builtin(&self) -> bool {
true
}
fn effect(&self) -> ToolEffect {
ToolEffect::ReadOnly
}
fn declaration(&self) -> Value {
let mut tool = json!({
"type": "advisor_20260301",
"name": "advisor",
"model": self.model,
});
if let Some(max_uses) = self.max_uses {
tool["max_uses"] = json!(max_uses);
}
if let Some(max_tokens) = self.max_tokens {
tool["max_tokens"] = json!(max_tokens);
}
if let Some(ttl) = self.caching_ttl {
tool["caching"] = json!({ "type": "ephemeral", "ttl": ttl });
}
json!({
"name": self.name(),
"description": self.description(),
"x-adk-anthropic-tool": tool,
})
}
async fn execute(&self, _ctx: Arc<dyn ToolContext>, _args: Value) -> Result<Value> {
Err(AdkError::tool(
"the advisor tool runs on Anthropic's servers, inside the model request",
))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_declaration_carries_every_configured_field() {
let tool = AnthropicAdvisorTool::new("claude-opus-5-5")
.with_max_uses(3)
.with_max_tokens(4_096)
.with_caching(true);
assert_eq!(
tool.declaration(),
json!({
"name": "advisor",
"description": "Consults a stronger Claude model for guidance mid-task (server-side).",
"x-adk-anthropic-tool": {
"type": "advisor_20260301",
"name": "advisor",
"model": "claude-opus-5-5",
"max_uses": 3,
"max_tokens": 4_096,
"caching": { "type": "ephemeral", "ttl": "1h" },
},
})
);
assert!(tool.is_builtin());
assert_eq!(tool.effect(), ToolEffect::ReadOnly);
}
}