Mintplex-Labs/anything-llm · error · APIError

The agent model failed to respond

Error message

The agent model failed to respond: ${error.message}

What it means

AIbitat's #safeProviderCall wraps every LLM provider invocation for agent execution: if providerCall() throws and the chat was not user-aborted (this._aborted rethrows the original error untouched), the failure is logged and rethrown as APIError('The agent model failed to respond: <original message>'). The suffix is the actual provider error — auth failure, model-not-found, quota, timeout, or connection refusal for local models.

Solutions

  1. Read the message suffix after 'failed to respond:' — 401/403 fix the key, 404 fix the model name, 429 wait/raise quota, ECONNREFUSED fix the endpoint.
  2. Run a plain (non-agent) chat with the same workspace model to isolate agent-vs-provider issues.
  3. For local models, set the base URL to a host the server container can reach (host.docker.internal or the LAN IP).
  4. Reduce context: fewer documents in prompt, smaller chat history, or a larger-context model.
Defensive patterns

Strategy: retry

Validate before calling

async function providerReady(provider) {
  try {
    const r = await provider.complete([{ role: "user", content: "ping" }]);
    return Boolean(r.textResponse);
  } catch {
    return false;
  }
}

Try / catch

async function chatWithRetry(send, attempts = 3) {
  for (let i = 0; i < attempts; i++) {
    try {
      return await send();
    } catch (e) {
      const transient = /429|5\d\d|timeout|ECONNRESET|overloaded/i.test(e.message);
      if (!transient || i === attempts - 1) throw e;
      await new Promise((r) => setTimeout(r, 2 ** i * 1000));
    }
  }
}

Prevention

When it happens

Trigger: Any agent chat/tool-execution turn where the provider call fails: invalid or expired API key, model name unavailable to the account, provider 429/5xx/timeout, context window overflow from a large workspace prompt, or a local endpoint (Ollama, LM Studio) that is down or unreachable from the container.

Common situations: Key rotated in the provider dashboard but not in workspace settings; switching workspace to a model the key can't access; Docker 'localhost' pointing at the container instead of the host running the local LLM; oversized system prompt + documents exceeding the model's context; provider transient outage during a long agent run.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18). Data as JSON: /api/errors/8f1787ee60470835. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/agents/aibitat/index.js:1003

  /**
   * Wrapper for provider calls that catches errors and converts them to APIError.
   * This ensures provider errors are properly surfaced to the user instead of crashing.
   *
   * @param {Function} providerCall - Async function that calls the provider
   * @returns {Promise<any>} - The result of the provider call
   * @throws {APIError} - If the provider call fails
   */
  async #safeProviderCall(providerCall) {
    try {
      return await providerCall();
    } catch (error) {
      // User-initiated abort - rethrow as-is so the chat loop exits quietly.
      if (this._aborted) throw error;
      console.error(`[AIbitat] Provider error: ${error.message}`, {
        hide_meta: true,
      });
      throw new APIError(`The agent model failed to respond: ${error.message}`);
    }
  }

  /**
   * Handle the async (streaming) execution of the provider
   * with tool calls. Reads the provider from this.providerInstance.
   *
   * @param messages
   * @param functions
   * @param byAgent
   *
   * @returns {Promise<string>}
   */
  async handleAsyncExecution(
    messages = [],
    functions = [],
    byAgent = null,
    depth = 0

View on GitHub (pinned to 20f6d3546c)