{"record":{"id":"d38e9d3e30bd3507","repo":"can1357/oh-my-pi","slug":"generated-systemprompt-is-empty","errorCode":null,"errorMessage":"Generated systemPrompt is empty","messagePattern":"Generated systemPrompt is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/modes/components/agents-hub.ts","lineNumber":194,"sourceCode":"\t}\n\tif (\n\t\ttypeof parsed.identifier !== \"string\" ||\n\t\ttypeof parsed.whenToUse !== \"string\" ||\n\t\ttypeof parsed.systemPrompt !== \"string\"\n\t) {\n\t\tthrow new Error(\"Model output is missing required fields (identifier, whenToUse, systemPrompt)\");\n\t}\n\tconst identifier = parsed.identifier.trim();\n\tconst whenToUse = parsed.whenToUse.trim();\n\tconst systemPrompt = parsed.systemPrompt.trim();\n\tif (!IDENTIFIER_PATTERN.test(identifier)) {\n\t\tthrow new Error(\"Generated identifier is invalid (must be lowercase kebab-case, 2+ words)\");\n\t}\n\tif (!whenToUse.toLowerCase().startsWith(\"use this agent when\")) {\n\t\tthrow new Error(\"Generated whenToUse must start with 'Use this agent when...'\");\n\t}\n\tif (!systemPrompt) {\n\t\tthrow new Error(\"Generated systemPrompt is empty\");\n\t}\n\treturn { identifier, whenToUse, systemPrompt };\n}\n\nfunction matchAgent(agent: HubAgent, query: string): boolean {\n\tconst text = `${agent.name} ${agent.description} ${SOURCE_LABEL[agent.source]} ${agent.overrideModel ?? \"\"}`;\n\treturn query\n\t\t.trim()\n\t\t.split(/\\s+/)\n\t\t.every(token => fuzzyMatch(token, text).matches);\n}\n\n/**\n * The fullscreen agents hub component. Hosted via\n * `ui.showOverlay(..., { fullscreen: true })`; the host must call\n * {@link AgentsHubComponent.dispose} when the overlay closes.\n */\nexport class AgentsHubComponent implements Component {","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/modes/components/agents-hub.ts#L176-L212","documentation":"parseGeneratedAgentSpec requires a non-empty systemPrompt in the LLM-generated agent spec. The systemPrompt is the body of the generated agent .md file; an empty one would produce a useless agent. This is a guard against the architect model returning a blank or missing systemPrompt field.","triggerScenarios":"The architect LLM's response parses to a spec whose systemPrompt trims to an empty string — e.g. the model emitted only the identifier/whenToUse, or a malformed block caused the systemPrompt capture to be empty.","commonSituations":"Model output truncated by token limits; model omitting the systemPrompt section; regex/parser section boundaries mismatching the model's formatting; blank-line-only prompt body.","solutions":["Re-run agent creation so the model regenerates a complete spec","Check the model's raw response (truncation or formatting) and retry with a larger max-tokens budget","Use a stronger model that reliably fills every required field","Enter the agent definition manually instead of via the creation architect"],"exampleFix":"// before\nsystemPrompt: \"\"\n// after\nsystemPrompt: \"You are a refactoring assistant. Review code and apply safe transformations.\"","handlingStrategy":"validation","validationCode":"const systemPrompt = (parsed.systemPrompt ?? \"\").trim();\nif (!systemPrompt) throw new Error(\"systemPrompt is empty\");","typeGuard":"function hasSystemPrompt(s: unknown): s is { systemPrompt: string } {\n  return typeof s === \"object\" && s !== null && typeof (s as any).systemPrompt === \"string\" &&\n    (s as any).systemPrompt.trim().length > 0;\n}","tryCatchPattern":"try {\n  const spec = await hub.runAgentCreationArchitect(desc);\n} catch (err) {\n  if (err instanceof Error && err.message === \"Generated systemPrompt is empty\") {\n    // retry once or fall back to manual authoring\n  } else throw err;\n}","preventionTips":["Ensure the architect model has enough max-tokens for the full spec","Check raw model output when creation fails repeatedly","Prefer models that reliably complete multi-section outputs","Author agents manually when LLM generation is flaky"],"tags":["validation","llm-output","agents"],"backgroundTag":"llm-output-validation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}