agent_core/client/
traits.rs

1use super::error::LlmError;
2use super::http::HttpClient;
3use super::models::{Message, MessageOptions, StreamEvent};
4use futures::Stream;
5use std::future::Future;
6use std::pin::Pin;
7
8/// Provider interface for LLM APIs.
9///
10/// Implement this trait to add support for new LLM providers.
11pub trait LlmProvider {
12    /// Send a message to the LLM.
13    /// Returns the assistant's response message or an error.
14    fn send_msg(
15        &self,
16        client: &HttpClient,
17        messages: &[Message],
18        options: &MessageOptions,
19    ) -> Pin<Box<dyn Future<Output = Result<Message, LlmError>> + Send>>;
20
21    /// Send a streaming message to the LLM.
22    /// Returns a stream of events as they arrive from the API.
23    fn send_msg_stream(
24        &self,
25        _client: &HttpClient,
26        _messages: &[Message],
27        _options: &MessageOptions,
28    ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamEvent, LlmError>> + Send>>, LlmError>> + Send>> {
29        Box::pin(async {
30            Err(LlmError::new(
31                "NOT_IMPLEMENTED",
32                "Streaming not supported for this provider",
33            ))
34        })
35    }
36}