danny-avila/LibreChat · error · Error
Agent not found
Error message
Agent not found
What it means
Thrown during agents endpoint initialization when the primary agent (endpointOption.agent) resolves to a falsy value. Before model validation, the code asserts the agent exists; a missing/null agent means the endpoint points at an agent that could not be loaded.
Source
Thrown at api/server/services/Endpoints/agents/initialize.js:251
})
: Promise.resolve([]);
const skillCreateAllowedPromise = skillsCapabilityEnabled
? getSkillToolDeps().canCreateSkill({ req })
: Promise.resolve(false);
const skillStatesPromise = accessibleSkillIdsPromise.then((accessibleSkillIds) =>
loadSkillStates({
userId: req.user.id,
appConfig,
getUserById: db.getUserById,
accessibleSkillIds,
}),
);
const primaryAgentPromise = endpointOption.agent;
const modelsConfigPromise = getModelsConfig(req);
const validatedPrimaryAgentPromise = Promise.all([primaryAgentPromise, modelsConfigPromise]).then(
async ([primaryAgent, modelsConfig]) => {
if (!primaryAgent) {
throw new Error('Agent not found');
}
const validationResult = await validateAgentModel({
req,
res,
modelsConfig,
logViolation,
agent: primaryAgent,
});
if (!validationResult.isValid) {
throw new Error(validationResult.error?.message);
}
return { primaryAgent, modelsConfig };
},
);
/**View on GitHub (pinned to 5ff282f900)
Solutions
- Verify the agent id exists and is accessible to the requesting user.
- Re-select a valid primary agent for the endpoint.
- If recently created, retry after the agent is committed/propagated.
- Remove dangling agent references from endpoints or conversations.
Defensive patterns
Strategy: validation
Validate before calling
const primaryAgent = await endpointOption.agent;
if (!primaryAgent) {
return res.status(404).json({ error: 'The configured agent no longer exists' });
} Type guard
function isAgentResolved(agent) {
return agent != null && typeof agent === 'object' && Boolean(agent.id);
} Try / catch
try { await initializeClient(req, res, endpointOption); }
catch (e) { if (/Agent not found/.test(e.message)) return res.status(404).json({ error: 'Agent not found' }); throw e; } Prevention
- Validate the agent id exists before binding it to an endpoint.
- Garbage-collect endpoint/conversation references to deleted agents.
- Return 404 cleanly at the controller boundary instead of crashing initialization.
When it happens
Trigger: The agent id referenced by the endpoint/endpointOption does not exist, was deleted, or its async load returned null; the agent belongs to another user and was filtered out by the loader.
Common situations: An agent was deleted but still referenced by an endpoint or conversation; a shared/other-user agent id used without access; a freshly created endpoint whose agent lookup fails due to propagation delay.
Related errors
- Subagent run configuration exceeds the maximum of ${MAX_SUBA
- Subagent ${agentId} failed model validation.
- Storage backend "${source}" does not support file writes
- [${req.baseUrl}] Invalid version: ${version}
- Storage backend "${source}" does not support file writes
AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12).
Data as JSON: /api/errors/1131021b70641d25.
Report an issue: GitHub.