xai-org/grok-build · error

Failed to create agent config: {e}

Error message

Failed to create agent config: {e}

What it means

run_single_turn wraps failures from AgentConfig::new_from_toml_cfg(&raw_config) with 'Failed to create agent config: {e}'. The raw TOML loaded fine, but one or more fields could not be converted into the typed AgentConfig (missing required key, wrong type, or semantically invalid value).

Source

Thrown at crates/codegen/xai-grok-pager/src/headless.rs:785

        None => std::env::current_dir()?,
        Some(ref p) => dunce::canonicalize(p)?,
    };

    let mut emitter = HeadlessEmitter::new(options.output_format, options.json_schema.is_some());

    if options.include_partial_messages
        && options.output_format != OutputFormat::StreamingMessagesJson
    {
        eprintln!(
            "warning: --include-partial-messages only affects --output-format streaming-messages-json; ignoring it"
        );
    }

    let t_spawn = Instant::now();
    let raw_config = xai_grok_shell::config::load_effective_config()
        .map_err(|e| anyhow::anyhow!("Failed to load config: {e}"))?;
    let mut agent_config = AgentConfig::new_from_toml_cfg(&raw_config)
        .map_err(|e| anyhow::anyhow!("Failed to create agent config: {e}"))?;

    // Only canonical tokens are stamped early; remapped menu ids need the post-session catalog resolve below
    if let Some(ref token) = options.reasoning_effort
        && let Some(effort) = parse_canonical_effort_token(token)
    {
        agent_config.reasoning_effort_override = Some(effort);
    }
    // Stamp `-m` early so the initial system prompt uses it, not a later SetSessionModel.
    if let Some(ref model) = options.model {
        agent_config.default_model_override = Some(model.clone());
    }

    agent_config.resolve_runtime_fields(&xai_grok_shell::agent::config::RuntimeResolutionContext {
        raw_config: &raw_config,
        remote_settings: None,
        is_headless: true,
        cli_subagents: None,
        cli_web_search_model: None,

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Read the inner {e}; it names the offending field and expected type
  2. Align config.toml keys/types with the current AgentConfig schema
  3. Delete or rename the stale config so defaults are regenerated
  4. Pin the config schema version / run the tool's config-migration step

Example fix

// before (config.toml)
max_turns = "25"
// after
max_turns = 25
Defensive patterns

Strategy: validation

Validate before calling

let raw = xai_grok_shell::config::load_effective_config()?;
// dry-convert to catch schema drift before starting a session
if let Err(e) = xai_grok_shell::agent::config::AgentConfig::new_from_toml_cfg(&raw) {
    eprintln!("agent config schema mismatch: {e:#}");
    std::process::exit(2);
}

Type guard

fn toml_field_is<'a, T: serde::Deserialize<'a>>(cfg: &'a toml::Value, key: &str) -> bool {
    cfg.get(key).map(|v| T::deserialize(v).is_ok()).unwrap_or(false)
}

Try / catch

match AgentConfig::new_from_toml_cfg(&raw_config) {
    Ok(cfg) => cfg,
    Err(e) => { eprintln!("Failed to create agent config: {e:#}"); std::process::exit(2); }
}

Prevention

When it happens

Trigger: Calling run_single_turn with a config whose parsed TOML does not match AgentConfig's expected schema: e.g. model id empty, api_key not a string, numeric fields given as strings, unknown enum value for a setting.

Common situations: Upgrading the binary after AgentConfig gained/renamed fields while the old config.toml persists; copying a config from another tool with a different schema; hand-editing values to the wrong type.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/9c3aee6b3d226054. Report an issue: GitHub.