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§
Sourcetype Session: ModelSession
type Session: ModelSession
The session type produced by this adapter.