Skip to main content

ModelAdapter

Trait ModelAdapter 

Source
pub trait ModelAdapter: Send + Sync {
    type Session: ModelSession;

    // Required method
    fn start_session<'life0, 'async_trait>(
        &'life0 self,
        config: SessionConfig,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Session, LoopError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Factory for creating model sessions.

Implement this trait to integrate a model provider (e.g. OpenRouter, Anthropic, a local LLM server) with the agent loop. Agent holds a single adapter and calls start_session once when Agent::start is invoked.

§Example

use agentkit_loop::{ModelAdapter, ModelSession, SessionConfig, LoopError};
use async_trait::async_trait;

struct MyAdapter;

#[async_trait]
impl ModelAdapter for MyAdapter {
    type Session = MySession;

    async fn start_session(&self, config: SessionConfig) -> Result<MySession, LoopError> {
        // Initialize provider-specific session state here.
        Ok(MySession { /* ... */ })
    }
}

Required Associated Types§

Source

type Session: ModelSession

The session type produced by this adapter.

Required Methods§

Source

fn start_session<'life0, 'async_trait>( &'life0 self, config: SessionConfig, ) -> Pin<Box<dyn Future<Output = Result<Self::Session, LoopError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create a new model session from the given configuration.

§Errors

Returns LoopError if the provider connection or initialisation fails.

Implementors§