Skip to main content

Module schema_adapter

Module schema_adapter 

Source
Expand description

Core traits and types.

Always available regardless of feature flags. Includes:

  • Agent - The fundamental trait for all agents
  • Tool / Toolset - For extending agents with capabilities
  • Session / State - For managing conversation context
  • Event - For streaming agent responses
  • AdkError / Result - Unified error handling Provider-aware JSON Schema normalization for tool declarations. Schema normalization adapter for LLM provider function-calling APIs.

Each LLM provider has different JSON Schema requirements for tool parameters. The SchemaAdapter trait provides a consistent interface for transforming raw MCP tool schemas into the provider’s accepted format at request time.

§Architecture

McpToolset returns raw schemas verbatim. Each model adapter implements SchemaAdapter to normalize schemas according to its backend’s limitations. This separation keeps MCP tool discovery independent of LLM-specific concerns.

§Example

use adk_core::SchemaAdapter;
use serde_json::{json, Value};
use std::borrow::Cow;

#[derive(Debug)]
struct MyAdapter;

impl SchemaAdapter for MyAdapter {
    fn normalize_schema(&self, schema: Value) -> Value {
        // Apply provider-specific transforms
        schema
    }
}

let adapter = MyAdapter;
let raw = json!({"type": "object", "properties": {"name": {"type": "string"}}});
let normalized = adapter.normalize_schema(raw);

Structs§

GenericSchemaAdapter
Default schema adapter for providers with no specific requirements (Ollama, etc.).

Traits§

SchemaAdapter
Normalizes JSON Schema for a specific LLM provider’s function-calling API.