RocketChat/Rocket.Chat · error · Error

The agent with id "${agent.id}" was not found.

Error message

The agent with id "${agent.id}" was not found.

What it means

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.

Source

Thrown at apps/meteor/app/apps/server/bridges/livechat.ts:114

		};

		// @ts-expect-error IVisitor vs ILivechatVisitor :(
		await updateMessage(data);
	}

	protected async createRoom(
		visitor: IVisitor,
		agent: IUser,
		appId: string,
		{ source, customFields }: IExtraRoomParams = {},
	): Promise<ILivechatRoom> {
		this.orch.debugLog(`The App ${appId} is creating a livechat room.`);

		let agentRoom: SelectedAgent | undefined;
		if (agent?.id) {
			const user = await Users.getAgentInfo(agent.id, settings.get('Livechat_show_agent_email'));
			if (!user) {
				throw new Error(`The agent with id "${agent.id}" was not found.`);
			}
			agentRoom = { agentId: user._id, username: user.username };
		}

		const room = await createRoom({
			visitor: this.orch.getConverters()?.get('visitors').convertAppVisitor(visitor),
			roomInfo: {
				source: {
					type: OmnichannelSourceType.APP,
					id: appId,
					alias: this.orch.getManager()?.getOneById(appId)?.getName(),
					...(source?.type === 'app' && {
						sidebarIcon: source.sidebarIcon,
						defaultIcon: source.defaultIcon,
						label: source.label,
						destination: source.destination,
					}),
				},

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Verify the agent id via Users.findOneAgentById (or the livechat read accessor) before calling createRoom.
  2. Re-fetch the agent id at call time rather than caching it long-term.
  3. Confirm the user is actually a livechat agent (has the agent role / is in the agents collection).
  4. If the agent may be optional, call createRoom without an agent and let routing assign one.

Example fix

// before
const agent = { id: cachedAgentId };
await app.getLivechatCreator().createRoom(visitor, agent, appId);

// after
const agent = cachedAgentId ? { id: cachedAgentId } : undefined;
if (agent && !(await Users.findOneAgentById(agent.id))) {
  throw new Error(`Agent ${agent.id} is not a valid livechat agent`);
}
await app.getLivechatCreator().createRoom(visitor, agent, appId);
Defensive patterns

Strategy: validation

Validate before calling

if (agent?.id) {
  const found = await Users.getAgentInfo(agent.id, false);
  if (!found) {
    throw new Error(`Cannot create livechat room: agent ${agent.id} is not a valid agent`);
  }
}
await app.getLivechatCreator().createRoom(visitor, agent, appId);

Type guard

const isResolvableAgent = async (id: string): Promise<boolean> =>
  Boolean(await Users.getAgentInfo(id, false));

Try / catch

try {
  await app.getLivechatCreator().createRoom(visitor, agent, appId);
} catch (e) {
  if ((e as Error).message.includes('was not found')) {
    // re-fetch a valid agent id or proceed without an agent
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12). Data as JSON: /api/errors/9dacf40b9dc5c61a. Report an issue: GitHub.