{"record":{"id":"9dacf40b9dc5c61a","repo":"RocketChat/Rocket.Chat","slug":"the-agent-with-id-agent-id-was-not-found","errorCode":null,"errorMessage":"The agent with id \"${agent.id}\" was not found.","messagePattern":"The agent with id \"(.+?)\" was not found\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/app/apps/server/bridges/livechat.ts","lineNumber":114,"sourceCode":"\t\t};\n\n\t\t// @ts-expect-error IVisitor vs ILivechatVisitor :(\n\t\tawait updateMessage(data);\n\t}\n\n\tprotected async createRoom(\n\t\tvisitor: IVisitor,\n\t\tagent: IUser,\n\t\tappId: string,\n\t\t{ source, customFields }: IExtraRoomParams = {},\n\t): Promise<ILivechatRoom> {\n\t\tthis.orch.debugLog(`The App ${appId} is creating a livechat room.`);\n\n\t\tlet agentRoom: SelectedAgent | undefined;\n\t\tif (agent?.id) {\n\t\t\tconst user = await Users.getAgentInfo(agent.id, settings.get('Livechat_show_agent_email'));\n\t\t\tif (!user) {\n\t\t\t\tthrow new Error(`The agent with id \"${agent.id}\" was not found.`);\n\t\t\t}\n\t\t\tagentRoom = { agentId: user._id, username: user.username };\n\t\t}\n\n\t\tconst room = await createRoom({\n\t\t\tvisitor: this.orch.getConverters()?.get('visitors').convertAppVisitor(visitor),\n\t\t\troomInfo: {\n\t\t\t\tsource: {\n\t\t\t\t\ttype: OmnichannelSourceType.APP,\n\t\t\t\t\tid: appId,\n\t\t\t\t\talias: this.orch.getManager()?.getOneById(appId)?.getName(),\n\t\t\t\t\t...(source?.type === 'app' && {\n\t\t\t\t\t\tsidebarIcon: source.sidebarIcon,\n\t\t\t\t\t\tdefaultIcon: source.defaultIcon,\n\t\t\t\t\t\tlabel: source.label,\n\t\t\t\t\t\tdestination: source.destination,\n\t\t\t\t\t}),\n\t\t\t\t},","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/app/apps/server/bridges/livechat.ts#L96-L132","documentation":"Thrown by AppLivechatBridge.createRoom when an agent.id is supplied but Users.getAgentInfo(agent.id) returns null. The bridge needs a valid agent user (with _id and username) to seed the room, so an unresolvable agent id aborts room creation.","triggerScenarios":"An App calls the livechat room creator with an agent whose id does not match a user, or matches a user who is not recognized as an agent (getAgentInfo returns null). The agent.id may be stale, deleted, or belong to a non-agent account.","commonSituations":"App hard-codes or caches an agent id that was later removed; App passes a visitor id or room id where an agent id is expected; the agent was demoted/removed from the livechat agents list; the Livechat_show_agent_email setting interacts with getAgentInfo projection and returns nothing for hidden agents.","solutions":["Verify the agent id via Users.findOneAgentById (or the livechat read accessor) before calling createRoom.","Re-fetch the agent id at call time rather than caching it long-term.","Confirm the user is actually a livechat agent (has the agent role / is in the agents collection).","If the agent may be optional, call createRoom without an agent and let routing assign one."],"exampleFix":"// before\nconst agent = { id: cachedAgentId };\nawait app.getLivechatCreator().createRoom(visitor, agent, appId);\n\n// after\nconst agent = cachedAgentId ? { id: cachedAgentId } : undefined;\nif (agent && !(await Users.findOneAgentById(agent.id))) {\n  throw new Error(`Agent ${agent.id} is not a valid livechat agent`);\n}\nawait app.getLivechatCreator().createRoom(visitor, agent, appId);","handlingStrategy":"validation","validationCode":"if (agent?.id) {\n  const found = await Users.getAgentInfo(agent.id, false);\n  if (!found) {\n    throw new Error(`Cannot create livechat room: agent ${agent.id} is not a valid agent`);\n  }\n}\nawait app.getLivechatCreator().createRoom(visitor, agent, appId);","typeGuard":"const isResolvableAgent = async (id: string): Promise<boolean> =>\n  Boolean(await Users.getAgentInfo(id, false));","tryCatchPattern":"try {\n  await app.getLivechatCreator().createRoom(visitor, agent, appId);\n} catch (e) {\n  if ((e as Error).message.includes('was not found')) {\n    // re-fetch a valid agent id or proceed without an agent\n  }\n  throw e;\n}","preventionTips":["Re-fetch agent ids at call time instead of caching long-term.","Confirm the user is an active livechat agent before passing it.","Prefer optional agent (let routing assign) when unsure."],"tags":["apps-engine","livechat","room-creation","agent","validation"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}