pub struct LlmConfig {
pub model: String,
pub api_key: Option<String>,
pub base_url: Option<String>,
pub temp: f64,
pub max_tokens: Option<u32>,
pub prompt_cache_key: Option<String>,
pub project_id: Option<String>,
pub location: Option<String>,
}Expand description
LLM provider configuration — single config for any provider.
Two optional fields control routing:
api_key: None → auto from env vars (OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.)base_url: None → auto-detect provider from model name; Some → custom endpoint
use sgr_agent::LlmConfig;
let c = LlmConfig::auto("gpt-4o"); // env vars
let c = LlmConfig::with_key("sk-...", "claude-3-haiku"); // explicit key
let c = LlmConfig::endpoint("sk-or-...", "https://openrouter.ai/api/v1", "gpt-4o"); // custom
let c = LlmConfig::auto("gpt-4o").temperature(0.9).max_tokens(2048); // builderFields§
§model: String§api_key: Option<String>§base_url: Option<String>§temp: f64§max_tokens: Option<u32>§prompt_cache_key: Option<String>OpenAI prompt cache key — caches system prompt prefix server-side.
project_id: Option<String>Vertex AI project ID (enables Vertex routing when set).
location: Option<String>Vertex AI location (default: “global”).
Implementations§
Source§impl LlmConfig
impl LlmConfig
Sourcepub fn auto(model: impl Into<String>) -> Self
pub fn auto(model: impl Into<String>) -> Self
Auto-detect provider from model name, use env vars for auth.
Sourcepub fn with_key(api_key: impl Into<String>, model: impl Into<String>) -> Self
pub fn with_key(api_key: impl Into<String>, model: impl Into<String>) -> Self
Explicit API key, auto-detect provider from model name.
Sourcepub fn endpoint(
api_key: impl Into<String>,
base_url: impl Into<String>,
model: impl Into<String>,
) -> Self
pub fn endpoint( api_key: impl Into<String>, base_url: impl Into<String>, model: impl Into<String>, ) -> Self
Custom OpenAI-compatible endpoint (OpenRouter, Ollama, LiteLLM, etc.).
Sourcepub fn vertex(project_id: impl Into<String>, model: impl Into<String>) -> Self
pub fn vertex(project_id: impl Into<String>, model: impl Into<String>) -> Self
Vertex AI — uses gcloud ADC for auth (no API key needed).
Sourcepub fn temperature(self, t: f64) -> Self
pub fn temperature(self, t: f64) -> Self
Set temperature.
Sourcepub fn max_tokens(self, m: u32) -> Self
pub fn max_tokens(self, m: u32) -> Self
Set max output tokens.
Sourcepub fn prompt_cache_key(self, key: impl Into<String>) -> Self
pub fn prompt_cache_key(self, key: impl Into<String>) -> Self
Set OpenAI prompt cache key for server-side system prompt caching.
Sourcepub fn compaction_model(&self) -> String
pub fn compaction_model(&self) -> String
Infer a cheap/fast model for compaction based on the primary model.
Sourcepub fn for_compaction(&self) -> Self
pub fn for_compaction(&self) -> Self
Create a compaction config — cheap model, low max_tokens.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for LlmConfig
impl<'de> Deserialize<'de> for LlmConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for LlmConfig
impl RefUnwindSafe for LlmConfig
impl Send for LlmConfig
impl Sync for LlmConfig
impl Unpin for LlmConfig
impl UnsafeUnpin for LlmConfig
impl UnwindSafe for LlmConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more