Skip to main content

Llm

Trait Llm 

Source
pub trait Llm: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn generate_content<'life0, 'async_trait>(
        &'life0 self,
        req: LlmRequest,
        stream: bool,
    ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<LlmResponse, AdkError>> + Send>>, AdkError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn schema_adapter(&self) -> &dyn SchemaAdapter { ... }
    fn uses_interactions_api(&self) -> bool { ... }
}
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 The core trait for all LLM providers.

Implementations wrap a specific model API (Gemini, OpenAI, Anthropic, etc.) and produce a stream of responses for a given request.

Required Methods§

Source

fn name(&self) -> &str

Returns the model identifier (e.g., “gemini-2.5-flash”).

Source

fn generate_content<'life0, 'async_trait>( &'life0 self, req: LlmRequest, stream: bool, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<LlmResponse, AdkError>> + Send>>, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Generates content from the given request, optionally streaming.

Provided Methods§

Source

fn schema_adapter(&self) -> &dyn SchemaAdapter

Returns the schema adapter for this provider.

The schema adapter normalizes raw JSON Schema from MCP tools into the format accepted by this provider’s function-calling API.

Default implementation returns GenericSchemaAdapter, which applies safe transforms suitable for most providers. Override this method to return a provider-specific adapter (e.g., GeminiSchemaAdapter, OpenAiStrictSchemaAdapter).

Source

fn uses_interactions_api(&self) -> bool

Returns true if this model is configured to use a server-managed environment (e.g., Gemini Interactions API) where the provider owns the tool-calling loop and filesystem.

This is used at agent build time to detect conflicts with client-side sandbox tools that would produce competing filesystems.

Default implementation returns false. Override in providers that support server-managed environments.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§