Skip to main content

Config

Struct Config 

Source
#[non_exhaustive]
pub struct Config {
Show 27 fields pub model: String, pub base_url: String, pub api_key: Option<String>, pub api_key_env: String, pub system_prompt: String, pub temperature: Option<f32>, pub max_tokens: Option<u32>, pub max_iterations: usize, pub effort: Option<String>, pub response_format: Option<Value>, pub extra_body: Map<String, Value>, pub max_total_output_tokens: Option<u64>, pub max_tool_output_bytes: Option<usize>, pub cwd: PathBuf, pub additional_dirs: Vec<PathBuf>, pub load_project_context: bool, pub sandbox: SandboxPolicy, pub approval: ApprovalPolicy, pub auto_approved_tools: HashSet<String>, pub approval_handler: Option<Box<dyn Fn(&ToolCall) -> bool + Send + Sync>>, pub pre_tool_hook: Option<Box<dyn Fn(&str, &Value) -> Option<String> + Send + Sync>>, pub post_tool_hook: Option<Box<dyn Fn(&str, &str, bool) + Send + Sync>>, pub prompts: HashMap<String, String>, pub compact_after_messages: Option<usize>, pub tool_overrides: HashMap<String, ToolOverride>, pub extra_headers: HashMap<String, String>, pub event_sink: Option<EventSink>,
}
Expand description

Everything that shapes an crate::Agent: the model and endpoint, the credentials, sampling parameters, the system prompt, and per-tool overrides.

Build one with Config::builder.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§model: String

Model identifier as understood by the endpoint, e.g. anthropic/claude-opus-4-8 or openai/gpt-5 on OpenRouter.

§base_url: String

Base URL of the OpenAI-compatible endpoint (no trailing /chat/...).

§api_key: Option<String>

Explicit API key. If None, Self::api_key_env is consulted.

§api_key_env: String

Environment variable to read the API key from when Self::api_key is unset.

§system_prompt: String

System prompt prepended to every conversation.

§temperature: Option<f32>

Optional sampling temperature.

§max_tokens: Option<u32>

Optional output token cap.

§max_iterations: usize

Maximum number of model/tool iterations per crate::Agent::send call.

§effort: Option<String>

Reasoning/effort level sent to the model (reasoning_effort).

§response_format: Option<Value>

Structured-output constraint (response_format), e.g. a json_schema.

§extra_body: Map<String, Value>

Extra request-body fields merged in (provider-native passthrough: prompt-cache controls, provider-specific knobs).

§max_total_output_tokens: Option<u64>

Optional cap on cumulative output tokens across one crate::Agent::send loop; the loop stops once exceeded.

§max_tool_output_bytes: Option<usize>

Max bytes of a single tool result fed back into the conversation. Output beyond this is truncated with a notice, so one runaway command (a huge log, a binary dump) can’t explode the context window. None disables the cap. Defaults to 100 KB.

§cwd: PathBuf

Working directory tools operate within.

§additional_dirs: Vec<PathBuf>

Additional roots beyond cwd (the analog of --add-dir / multi-root): searched for project-context files and available to tools.

§load_project_context: bool

Whether to auto-load CLAUDE.md / AGENTS.md into the system prompt.

§sandbox: SandboxPolicy

Filesystem confinement applied to write-capable tools.

§approval: ApprovalPolicy

When the agent must seek approval before running a tool.

§auto_approved_tools: HashSet<String>

Tools that never require approval under ApprovalPolicy::OnRequest.

§approval_handler: Option<Box<dyn Fn(&ToolCall) -> bool + Send + Sync>>

Consulted when a tool call needs approval; None denies by default.

§pre_tool_hook: Option<Box<dyn Fn(&str, &Value) -> Option<String> + Send + Sync>>

Runs before each tool executes; may block the call.

§post_tool_hook: Option<Box<dyn Fn(&str, &str, bool) + Send + Sync>>

Runs after each tool executes (observational).

§prompts: HashMap<String, String>

Named prompt templates (skills / slash commands). A user message of the form /<name> <args> is expanded to the template with {args} filled.

§compact_after_messages: Option<usize>

If set, the conversation is compacted once it grows beyond this many messages (older middle turns are summarized into one marker), keeping the system prompt and the most recent turns.

§tool_overrides: HashMap<String, ToolOverride>

Per-tool enable/disable + description overrides, keyed by tool name.

§extra_headers: HashMap<String, String>

Extra HTTP headers sent with every request (e.g. OpenRouter’s HTTP-Referer / X-Title attribution headers).

§event_sink: Option<EventSink>

Optional sink for streaming crate::AgentEvents.

Implementations§

Source§

impl Config

Source

pub fn builder() -> ConfigBuilder

Start building a Config from defaults.

Source

pub fn tool_enabled(&self, name: &str) -> bool

Whether a tool is enabled given the overrides (defaults to enabled).

Source

pub fn needs_approval(&self, tool: &str) -> bool

Whether a tool call requires approval before it runs, given the policy and the auto-approve allowlist.

Source

pub fn tool_description<'a>(&'a self, name: &str, builtin: &'a str) -> &'a str

The effective description for a tool, applying any override.

Source§

impl Config

Source

pub fn from_profile_file( path: impl AsRef<Path>, profile: &str, ) -> Result<ConfigBuilder>

Load a named profile from a JSON config file into a builder. Layered: start from defaults, then apply the named profile’s set fields.

Trait Implementations§

Source§

impl Default for Config

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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