{"record":{"id":"4c8d3bfe91ffba9a","repo":"Budibase/budibase","slug":"invalid-agent-request-link-response","errorCode":null,"errorMessage":"Invalid agent request link response","messagePattern":"Invalid agent request link response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/agentRequests/helpers.ts","lineNumber":133,"sourceCode":"      prompt: JSON.stringify({\n        currentSessionId: sessionId,\n        latestPrompt: normalizedPrompt,\n        recentChatContext,\n        candidateRequests: candidateRequests.map(buildCandidateSummary),\n      }),\n    })\n  } catch (error) {\n    console.error(\"Failed to analyze agent request link\", {\n      agentId,\n      sessionId,\n      error,\n    })\n    throw error\n  }\n\n  const decision = extractJson(result.text || \"\")\n  if (!decision) {\n    throw new Error(\"Invalid agent request link response\")\n  }\n\n  if (\n    decision.decision === \"existing_thread\" &&\n    !candidateRequests.some(request => request._id === decision.requestId)\n  ) {\n    throw new Error(\n      `Invalid agent request link response: unknown requestId \"${decision.requestId}\"`\n    )\n  }\n\n  return {\n    decision: decision.decision,\n    requestId: decision.requestId,\n    entryAction: decision.entryAction,\n  }\n}\n","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/agentRequests/helpers.ts#L115-L151","documentation":"analyzeAgentRequestLink asks an LLM to decide whether a prompt belongs to an existing agent request thread, expecting a strict JSON reply. extractJson parses and validates that reply; if it cannot produce a valid decision object (missing/unknown decision value, or existing_thread without requestId/entryAction), the function throws Error(\"Invalid agent request link response\").","triggerScenarios":"The LLM returns prose instead of JSON, malformed JSON, a decision value other than existing_thread/new_thread, or existing_thread without a valid requestId and entryAction.","commonSituations":"A weak or non-instruct-tuning-capable model ignoring the JSON-only instruction; the model wraps JSON in markdown fences or adds commentary (only the first {...} block is extracted); truncated responses cutting off the JSON.","solutions":["Use a model/aiconfig that reliably follows JSON-only instructions; raise temperature constraints if configurable","Catch the error and fall back to decision \"new_thread\" so the agent flow continues","Retry the generateText call once on failure","Strengthen output handling: request structured output / response_format JSON if the provider supports it"],"exampleFix":"// before\nconst analysis = await analyzeAgentRequestLink({...}) // throws on bad LLM reply\n// after\nlet analysis\ntry {\n  analysis = await analyzeAgentRequestLink({...})\n} catch {\n  analysis = { decision: \"new_thread\" }\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"let analysis\ntry {\n  analysis = await analyzeAgentRequestLink({ latestPrompt, candidateRequests, ... })\n} catch (err) {\n  if (err instanceof Error && err.message === \"Invalid agent request link response\") {\n    analysis = { decision: \"new_thread\" }\n  } else {\n    throw err\n  }\n}","preventionTips":["Configure a model that reliably emits strict JSON for the agent's aiconfig","Prefer provider JSON/structured output modes when available","Always define a safe default decision (new_thread) for link analysis failures"],"tags":["llm","json-parsing","response-validation","agent-requests"],"backgroundTag":"llm-invalid-json-response","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}