#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.model: StringModel identifier as understood by the endpoint, e.g.
anthropic/claude-opus-4-8 or openai/gpt-5 on OpenRouter.
base_url: StringBase 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: StringEnvironment variable to read the API key from when Self::api_key is unset.
system_prompt: StringSystem prompt prepended to every conversation.
temperature: Option<f32>Optional sampling temperature.
max_tokens: Option<u32>Optional output token cap.
max_iterations: usizeMaximum 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: PathBufWorking 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: boolWhether to auto-load CLAUDE.md / AGENTS.md into the system prompt.
sandbox: SandboxPolicyFilesystem confinement applied to write-capable tools.
approval: ApprovalPolicyWhen 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
impl Config
Sourcepub fn builder() -> ConfigBuilder
pub fn builder() -> ConfigBuilder
Start building a Config from defaults.
Sourcepub fn tool_enabled(&self, name: &str) -> bool
pub fn tool_enabled(&self, name: &str) -> bool
Whether a tool is enabled given the overrides (defaults to enabled).
Sourcepub fn needs_approval(&self, tool: &str) -> bool
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.
Sourcepub fn tool_description<'a>(&'a self, name: &str, builtin: &'a str) -> &'a str
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
impl Config
Sourcepub fn from_profile_file(
path: impl AsRef<Path>,
profile: &str,
) -> Result<ConfigBuilder>
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.