pub trait SchemaAdapter:
Send
+ Sync
+ Debug {
// Required method
fn normalize_schema(&self, schema: Value) -> Value;
// Provided methods
fn normalize_tool_name<'a>(&self, name: &'a str) -> Cow<'a, str> { ... }
fn empty_schema(&self) -> Value { ... }
}Expand description
Core traits and types.
Always available regardless of feature flags. Includes:
Agent- The fundamental trait for all agentsTool/Toolset- For extending agents with capabilitiesSession/State- For managing conversation contextEvent- For streaming agent responsesAdkError/Result- Unified error handling Normalizes JSON Schema for a specific LLM provider’s function-calling API.
Each provider has different schema requirements. The adapter transforms raw MCP tool schemas into the provider’s accepted format at request time.
§Default Implementations
normalize_tool_name: Truncates names exceeding 64 bytes at a valid UTF-8 character boundary.empty_schema: Returns{"type": "object", "properties": {}}as the fallback when no input schema is provided.
§Thread Safety
All implementations must be Send + Sync to support concurrent request building
across async tasks.
Required Methods§
Sourcefn normalize_schema(&self, schema: Value) -> Value
fn normalize_schema(&self, schema: Value) -> Value
Provided Methods§
Sourcefn normalize_tool_name<'a>(&self, name: &'a str) -> Cow<'a, str>
fn normalize_tool_name<'a>(&self, name: &'a str) -> Cow<'a, str>
Normalize a tool name for this provider’s limits.
Default implementation truncates names exceeding 64 bytes at the nearest valid UTF-8 character boundary, preserving the prefix.
§Arguments
name- The original tool name.
§Returns
A Cow::Borrowed reference if the name fits within 64 bytes, or a
Cow::Owned truncated string otherwise.
§Example
use adk_core::SchemaAdapter;
use serde_json::Value;
use std::borrow::Cow;
#[derive(Debug)]
struct TestAdapter;
impl SchemaAdapter for TestAdapter {
fn normalize_schema(&self, schema: Value) -> Value { schema }
}
let adapter = TestAdapter;
// Short names are returned as-is
assert_eq!(adapter.normalize_tool_name("get_weather"), Cow::Borrowed("get_weather"));
// Long names are truncated to at most 64 bytes
let long_name = "a".repeat(100);
let result = adapter.normalize_tool_name(&long_name);
assert!(result.len() <= 64);Sourcefn empty_schema(&self) -> Value
fn empty_schema(&self) -> Value
Fallback schema when a tool provides no parameters_schema.
Returns {"type": "object", "properties": {}} by default, which represents
a tool that accepts no parameters.
§Example
use adk_core::SchemaAdapter;
use serde_json::{json, Value};
#[derive(Debug)]
struct TestAdapter;
impl SchemaAdapter for TestAdapter {
fn normalize_schema(&self, schema: Value) -> Value { schema }
}
let adapter = TestAdapter;
assert_eq!(adapter.empty_schema(), json!({"type": "object", "properties": {}}));Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl SchemaAdapter for GeminiSchemaAdapter
impl SchemaAdapter for GeminiSchemaAdapter
Source§fn normalize_tool_name<'a>(&self, name: &'a str) -> Cow<'a, str>
fn normalize_tool_name<'a>(&self, name: &'a str) -> Cow<'a, str>
Truncates tool names exceeding 64 bytes at a valid UTF-8 character boundary.
Preserves the prefix of the name, truncating from the end.
Source§fn empty_schema(&self) -> Value
fn empty_schema(&self) -> Value
Returns the fallback schema for tools with no parameters_schema.
Gemini requires {"type": "object", "properties": {}} as the minimum
valid function declaration parameters.