{"record":{"id":"1131021b70641d25","repo":"danny-avila/LibreChat","slug":"agent-not-found","errorCode":null,"errorMessage":"Agent not found","messagePattern":"Agent not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"api/server/services/Endpoints/agents/initialize.js","lineNumber":251,"sourceCode":"      })\n    : Promise.resolve([]);\n  const skillCreateAllowedPromise = skillsCapabilityEnabled\n    ? getSkillToolDeps().canCreateSkill({ req })\n    : Promise.resolve(false);\n  const skillStatesPromise = accessibleSkillIdsPromise.then((accessibleSkillIds) =>\n    loadSkillStates({\n      userId: req.user.id,\n      appConfig,\n      getUserById: db.getUserById,\n      accessibleSkillIds,\n    }),\n  );\n  const primaryAgentPromise = endpointOption.agent;\n  const modelsConfigPromise = getModelsConfig(req);\n  const validatedPrimaryAgentPromise = Promise.all([primaryAgentPromise, modelsConfigPromise]).then(\n    async ([primaryAgent, modelsConfig]) => {\n      if (!primaryAgent) {\n        throw new Error('Agent not found');\n      }\n\n      const validationResult = await validateAgentModel({\n        req,\n        res,\n        modelsConfig,\n        logViolation,\n        agent: primaryAgent,\n      });\n      if (!validationResult.isValid) {\n        throw new Error(validationResult.error?.message);\n      }\n\n      return { primaryAgent, modelsConfig };\n    },\n  );\n\n  /**","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Endpoints/agents/initialize.js#L233-L269","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const primaryAgent = await endpointOption.agent;\nif (!primaryAgent) {\n  return res.status(404).json({ error: 'The configured agent no longer exists' });\n}","typeGuard":"function isAgentResolved(agent) {\n  return agent != null && typeof agent === 'object' && Boolean(agent.id);\n}","tryCatchPattern":"try { await initializeClient(req, res, endpointOption); }\ncatch (e) { if (/Agent not found/.test(e.message)) return res.status(404).json({ error: 'Agent not found' }); throw e; }","preventionTips":["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."],"tags":["agents","not-found","configuration","initialization"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}