Skip to main content

LlmClientTrait

Trait LlmClientTrait 

Source
pub trait LlmClientTrait: Send + Sync {
    // Required method
    fn chat<'life0, 'life1, 'async_trait>(
        &'life0 self,
        req: &'life1 ChatRequest,
    ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, LlmError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Object-safe interface for issuing a single chat-completions call.

Why: Lets AgentLoop accept an Arc<dyn LlmClientTrait> so the network client can be swapped for a deterministic stub in tests. Send + Sync are required because the loop runs under tokio and may be shared across tasks. What: A one-method async trait whose signature matches LlmClient::chat exactly, so the concrete client implements it by trivial delegation. Test: llm_client_implements_trait.

Required Methods§

Source

fn chat<'life0, 'life1, 'async_trait>( &'life0 self, req: &'life1 ChatRequest, ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, LlmError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Issue one chat-completions request and return the parsed response.

Why: A single-method surface keeps the mock trivial and the loop’s dependency minimal. What: Mirrors LlmClient::chat: posts req and yields a ChatResponse or an LlmError. Test: Exercised by the real client in llm_client_implements_trait and by the scripted mock in agent_loop::tests.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§