1use async_trait::async_trait;
2use futures_core::Stream;
3use serde_json::Value;
4use std::pin::Pin;
5
6use crate::types::{AgentResult, ChatMessage, ResponseFormat};
7
8mod anthropic;
9mod openai;
10mod registry;
11
12pub use anthropic::AnthropicClient;
13pub use openai::{LlmClientConfig, OpenAiClient};
14pub use registry::{LlmClientBuilder, LlmProvider};
15
16#[derive(Clone, Debug)]
17pub enum StreamChunk {
18 Text(String),
19 Thought(String),
20 ToolCall(Value),
21 Usage(UsageInfo),
22 Stop,
23}
24
25#[derive(Clone, Debug, Default)]
26pub struct UsageInfo {
27 pub prompt_tokens: Option<u32>,
28 pub completion_tokens: Option<u32>,
29 pub total_tokens: Option<u32>,
30}
31
32#[derive(Clone, Debug, Default)]
33pub struct LlmCapabilities {
34 pub supports_streaming: bool,
35 pub supports_tools: bool,
36 pub supports_vision: bool,
37 pub supports_thinking: bool,
38 pub max_context_tokens: Option<u32>,
39 pub max_output_tokens: Option<u32>,
40}
41
42#[derive(Debug, Clone, Default)]
44pub struct ReasoningConfig {
45 pub enabled: Option<bool>,
47 pub budget_tokens: Option<u64>,
49 pub effort: Option<ReasoningEffort>,
51}
52
53#[derive(Debug, Clone)]
55pub enum ReasoningEffort {
56 None,
57 Low,
58 Medium,
59 High,
60 XHigh,
61}
62
63#[async_trait]
64pub trait LlmClient: Send + Sync {
65 async fn chat(
66 &self,
67 messages: &[ChatMessage],
68 tools: &[Value],
69 reasoning: Option<&ReasoningConfig>,
70 response_format: Option<&ResponseFormat>,
71 ) -> AgentResult<Value>;
72
73 async fn chat_stream(
74 &self,
75 messages: &[ChatMessage],
76 tools: &[Value],
77 reasoning: Option<&ReasoningConfig>,
78 response_format: Option<&ResponseFormat>,
79 ) -> AgentResult<Pin<Box<dyn Stream<Item = AgentResult<StreamChunk>> + Send>>>;
80
81 fn capabilities(&self) -> LlmCapabilities;
82
83 fn model_name(&self) -> &str {
86 "unknown"
87 }
88}