Hmbown/CodeWhale · error

Kimi native web search exceeded the bounded tool-call loop

Error message

Kimi native web search exceeded the bounded tool-call loop

What it means

The Kimi native web-search exchange runs as a bounded loop: each round executes returned $web_search calls and re-requests, but only up to MAX_NATIVE_SEARCH_TOOL_CALLS (8) total calls. If the loop exits its budget without the model producing a final answer, the client bails rather than looping forever.

Solutions

  1. Rephrase/narrow the search query so the model converges faster
  2. Raise MAX_NATIVE_SEARCH_TOOL_CALLS if 8 is genuinely too small (mind cost/latency)
  3. Inspect the conversation for a loop trigger (same query repeatedly re-issued)
  4. Treat as a retry-able upstream misbehavior with backoff, or fall back to non-native search

Example fix

// before
const MAX_NATIVE_SEARCH_TOOL_CALLS: usize = 8;
// after
const MAX_NATIVE_SEARCH_TOOL_CALLS: usize = 16; // search-heavy workloads need more rounds
Defensive patterns

Strategy: fallback

Validate before calling

// keep queries narrow so the model converges in few rounds
if query.split_whitespace().count() > 30 { query = summarize(query); }

Try / catch

match provider.search(req).await {
    Err(e) if e.to_string().contains("bounded tool-call loop") => {
        warn!("Kimi search looped past budget; retrying once with narrowed query");
        provider.search(req.with_narrowed_query()).await
    }
    other => other,
}

Prevention

When it happens

Trigger: search_builtin exhausts its loop iterations because Kimi keeps returning additional rounds of $web_search tool calls and never yields a final non-tool-call answer within the 8-call budget.

Common situations: Very broad or ambiguous search queries causing many search rounds; a Kimi model stuck in a tool-call loop; MAX budget tuned too low for search-heavy workloads.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/3d5c80af8c28ea21. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/client/provider_native_search/kimi.rs:126

                .get("id")
                .and_then(Value::as_str)
                .context("Kimi native web-search call omitted id")?;
            let arguments = tool_call
                .pointer("/function/arguments")
                .and_then(Value::as_str)
                .context("Kimi native web-search call omitted arguments")?;
            let _: Value = serde_json::from_str(arguments)
                .context("Kimi native web-search arguments were not valid JSON")?;
            messages.push(json!({
                "role": "tool",
                "tool_call_id": id,
                "name": "$web_search",
                "content": arguments,
            }));
        }
    }

    bail!("Kimi native web search exceeded the bounded tool-call loop")
}

async fn search_formula(
    client: &ProviderNativeSearchClient,
    request: &ProviderNativeSearchRequest,
) -> Result<ProviderNativeSearchResponse> {
    let formula_path = format!("formulas/{WEB_SEARCH_FORMULA_URI}");
    let tools_payload = client
        .get_json(&api_url(
            &client.inner.base_url,
            &format!("{formula_path}/tools"),
        ))
        .await?;
    let tools = formula_web_search_tools(&tools_payload)?;
    let mut messages = vec![json!({
        "role": "user",
        "content": super::search_prompt(request),
    })];

View on GitHub (pinned to 73e0f67d83)