{"record":{"id":"c73b81d51e49ce35","repo":"Mintplex-Labs/anything-llm","slug":"no-valid-provider-found-for-the-agent","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/ephemeral.js","lineNumber":192,"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.#workspace?.agentModel) return this.#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.#workspace?.agentProvider ?? null;\n    this.model = this.#fetchModel();\n\n    // If provider resolved to model router, resolve the actual provider/model\n    if (this.provider === \"anythingllm-router\") {","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/ephemeral.js#L174-L210","documentation":"Thrown by EphemeralAgentHandler.#fetchModel() (server/utils/agents/ephemeral.js:187) when this.provider is null AND #getFallbackProvider() also returns null. The fallback path tries the system LLM_PROVIDER and calls providerDefault() to find a model; it returns null when LLM_PROVIDER is unset or set to a provider whose default model cannot be resolved. Net effect: neither the workspace nor the system provides a usable agent provider+model pair.","triggerScenarios":"Ephemeral agent init runs with #workspace.agentProvider unset/null, and process.env.LLM_PROVIDER is unset OR set to a provider whose providerDefault() yields no model.","commonSituations":"Fresh install where the system LLM preference was never set; workspace created before any provider configured; LLM_PROVIDER points at a provider that needs a model-pref env (e.g. OPEN_MODEL_PREF) which is also unset; multi-model loading disabled and no system default.","solutions":["Configure a system LLM provider in System Settings -> LLM Preference (sets LLM_PROVIDER) plus its model, then retry.","Or set the workspace Agent Provider and Agent Model explicitly.","For providers that need a model-pref env (OPEN_MODEL_PREF, MOONSHOT_AI_MODEL_PREF, etc.), set that env too so providerDefault() returns a value."],"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 canResolveEphemeralProvider(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 (!canResolveEphemeralProvider(workspace)) return showSetupError('Configure a system or workspace agent provider.');","typeGuard":null,"tryCatchPattern":"try { await ephemeral.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 path succeeds.","Set workspace-level agentProvider/agentModel for workspaces that use agents.","Run a boot self-test calling providerDefault() for the configured provider and warn if null."],"tags":["config","agent-provider","model-resolution","ephemeral","agents"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}