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 { ... }
fn parameters_field(&self) -> &'static str { ... }
}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": {}}));Sourcefn parameters_field(&self) -> &'static str
fn parameters_field(&self) -> &'static str
The function-declaration field this adapter’s output must be posted under.
A provider may accept more than one schema dialect on different fields —
Gemini takes an OpenAPI subset on parameters and standard JSON Schema
on parametersJsonSchema, and the two are mutually exclusive. The
reduction and the field name are therefore one decision: a schema
reduced for one dialect but posted under the other’s field is either
rejected outright, or silently accepted carrying constraints the model
was never shown.
Returning the field from the adapter keeps that decision in the one place
that already knows which dialect it produced, so a caller cannot pick the
wrong one. Defaults to "parameters", which is correct for every
provider having only one such field.
§Example
use adk_core::SchemaAdapter;
use serde_json::Value;
#[derive(Debug)]
struct TestAdapter;
impl SchemaAdapter for TestAdapter {
fn normalize_schema(&self, schema: Value) -> Value { schema }
}
assert_eq!(TestAdapter.parameters_field(), "parameters");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.
Source§fn parameters_field(&self) -> &'static str
fn parameters_field(&self) -> &'static str
The function-declaration field this adapter’s output belongs under, derived from the dialect so the reduction and the field cannot disagree.