mastra-ai/mastra · error · Error
Agent with id ${id} not found
Error message
Agent with id ${id} not found What it means
`update` looks up the agent by `id` in the in-memory map and throws when no row exists. Updates never create agents implicitly.
Source
Thrown at packages/core/src/storage/domains/agents/inmemory.ts:92
await this.createVersion({
id: versionId,
agentId: agent.id,
versionNumber: 1,
...snapshotConfig,
changedFields: Object.keys(snapshotConfig),
changeMessage: 'Initial version',
});
// Return the thin agent record (activeVersionId remains null)
return this.deepCopyAgent(newAgent);
}
async update(input: StorageUpdateAgentInput): Promise<StorageAgentType> {
const { id, ...updates } = input;
const existingAgent = this.db.agents.get(id);
if (!existingAgent) {
throw new Error(`Agent with id ${id} not found`);
}
const { authorId, visibility, activeVersionId, metadata, status } = updates;
const updatedAgent: StorageAgentType = {
...existingAgent,
...(authorId !== undefined && { authorId }),
...(visibility !== undefined && { visibility }),
...(activeVersionId !== undefined && { activeVersionId }),
...(metadata !== undefined && {
metadata: { ...existingAgent.metadata, ...metadata },
}),
...(status !== undefined && { status }),
updatedAt: new Date(),
};
this.db.agents.set(id, updatedAgent);
return this.deepCopyAgent(updatedAgent);View on GitHub (pinned to 75dd419e61)
Solutions
- Verify the agent exists (get by ID) before updating, or create it if missing
- Ensure you are using the same store instance that holds the agent (in-memory data does not survive restarts)
- Log/validate the incoming `id` — check for typos or IDs from another environment
Example fix
// before
await agents.update({ id: 'agent-1', name: 'new-name' });
// after
if (await agents.get({ agentId: 'agent-1' })) {
await agents.update({ id: 'agent-1', name: 'new-name' });
} Defensive patterns
Strategy: try-catch
Validate before calling
const existing = await agentsDomain.get({ agentId: id });
if (!existing) {
// create the agent first or surface a 404 to the caller
} Type guard
null
Try / catch
try {
await agentsDomain.update({ id, ...updates });
} catch (e) {
if (e instanceof Error && /Agent with id .* not found/.test(e.message)) {
throw new NotFoundError(`Agent ${id} does not exist in this store`);
}
throw e;
} Prevention
- Remember in-memory stores reset on process restart — recreate or reseed before updates
- Verify the ID comes from the same store/environment
- Check for typos in agent IDs
- Use get-before-update in flows where deletion can race the update
When it happens
Trigger: Calling `update({ id, ... })` with an ID that was never created, was created in a different store instance, or belongs to an in-memory store that was reset (process restart loses all data).
Common situations: Updating an agent after a dev-server restart wiped the in-memory DB; using an ID from a different environment/store; race where another caller deleted the agent first; typo in the agent ID.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Dataset not found: ${args.id}
- Dataset not found: ${args.datasetId}
- Item not found: ${args.id}
- MCP client with id ${id} not found
- MCP server with id ${id} not found
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/3967f301f84acae4.
Report an issue: GitHub.