{"record":{"id":"cff82764199c2cda","repo":"mastra-ai/mastra","slug":"agent-agentid-not-found","errorCode":null,"errorMessage":"Agent \"${agentId}\" not found","messagePattern":"Agent \"(.+?)\" not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"channels/slack/src/provider.ts","lineNumber":1057,"sourceCode":"    if (!isAgentIdForm && !agentIdOrOptions.name) {\n      throw new Error('connect({ id, name }): \"name\" is required when connecting without an agent id');\n    }\n\n    const client = this.#requireManifestClient();\n\n    const baseUrl = this.#getBaseUrl();\n    if (!baseUrl) {\n      throw new Error(\n        'SlackProvider baseUrl not set. Configure studioHost/studioProtocol/studioPort in Mastra server config, or call setBaseUrl().',\n      );\n    }\n\n    // In the agentId form, the agent must exist. In the options form the id may\n    // belong to a registered agent or an AgentController — resolve which one so\n    // the installation records who owns it.\n    const agent = this.#resolveAgent(agentId);\n    if (isAgentIdForm && !agent) {\n      throw new Error(`Agent \"${agentId}\" not found`);\n    }\n    let ownerType: SlackOwnerType = 'agent';\n    if (!isAgentIdForm && !agent) {\n      const controller = this.#resolveAgentController(agentId);\n      if (!controller) {\n        throw new Error(`No agent or agent controller found with id \"${agentId}\"`);\n      }\n      ownerType = 'agentController';\n    }\n\n    // If there's already a pending installation, return its authorization URL\n    // instead of creating a duplicate Slack app\n    const storage = await this.#getStorage();\n    const existingRecord = await storage.getInstallationByAgent(PLATFORM, agentId);\n    if (existingRecord?.status === 'pending') {\n      try {\n        const pending = this.#parsePendingInstallation(existingRecord);\n        const decrypted = this.#decryptPendingInstallation(pending);","sourceCodeStart":1039,"sourceCodeEnd":1075,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/channels/slack/src/provider.ts#L1039-L1075","documentation":"When connect() is called in the string form connect(agentId), the id must resolve to a registered Agent on the attached Mastra instance via #resolveAgent(). If it does not, the installation would have no valid owner, so the provider throws with the offending id.","triggerScenarios":"provider.connect('my-agent') where 'my-agent' is not a key in the Mastra instance's agents map — typo, agent not registered, or agent registered on a different Mastra instance than the one attached to the provider.","commonSituations":"Renaming an agent without updating the connect call; connecting before the agent is registered; multiple Mastra instances (e.g. dev vs worker) where the provider is attached to one that lacks the agent.","solutions":["Register the agent on the Mastra instance: new Mastra({ agents: { 'my-agent': agent } }).","Fix the id typo in the connect() call to match the registered agent key.","Verify provider.__attach() received the same Mastra instance that holds the agent."],"exampleFix":"// before\nawait provider.connect('supprot-agent');\n// after\nawait provider.connect('support-agent'); // matches agents key in new Mastra({ agents: { 'support-agent': agent } })","handlingStrategy":"validation","validationCode":"const agent = mastra.getAgent?.(agentId);\nif (!agent) {\n  throw new Error(`Register agent \"${agentId}\" on the Mastra instance before connecting`);\n}","typeGuard":"function agentExists(mastra: Mastra, id: string): boolean {\n  return Object.keys(mastra.getAgents?.() ?? {}).includes(id);\n}","tryCatchPattern":"try {\n  await provider.connect(agentId);\n} catch (err) {\n  if (err instanceof Error && err.message === `Agent \"${agentId}\" not found`) {\n    console.error(`Available agents: ${Object.keys(mastra.getAgents()).join(', ')}`);\n  } else throw err;\n}","preventionTips":["Derive agent ids from the same constant used in the Mastra agents config.","Add a startup check that every connectable agent id exists on the attached instance.","Use one Mastra instance for both agent registration and SlackProvider attachment."],"tags":["validation","agents","slack"],"backgroundTag":"agent-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}