Mintplex-Labs/anything-llm · error · Error
No valid provider found for the agent.
Error message
No valid provider found for the agent.
What it means
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.
Source
Thrown at server/utils/agents/index.js:450
};
}
return null;
}
/**
* Finds or assumes the model preference value to use for API calls.
* If multi-model loading is supported, we use their agent model selection of the workspace
* If not supported, we attempt to fallback to the system provider value for the LLM preference
* and if that fails - we assume a reasonable base model to exist.
* @returns {string|null} the model preference value to use in API calls
*/
#fetchModel() {
// Provider was not explicitly set for workspace, so we are going to run our fallback logic
// that will set a provider and model for us to use.
if (!this.provider) {
const fallback = this.#getFallbackProvider();
if (!fallback) throw new Error("No valid provider found for the agent.");
this.provider = fallback.provider; // re-set the provider to the fallback provider so it is not null.
return fallback.model; // set its defined model based on fallback logic.
}
// The provider was explicitly set, so check if the workspace has an agent model set.
if (this.invocation.workspace.agentModel)
return this.invocation.workspace.agentModel;
// Otherwise, we have no model to use - so guess a default model to use via the provider
// and it's system ENV params and if that fails - we return either a base model or null.
return this.providerDefault();
}
async #providerSetupAndCheck() {
this.provider = this.invocation.workspace.agentProvider ?? null; // set provider to workspace agent provider if it exists
this.model = this.#fetchModel();
// If provider resolved to model router, resolve the actual provider/modelView on GitHub (pinned to 526360e320)
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.
Example fix
// before: LLM_PROVIDER unset, workspace has no agentProvider // after (.env) LLM_PROVIDER=openai OPEN_AI_API_KEY=sk-... OPEN_MODEL_PREF=gpt-4o-mini
Defensive patterns
Strategy: validation
Validate before calling
function canResolveProvider(workspace) {
if (workspace?.agentProvider) return true;
const sys = process.env.LLM_PROVIDER;
return Boolean(sys); // providerDefault() must also yield a model
}
if (!canResolveProvider(workspace)) return showSetupError('Configure a system or workspace agent provider.'); Try / catch
try { await agent.init(); } catch (e) { if (/No valid provider found for the agent/.test(e.message)) return promptProviderSetup(); throw e; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No valid provider found for the agent.
- Foundry base path must be provided to use agents.
- GiteeAI API Key must be provided to use agents.
- Cohere API key must be provided to use agents.
- Docker Model Runner base path must be provided to use agents
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/5264dc07e4ad3043.
Report an issue: GitHub.