Skip to main content

AgentConfig

Struct AgentConfig 

Source
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: ProviderKind

Which 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: u64

Per-request HTTP timeout in seconds.

§max_steps: u32

Maximum agent-loop iterations before the run stops.

§max_tokens: u32

Token budget for one agent run (estimated + provider-reported).

§system_prompt: Option<String>

System prompt prepended to every agent run, if set.

§prompt_caching: bool

Mark 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

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn resolved_model(&self) -> &str

Effective model name: the configured one, or the provider default.

Source

pub fn resolved_base_url(&self) -> &str

Effective base URL: the configured one, or the provider default.

Trait Implementations§

Source§

impl Clone for AgentConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AgentConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scoped for T
where T: Send + Sync + 'static,

Source§

fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>

Open a deferred ScopeQuery for this type. Resolves the registered scope at .load() time, not here.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more