The encodeAgentFormula / decodeAgentFormula functions in src/lib/agents/agentFormula.ts use :: as a delimiter in the header line, but the instruction text is appended unescaped on the line below.
Problem: If the instruction text contains @agent: at the start of a line (after \n), or :: inline, the parser in decodeAgentFormula will misparse it because:
- The header detection (
startsWith(@agent:)) matches against the full string including the instruction body — so an instruction like @agent: use API key X would be detected as an agent formula header
- The
decodeAgentFormula only splits on the first \n, but the :: in the header is used for splitting fields — if the instruction (after the newline) happens to start with something that looks like a new header, parsing breaks
Example that triggers this:
@agent: openai::gpt-4o-mini::10
Find funding for Acme Corp :: Series A preferred
This would parse Acme Corp as provider, Series A preferred as model, etc.
Suggested fix: Use a more robust serialization format (e.g., JSON-based encoding, or escape :: in header fields, or use a fixed-number-of-fields parsing approach that stops splitting at the known fields).
The
encodeAgentFormula/decodeAgentFormulafunctions insrc/lib/agents/agentFormula.tsuse::as a delimiter in the header line, but the instruction text is appended unescaped on the line below.Problem: If the instruction text contains
@agent:at the start of a line (after\n), or::inline, the parser indecodeAgentFormulawill misparse it because:startsWith(@agent:)) matches against the full string including the instruction body — so an instruction like@agent: use API key Xwould be detected as an agent formula headerdecodeAgentFormulaonly splits on the first\n, but the::in the header is used for splitting fields — if the instruction (after the newline) happens to start with something that looks like a new header, parsing breaksExample that triggers this:
This would parse
Acme Corpasprovider,Series A preferredasmodel, etc.Suggested fix: Use a more robust serialization format (e.g., JSON-based encoding, or escape
::in header fields, or use a fixed-number-of-fields parsing approach that stops splitting at the known fields).