pub struct AgentConfig {
pub provider: ProviderKind,
pub model: Option<String>,
pub base_url: Option<String>,
pub request_timeout_secs: u64,
pub max_steps: u32,
pub max_tokens: u32,
pub system_prompt: Option<String>,
pub prompt_caching: bool,
pub max_run_secs: Option<u64>,
}Expand description
Configuration for the agent plugin.
Build it with AgentConfig::load (file + env), tweak it in tests with
AgentConfig::from_toml_str, or construct it by hand and adjust fields.
Fields§
§provider: ProviderKindWhich provider protocol to speak.
model: Option<String>Model name, or None for the provider default.
base_url: Option<String>Provider base URL, or None for the provider default.
request_timeout_secs: u64Per-request HTTP timeout in seconds.
max_steps: u32Maximum agent-loop iterations before the run stops.
max_tokens: u32Token budget for one agent run (estimated + provider-reported).
system_prompt: Option<String>System prompt prepended to every agent run, if set.
prompt_caching: boolMark Anthropic prompt-cache breakpoints. On by default; OpenAI caches on its own and ignores this.
max_run_secs: Option<u64>Wall-clock limit for one agent run in seconds, or None for no limit.
Implementations§
Source§impl AgentConfig
impl AgentConfig
Sourcepub fn load() -> Result<Self, AgentError>
pub fn load() -> Result<Self, AgentError>
Load configuration from autumn.toml plus the environment.
Reads ./autumn.toml (or the file named by AGENT_CONFIG_FILE),
applies the [agent] table, then applies AGENT_* overrides.
A missing file is fine: defaults plus environment still work.
§Errors
Returns AgentError with ErrorKind::Config
when the file cannot be read or parsed, an AGENT_* variable has an
invalid value, or the merged configuration fails validation.
Sourcepub fn from_toml_str(document: &str) -> Result<Self, AgentError>
pub fn from_toml_str(document: &str) -> Result<Self, AgentError>
Parse the [agent] table out of a TOML document.
Pure and side-effect free: this is the seam unit tests exercise.
A missing [agent] table yields defaults.
§Errors
Returns AgentError with ErrorKind::Config
when the document is not valid TOML, [agent] is not a table, the
table sets api_key/api-key (fail-closed: the key must come from
AGENT_API_KEY), or a field fails validation.
Sourcepub fn apply_env(&mut self) -> Result<(), AgentError>
pub fn apply_env(&mut self) -> Result<(), AgentError>
Apply AGENT_* environment variables over the current values.
Recognised: AGENT_PROVIDER, AGENT_MODEL, AGENT_BASE_URL,
AGENT_REQUEST_TIMEOUT_SECS, AGENT_MAX_STEPS, AGENT_MAX_TOKENS,
AGENT_SYSTEM_PROMPT, AGENT_PROMPT_CACHING (true/false),
AGENT_MAX_RUN_SECS. Unset variables leave the value alone.
§Errors
Returns AgentError with ErrorKind::Config
when a set variable has an invalid value (unknown provider, malformed
number, or a number that does not fit its field).
Sourcepub fn api_key(&self) -> Result<String, AgentError>
pub fn api_key(&self) -> Result<String, AgentError>
Read the provider API key from the environment.
The key comes only from AGENT_API_KEY. Never log the return value.
§Errors
Returns AgentError with ErrorKind::Config
when AGENT_API_KEY is not set.
Sourcepub fn validate(&self) -> Result<(), AgentError>
pub fn validate(&self) -> Result<(), AgentError>
Check every field for sanity. Called by AgentConfig::load and
AgentConfig::from_toml_str; call it again after hand-editing.
§Errors
Returns AgentError with ErrorKind::Config
when any field is out of its accepted range or malformed.
Sourcepub fn resolved_model(&self) -> &str
pub fn resolved_model(&self) -> &str
Effective model name: the configured one, or the provider default.
Sourcepub fn resolved_base_url(&self) -> &str
pub fn resolved_base_url(&self) -> &str
Effective base URL: the configured one, or the provider default.
Trait Implementations§
Source§impl Clone for AgentConfig
impl Clone for AgentConfig
Source§impl Debug for AgentConfig
impl Debug for AgentConfig
Auto Trait Implementations§
impl Forget for AgentConfig
impl Freeze for AgentConfig
impl RefUnwindSafe for AgentConfig
impl Send for AgentConfig
impl Sync for AgentConfig
impl Unpin for AgentConfig
impl UnsafeUnpin for AgentConfig
impl UnwindSafe for AgentConfig
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Scoped for T
impl<T> Scoped for T
Source§fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
ScopeQuery for this type. Resolves the
registered scope at .load() time, not here.