{"record":{"id":"1b9c94b1b42f245e","repo":"Budibase/budibase","slug":"agent-is-not-properly-configured-ai-config-age","errorCode":null,"errorMessage":"Agent is not properly configured: AI config \"${agent.aiconfig}\" not found","messagePattern":"Agent is not properly configured: AI config \"(.+?)\" not found","errorType":"http","errorClass":"HTTPError","httpStatus":422,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/agents/utils.ts","lineNumber":473,"sourceCode":"\nexport function formatIncompleteToolCallError(\n  incompleteTools: IncompleteToolCall[]\n): string {\n  const toolNames = incompleteTools.map(t => t.toolName).join(\", \")\n  return `The AI model failed to complete tool execution${toolNames ? ` for: ${toolNames}` : \"\"}. This may be due to a compatibility issue with the selected model. Please try a different model or try again.`\n}\n\nexport const assertAgentHasValidConfig = async (agent: Agent) => {\n  if (!agent.aiconfig) {\n    throw new HTTPError(\n      \"Agent is not properly configured: missing AI config\",\n      422\n    )\n  }\n\n  const aiConfig = await sdk.ai.configs.find(agent.aiconfig)\n  if (!aiConfig) {\n    throw new HTTPError(\n      `Agent is not properly configured: AI config \"${agent.aiconfig}\" not found`,\n      422\n    )\n  }\n}\n","sourceCodeStart":455,"sourceCodeEnd":479,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/agents/utils.ts#L455-L479","documentation":"After confirming agent.aiconfig is set, assertAgentHasValidConfig looks the config up via sdk.ai.configs.find. If the referenced config no longer exists, it throws a 422 HTTPError naming the missing config ID. This catches dangling references left behind when AI configs are deleted or belong to another workspace.","triggerScenarios":"Running an agent whose aiconfig points to a config ID that does not resolve - config deleted after the agent was created, config in a different app/workspace, or ID typo/corruption in the agent document.","commonSituations":"Deleting an AI config that is still referenced by agents; copying agents between environments where config IDs differ; license/tenant changes removing cloud-provided configs.","solutions":["Re-point the agent's aiconfig to an existing AI config ID (create or select one) and save.","Audit agents for dangling aiconfig references after deleting configs and clean them up.","Catch the 422 HTTPError and surface 'AI config not found - reconfigure this agent' in the UI."],"exampleFix":"// before\nawait runAgent(agent) // 422: config \"abc123\" not found\n// after\nconst configs = await sdk.ai.configs.fetch()\nagent.aiconfig = configs[0]._id\nawait sdk.agents.update(agent)\nawait runAgent(agent)","handlingStrategy":"validation","validationCode":"const aiConfig = await sdk.ai.configs.find(agent.aiconfig)\nif (!aiConfig) {\n  throw new HTTPError(\"Referenced AI config no longer exists - reconfigure the agent\", 422)\n}\nawait assertAgentHasValidConfig(agent)","typeGuard":"const hasResolvableAiConfig = async (agent: Agent): Promise<boolean> =>\n  !!agent.aiconfig && !!(await sdk.ai.configs.find(agent.aiconfig))","tryCatchPattern":"try {\n  await assertAgentHasValidConfig(agent)\n} catch (err) {\n  if (err instanceof HTTPError && err.status === 422 && err.message.includes(\"not found\")) {\n    // re-point agent.aiconfig to an existing config and save\n  }\n}","preventionTips":["When deleting an AI config, cascade-clear or reassign referencing agents.","Periodically audit agents for dangling aiconfig references.","Re-map config IDs when copying agents across environments."],"tags":["configuration","agents","dangling-reference"],"backgroundTag":"agent-not-configured","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}