adk_anthropic/tool_search.rs
1/// Provider-level configuration for regex-based dynamic tool discovery.
2///
3/// `ToolSearchConfig` allows filtering tools by name using a regex pattern.
4/// When set on an Anthropic provider, only tools whose names match the pattern
5/// are loaded per request. When not set, all available tools are loaded.
6///
7/// # Example
8///
9/// ```
10/// use adk_anthropic::ToolSearchConfig;
11///
12/// let config = ToolSearchConfig::new("^(search|fetch)_.*");
13/// assert!(config.matches("search_web").unwrap());
14/// assert!(!config.matches("delete_all").unwrap());
15/// ```
16#[derive(Debug, Clone)]
17pub struct ToolSearchConfig {
18 /// Regex pattern for matching tool names.
19 pub pattern: String,
20}
21
22impl ToolSearchConfig {
23 /// Create a new `ToolSearchConfig` with the given regex pattern.
24 ///
25 /// The pattern is compiled on each call to [`matches`](Self::matches).
26 /// An invalid regex will produce an error at match time.
27 pub fn new(pattern: impl Into<String>) -> Self {
28 Self { pattern: pattern.into() }
29 }
30
31 /// Check whether `tool_name` matches the configured regex pattern.
32 ///
33 /// # Errors
34 ///
35 /// Returns an error if the pattern is not a valid regex.
36 pub fn matches(&self, tool_name: &str) -> Result<bool, regex::Error> {
37 let re = regex::Regex::new(&self.pattern)?;
38 Ok(re.is_match(tool_name))
39 }
40}