{"record":{"id":"17d7d54f3dee15ec","repo":"Budibase/budibase","slug":"agent-is-not-properly-configured-missing-ai-confi","errorCode":null,"errorMessage":"Agent is not properly configured: missing AI config","messagePattern":"Agent is not properly configured: missing AI config","errorType":"http","errorClass":"HTTPError","httpStatus":422,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/agents/utils.ts","lineNumber":465,"sourceCode":"\n  return {\n    successResults,\n    successNames,\n    semanticFailureNames,\n    semanticFailureResults,\n  }\n}\n\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":447,"sourceCodeEnd":479,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/agents/utils.ts#L447-L479","documentation":"assertAgentHasValidConfig validates that an agent references an AI config before it can run. If agent.aiconfig is falsy, it throws a 422 HTTPError indicating the agent is not properly configured. This is a pre-flight guard so agents fail fast with a clear message instead of failing deep inside model calls.","triggerScenarios":"Invoking an agent (chat/run flows that call assertAgentHasValidConfig) where the Agent document was saved without selecting an AI config, leaving aiconfig undefined.","commonSituations":"Agents created before AI config setup was completed; aiconfig field dropped by API clients omitting it; agents imported/copied without their config reference; configs deleted leaving agents pointing at nothing (related but distinct from 467).","solutions":["Assign a valid AI config to the agent (set agent.aiconfig to an existing config ID) and save it.","In the UI, complete agent setup by choosing a model/AI config before invoking the agent.","Catch the 422 HTTPError and prompt the user to configure the agent rather than retrying."],"exampleFix":"// before\nawait runAgent(agent) // 422: missing AI config\n// after\nif (!agent.aiconfig) {\n  agent.aiconfig = existingConfigId\n  await sdk.agents.update(agent)\n}\nawait runAgent(agent)","handlingStrategy":"validation","validationCode":"const isAgentConfigured = (agent: Agent): boolean => !!agent.aiconfig\nif (!isAgentConfigured(agent)) {\n  throw new HTTPError(\"Select an AI config for this agent first\", 422)\n}\nawait assertAgentHasValidConfig(agent)","typeGuard":"const hasAiConfig = (agent: Agent): agent is Agent & { aiconfig: string } =>\n  typeof agent.aiconfig === \"string\" && agent.aiconfig.length > 0","tryCatchPattern":"try {\n  await assertAgentHasValidConfig(agent)\n} catch (err) {\n  if (err instanceof HTTPError && err.status === 422 && err.message.includes(\"missing AI config\")) {\n    // redirect user to agent configuration screen\n  }\n}","preventionTips":["Make AI config selection a required step in agent creation flows.","Pre-validate aiconfig presence before any agent invocation.","Block 'run/test' buttons in the UI until a config is chosen."],"tags":["configuration","agents","http-422"],"backgroundTag":"agent-not-configured","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}