{"record":{"id":"bda85afcd91f4559","repo":"Budibase/budibase","slug":"agent-not-found","errorCode":null,"errorMessage":"Agent not found","messagePattern":"Agent not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/builder/src/stores/portal/agents.ts","lineNumber":126,"sourceCode":"      agents: [],\n      tools: [],\n      toolsLoading: false,\n      toolsLoaded: false,\n      toolsLoadFailed: false,\n      agentsLoaded: false,\n      knowledgeByOperation: {},\n      knowledgeUploadByOperation: {},\n      knowledgeLoadingByOperation: {},\n      knowledgeConfiguration: undefined,\n    })\n  }\n\n  private getAgentOrThrow = (agentId: string) => {\n    const agent = get(this.store).agents.find(\n      candidate => candidate._id === agentId\n    )\n    if (!agent) {\n      throw new Error(\"Agent not found\")\n    }\n    return agent\n  }\n\n  private updateOperation = async (\n    agentId: string,\n    operationId: string,\n    updater: (operation: AgentOperation) => AgentOperation\n  ) => {\n    const operation = this.getAgentOperation(agentId, operationId)\n    if (!operation) {\n      throw new Error(\"Operation not found\")\n    }\n    const updated = updater(operation)\n    return await this.updateAgentOperation(agentId, operationId, {\n      name: updated.name,\n      live: updated.live,\n      promptInstructions: updated.promptInstructions,","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/builder/src/stores/portal/agents.ts#L108-L144","documentation":"getAgentOrThrow is the store's internal lookup helper: it finds an agent by _id in local state and throws if absent, guaranteeing subsequent operations have a valid agent. Callers (delete, update operations, toggles) all funnel through it.","triggerScenarios":"Any AgentsStore public operation (delete, updateAgentOperation, toggling live status) with an agentId that does not exist in the local store list.","commonSituations":"Agent deleted in another tab/session while the UI still holds its id; passing an id from a stale list; calling operations before the agents list has been fetched; wrong id variable used.","solutions":["Fetch/refresh the agents list before performing the operation","Verify the agentId is valid and the agent still exists","Handle concurrent deletion gracefully — re-fetch and update the UI","Confirm you're not passing a different id type/format than stored _id"],"exampleFix":"// before\nagents.delete(agentId)\n// after\nconst exists = get(agents).agents.some(a => a._id === agentId)\nif (exists) await agents.delete(agentId)","handlingStrategy":"try-catch","validationCode":"const agent = get(agents).agents.find(a => a._id === agentId)\nif (!agent) {\n  await agents.fetch()\n  return\n}","typeGuard":null,"tryCatchPattern":"try {\n  await agents.delete(agentId)\n} catch (e) {\n  if (e.message === \"Agent not found\") {\n    await agents.fetch() // resync; agent likely deleted elsewhere\n  } else throw e\n}","preventionTips":["Refresh the agents list before operations on stored ids","Update UI state after deletions in any tab/session","Confirm the agentId source (list item) rather than hardcoding","Re-fetch after failed operations to resync state"],"tags":["builder","agents","not-found","state"],"backgroundTag":"entity-not-found","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}