{"record":{"id":"5264dc07e4ad3043","repo":"Mintplex-Labs/anything-llm","slug":"no-valid-provider-found-for-the-agent-5264dc","errorCode":null,"errorMessage":"No valid provider found for the agent.","messagePattern":"No valid provider found for the agent\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agents/index.js","lineNumber":450,"sourceCode":"      };\n    }\n\n    return null;\n  }\n\n  /**\n   * Finds or assumes the model preference value to use for API calls.\n   * If multi-model loading is supported, we use their agent model selection of the workspace\n   * If not supported, we attempt to fallback to the system provider value for the LLM preference\n   * and if that fails - we assume a reasonable base model to exist.\n   * @returns {string|null} the model preference value to use in API calls\n   */\n  #fetchModel() {\n    // Provider was not explicitly set for workspace, so we are going to run our fallback logic\n    // that will set a provider and model for us to use.\n    if (!this.provider) {\n      const fallback = this.#getFallbackProvider();\n      if (!fallback) throw new Error(\"No valid provider found for the agent.\");\n      this.provider = fallback.provider; // re-set the provider to the fallback provider so it is not null.\n      return fallback.model; // set its defined model based on fallback logic.\n    }\n\n    // The provider was explicitly set, so check if the workspace has an agent model set.\n    if (this.invocation.workspace.agentModel)\n      return this.invocation.workspace.agentModel;\n\n    // Otherwise, we have no model to use - so guess a default model to use via the provider\n    // and it's system ENV params and if that fails - we return either a base model or null.\n    return this.providerDefault();\n  }\n\n  async #providerSetupAndCheck() {\n    this.provider = this.invocation.workspace.agentProvider ?? null; // set provider to workspace agent provider if it exists\n    this.model = this.#fetchModel();\n\n    // If provider resolved to model router, resolve the actual provider/model","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/index.js#L432-L468","documentation":"Thrown by AgentHandlerContext.#fetchModel() (server/utils/agents/index.js:445) when this.provider is null AND #getFallbackProvider() returns null. The fallback tries system LLM_PROVIDER and calls providerDefault() to find a model; it returns null when LLM_PROVIDER is unset or its default model cannot be resolved. Result: neither the workspace nor the system yields a usable agent provider+model pair.","triggerScenarios":"agent.init() runs with workspace.agentProvider unset/null, and process.env.LLM_PROVIDER is unset OR set to a provider whose providerDefault() returns no model.","commonSituations":"Fresh install with no system LLM preference; workspace created before any provider configured; LLM_PROVIDER points at a provider needing a model-pref env (e.g. OPEN_MODEL_PREF) that is also unset.","solutions":["Configure a system LLM provider in System Settings -> LLM Preference plus its model, then retry.","Or set the workspace Agent Provider and Agent Model explicitly.","Set any provider-specific model-pref env (OPEN_MODEL_PREF, MOONSHOT_AI_MODEL_PREF) so providerDefault() resolves a model."],"exampleFix":"// before: LLM_PROVIDER unset, workspace has no agentProvider\n// after (.env)\nLLM_PROVIDER=openai\nOPEN_AI_API_KEY=sk-...\nOPEN_MODEL_PREF=gpt-4o-mini","handlingStrategy":"validation","validationCode":"function canResolveProvider(workspace) {\n  if (workspace?.agentProvider) return true;\n  const sys = process.env.LLM_PROVIDER;\n  return Boolean(sys); // providerDefault() must also yield a model\n}\nif (!canResolveProvider(workspace)) return showSetupError('Configure a system or workspace agent provider.');","typeGuard":null,"tryCatchPattern":"try { await agent.init(); } catch (e) { if (/No valid provider found for the agent/.test(e.message)) return promptProviderSetup(); throw e; }","preventionTips":["Always configure a system LLM provider so the fallback succeeds.","Set workspace agentProvider/agentModel where agents are used.","Boot-test providerDefault() for the configured provider and warn if null."],"tags":["config","agent-provider","model-resolution","agents"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}