{"record":{"id":"65c09ee75e8e67ac","repo":"mastra-ai/mastra","slug":"agent-agentbody-agentid-not-found","errorCode":null,"errorMessage":"Agent \"${agentBody.agentId}\" not found","messagePattern":"Agent \"(.+?)\" not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/schedules.ts","lineNumber":165,"sourceCode":"      } catch {\n        throw new HTTPException(404, { message: `Workflow \"${body.workflowId}\" not found` });\n      }\n      return await mastra.schedules.create({\n        workflowId: body.workflowId,\n        cron: body.cron,\n        ...(body.id ? { id: body.id } : {}),\n        ...(body.timezone ? { timezone: body.timezone } : {}),\n        ...(body.inputData !== undefined ? { inputData: body.inputData } : {}),\n        ...(body.initialState !== undefined ? { initialState: body.initialState } : {}),\n        ...(body.requestContext ? { requestContext: body.requestContext } : {}),\n        ...(body.metadata ? { metadata: body.metadata } : {}),\n      });\n    }\n    const agentBody = body as Extract<typeof body, { agentId: string }>;\n    try {\n      mastra.getAgentById(agentBody.agentId);\n    } catch {\n      throw new HTTPException(404, { message: `Agent \"${agentBody.agentId}\" not found` });\n    }\n    return await mastra.schedules.create({\n      agentId: agentBody.agentId,\n      cron: agentBody.cron,\n      prompt: agentBody.prompt,\n      ...(agentBody.id ? { id: agentBody.id } : {}),\n      ...(agentBody.name ? { name: agentBody.name } : {}),\n      ...(agentBody.timezone ? { timezone: agentBody.timezone } : {}),\n      ...(agentBody.threadId ? { threadId: agentBody.threadId } : {}),\n      ...(agentBody.resourceId ? { resourceId: agentBody.resourceId } : {}),\n      ...(agentBody.signalType ? { signalType: agentBody.signalType } : {}),\n      ...(agentBody.tagName ? { tagName: agentBody.tagName } : {}),\n      ...(agentBody.attributes ? { attributes: agentBody.attributes } : {}),\n      ...(agentBody.ifActive ? { ifActive: agentBody.ifActive } : {}),\n      ...(agentBody.ifIdle ? { ifIdle: agentBody.ifIdle } : {}),\n      ...(agentBody.providerOptions ? { providerOptions: agentBody.providerOptions } : {}),\n      ...(agentBody.metadata ? { metadata: agentBody.metadata } : {}),\n    });","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/schedules.ts#L147-L183","documentation":"When creating a schedule targeting an agent, the handler validates the agent exists via mastra.getAgentById(agentBody.agentId); failure is translated to HTTP 404 'Agent \"<id>\" not found'.","triggerScenarios":"POST /api/schedules with body.agentId set to an id not registered on the Mastra instance.","commonSituations":"Agent registered under a different id than the name used in the request; agents module not wired into the Mastra instance; case/space mismatch in the id.","solutions":["Use the agent's registered id from new Agent({ id/name: ... }) exactly.","Confirm the agent is included in the Mastra constructor's agents map.","Validate with mastra.getAgentById(id) locally before calling the create route."],"exampleFix":"// before\nPOST /api/schedules { \"agentId\": \"Support Agent\", ... }  // registered id 'support-agent'\n// after\nPOST /api/schedules { \"agentId\": \"support-agent\", ... }","handlingStrategy":"validation","validationCode":"const registered = mastra.getAgentById(agentId); // throws if missing\n// or client-side:\nif (!knownAgentIds.includes(agentId)) {\n  throw new Error(`Agent \"${agentId}\" is not registered`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await client.createSchedule({ agentId, cron, prompt });\n} catch (e) {\n  if (isHttpError(e, 404) && /not found/.test(e.message)) {\n    throw new Error(`Register agent '${agentId}' on the Mastra instance first`);\n  }\n  throw e;\n}","preventionTips":["Use the agent's registered id, not its display name.","Ensure all agents are included in the Mastra instance's agents map.","Validate agent ids against a shared config/manifest before calling the API."],"tags":["http-404","schedules","agent","configuration"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}