#[non_exhaustive]pub struct AgentConfig<Tools = NoTools, Schema = NoSchema> {
pub system_prompt: Option<String>,
pub prompt: String,
pub model: String,
pub allowed_tools: Vec<String>,
pub max_turns: Option<u32>,
pub max_budget_usd: Option<f64>,
pub working_dir: Option<String>,
pub mcp_config: Option<String>,
pub permission_mode: PermissionMode,
pub json_schema: Option<String>,
pub resume_session_id: Option<String>,
pub verbose: bool,
/* private fields */
}Expand description
Serializable configuration passed to an AgentProvider for a single invocation.
Built by Agent::run from the builder state.
Provider implementations translate these fields into whatever format the underlying
backend expects.
§Typestate: tools vs structured output
Claude CLI has a known bug
where combining --json-schema with --allowedTools always returns
structured_output: null. To prevent this at compile time, allow_tool
and output / output_schema_raw are mutually
exclusive: using one removes the other from the available API.
use ironflow_core::provider::AgentConfig;
// OK: tools only
let _ = AgentConfig::new("search").allow_tool("WebSearch");
// OK: structured output only
let _ = AgentConfig::new("classify").output_schema_raw(r#"{"type":"object"}"#);use ironflow_core::provider::AgentConfig;
// COMPILE ERROR: cannot add tools after setting structured output
let _ = AgentConfig::new("x").output_schema_raw("{}").allow_tool("Read");use ironflow_core::provider::AgentConfig;
// COMPILE ERROR: cannot set structured output after adding tools
let _ = AgentConfig::new("x").allow_tool("Read").output_schema_raw("{}");Workaround: split the work into two steps – one agent with tools to
gather data, then a second agent with .output::<T>() to structure the result.
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.system_prompt: Option<String>Optional system prompt that sets the agent’s persona or constraints.
prompt: StringThe user prompt - the main instruction to the agent.
model: StringWhich model to use for this invocation.
Accepts any string. Use Model constants for well-known Claude models
(e.g. Model::SONNET), or pass a custom identifier for other providers.
allowed_tools: Vec<String>Allowlist of tool names the agent may invoke (empty = provider default).
max_turns: Option<u32>Maximum number of agentic turns before the provider should stop.
max_budget_usd: Option<f64>Maximum spend in USD for this single invocation.
working_dir: Option<String>Working directory for the agent process.
mcp_config: Option<String>Path to an MCP server configuration file.
permission_mode: PermissionModePermission mode controlling how the agent handles tool-use approvals.
json_schema: Option<String>Optional JSON Schema string. When set, the provider should request structured (typed) output from the model.
resume_session_id: Option<String>Optional session ID to resume a previous conversation.
When set, the provider should continue the conversation from the specified session rather than starting a new one.
verbose: boolEnable verbose/debug mode to capture the full conversation trace.
When true, the provider uses streaming output (stream-json) to
record every assistant message and tool call. The resulting
AgentOutput::debug_messages field will contain the conversation
trace for inspection.
Implementations§
Source§impl AgentConfig
impl AgentConfig
Source§impl<Tools, Schema> AgentConfig<Tools, Schema>
impl<Tools, Schema> AgentConfig<Tools, Schema>
Sourcepub fn system_prompt(self, prompt: &str) -> Self
pub fn system_prompt(self, prompt: &str) -> Self
Set the system prompt.
Sourcepub fn max_budget_usd(self, budget: f64) -> Self
pub fn max_budget_usd(self, budget: f64) -> Self
Set the maximum budget in USD.
Sourcepub fn working_dir(self, dir: &str) -> Self
pub fn working_dir(self, dir: &str) -> Self
Set the working directory.
Sourcepub fn permission_mode(self, mode: PermissionMode) -> Self
pub fn permission_mode(self, mode: PermissionMode) -> Self
Set the permission mode.
Sourcepub fn mcp_config(self, config: &str) -> Self
pub fn mcp_config(self, config: &str) -> Self
Set the MCP server configuration file path.
Source§impl<Tools> AgentConfig<Tools, NoSchema>
impl<Tools> AgentConfig<Tools, NoSchema>
Sourcepub fn allow_tool(self, tool: &str) -> AgentConfig<WithTools, NoSchema>
pub fn allow_tool(self, tool: &str) -> AgentConfig<WithTools, NoSchema>
Add an allowed tool.
Can be called multiple times to allow several tools. Returns an
AgentConfig<WithTools, NoSchema>, which cannot call
output or output_schema_raw.
This restriction exists because Claude CLI has a
known bug
where --json-schema combined with --allowedTools always returns
structured_output: null.
Workaround: use two sequential agent steps – one with tools to
gather data, then one with .output::<T>() to structure the result.
§Examples
use ironflow_core::provider::AgentConfig;
let config = AgentConfig::new("search the web")
.allow_tool("WebSearch")
.allow_tool("WebFetch");use ironflow_core::provider::AgentConfig;
// ERROR: cannot set structured output after adding tools
let _ = AgentConfig::new("x")
.allow_tool("Read")
.output_schema_raw(r#"{"type":"object"}"#);Source§impl<Schema> AgentConfig<NoTools, Schema>
impl<Schema> AgentConfig<NoTools, Schema>
Sourcepub fn output<T: JsonSchema>(self) -> AgentConfig<NoTools, WithSchema>
pub fn output<T: JsonSchema>(self) -> AgentConfig<NoTools, WithSchema>
Set structured output from a Rust type implementing JsonSchema.
The schema is serialized once at build time. When set, the provider will request typed output conforming to this schema.
Important: structured output requires max_turns >= 2.
Returns an AgentConfig<NoTools, WithSchema>, which cannot
call allow_tool.
This restriction exists because Claude CLI has a
known bug
where --json-schema combined with --allowedTools always returns
structured_output: null.
Workaround: use two sequential agent steps – one with tools to
gather data, then one with .output::<T>() to structure the result.
§Known limitations of Claude CLI structured output
The Claude CLI does not guarantee strict schema conformance for structured output. The following upstream bugs affect the behavior:
- Schema flattening (anthropics/claude-agent-sdk-python#502):
a schema like
{"type":"object","properties":{"items":{"type":"array",...}}}may return a bare array instead of the wrapper object. The CLI non-deterministically flattens schemas with a single array field. - Non-deterministic wrapping (anthropics/claude-agent-sdk-python#374): the same prompt can produce differently wrapped output across runs.
- No conformance guarantee (anthropics/claude-code#9058): the CLI does not validate output against the provided JSON schema.
Because of these bugs, ironflow’s provider layer applies multiple
fallback strategies when extracting the structured value (see
extract_structured_value).
§Examples
use ironflow_core::provider::AgentConfig;
use schemars::JsonSchema;
#[derive(serde::Deserialize, JsonSchema)]
struct Labels { labels: Vec<String> }
let config = AgentConfig::new("classify this text")
.output::<Labels>();use ironflow_core::provider::AgentConfig;
use schemars::JsonSchema;
#[derive(serde::Deserialize, JsonSchema)]
struct Out { x: i32 }
// ERROR: cannot add tools after setting structured output
let _ = AgentConfig::new("x").output::<Out>().allow_tool("Read");§Panics
Panics if the schema generated by schemars cannot be serialized
to JSON. This indicates a bug in the type’s JsonSchema derive,
not a recoverable runtime error.
Sourcepub fn output_schema_raw(self, schema: &str) -> AgentConfig<NoTools, WithSchema>
pub fn output_schema_raw(self, schema: &str) -> AgentConfig<NoTools, WithSchema>
Set structured output from a pre-serialized JSON Schema string.
Returns an AgentConfig<NoTools, WithSchema>, which cannot
call allow_tool. See output
for the rationale and workaround.
Trait Implementations§
Source§impl<Tools: Clone, Schema: Clone> Clone for AgentConfig<Tools, Schema>
impl<Tools: Clone, Schema: Clone> Clone for AgentConfig<Tools, Schema>
Source§fn clone(&self) -> AgentConfig<Tools, Schema>
fn clone(&self) -> AgentConfig<Tools, Schema>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more