Skip to main content

AgentConfig

Struct AgentConfig 

Source
pub struct AgentConfig {
Show 17 fields pub model: String, pub api_key: Option<String>, pub system_instructions: Option<SystemInstructions>, pub capabilities: Option<CapabilitiesConfig>, pub workspaces: Vec<PathBuf>, pub tools: Vec<ToolDefinition>, pub policies: Vec<PolicyRule>, pub triggers: Vec<TriggerEntry>, pub hooks: Vec<HookEntry>, pub skills: Vec<PathBuf>, pub mcp_servers: Vec<McpServer>, pub conversation_id: Option<String>, pub save_dir: Option<PathBuf>, pub app_data_dir: Option<PathBuf>, pub response_schema: Option<JsonSchema>, pub gemini: Option<GeminiConfig>, pub max_quota_retries: Option<u32>,
}
Expand description

Full configuration for creating an agent.

Covers model selection, system instructions, capabilities, tools, policies, hooks, MCP servers, structured output, and Gemini backend settings. All fields have sensible defaults.

§Construction patterns

AgentConfig deliberately supports two construction paths:

  1. TypedBuilder — ergonomic chained construction with impl IntoIterator setters for collection fields. Preferred for programmatic use:

    let config = AgentConfig::builder()
        .model("gemini-3.5-flash")
        .build();
  2. Struct literal with ..Default::default() — convenient for deserialization (serde), config files, and framework code that already has fully-formed values:

    let config = AgentConfig {
        model: "gemini-3.5-flash".into(),
        ..AgentConfig::default()
    };

Both paths are supported intentionally. The builder provides ergonomic setters (e.g. accepting impl IntoIterator for collection fields), while struct literals enable direct field access for serialization roundtrips and downstream framework integration.

Fields§

§model: String

The model name (e.g. "gemini-3.5-flash").

§api_key: Option<String>

API key. Falls back to GEMINI_API_KEY env var if None.

§system_instructions: Option<SystemInstructions>

Optional system instructions (custom text or templated sections).

§capabilities: Option<CapabilitiesConfig>

Agent capability toggles (tool lists, subagents, compaction).

§workspaces: Vec<PathBuf>

Workspace directories the agent can access.

When empty (the default), the Python SDK’s own default of [os.getcwd()] applies. Set explicitly to override.

§tools: Vec<ToolDefinition>

Custom tool definitions exposed to the agent.

§policies: Vec<PolicyRule>

Policy rules evaluated before each tool call.

§triggers: Vec<TriggerEntry>

Event-driven triggers attached to this agent.

§hooks: Vec<HookEntry>

Lifecycle hooks (pre-turn, post-turn, pre-tool, etc.).

§skills: Vec<PathBuf>

Paths to skill instruction files loaded into the agent.

Serializes as "skills_paths" to match the Python SDK field name.

§mcp_servers: Vec<McpServer>

MCP server configurations.

§conversation_id: Option<String>

Pre-existing conversation ID to resume.

§save_dir: Option<PathBuf>

Directory where conversation state is saved.

§app_data_dir: Option<PathBuf>

Application data directory.

§response_schema: Option<JsonSchema>

Optional JSON schema for structured responses.

§gemini: Option<GeminiConfig>

Gemini model backend configuration.

Controls per-model API keys, model selection per capability, and generation parameters such as thinking_level.

Serializes as "gemini_config" to match the Python SDK field name.

§max_quota_retries: Option<u32>

Maximum number of quota retry attempts before giving up.

If None, defaults to 0 (no retries).

Implementations§

Source§

impl AgentConfig

Source

pub fn builder() -> AgentConfigBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>

Create a builder for building AgentConfig. On the builder, call .model(...)(optional), .api_key(...)(optional), .system_instructions(...)(optional), .capabilities(...)(optional), .workspaces(...)(optional), .tools(...)(optional), .policies(...)(optional), .triggers(...)(optional), .hooks(...)(optional), .skills(...)(optional), .mcp_servers(...)(optional), .conversation_id(...)(optional), .save_dir(...)(optional), .app_data_dir(...)(optional), .response_schema(...)(optional), .gemini(...)(optional), .max_quota_retries(...)(optional) to set the values of the fields. Finally, call .build() to create the instance of AgentConfig.

Source§

impl AgentConfig

Source

pub fn effective_api_key(&self) -> Option<String>

Resolve the effective API key using the same priority chain as the Python SDK’s LocalAgentConfig_build_harness_config:

  1. Per-model key (gemini.models.default.api_key)
  2. Shared GeminiConfig key (gemini.api_key)
  3. Top-level shorthand (api_key)
  4. $GEMINI_API_KEY environment variable
Source

pub fn custom_tool_names(&self) -> Vec<String>

Returns the names of all explicitly registered custom tools. To get the full list of tools including built-ins, combine this with capabilities.enabled_tools or examine tools + default semantics.

Trait Implementations§

Source§

impl Clone for AgentConfig

Source§

fn clone(&self) -> AgentConfig

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

impl<'de> Deserialize<'de> for AgentConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<AgentConfig> for LocalAgentConfig

Source§

fn from(agent: AgentConfig) -> Self

Converts to this type from the input type.
Source§

impl Serialize for AgentConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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 = 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> Ungil for T
where T: Send,

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