import type { AgentResult } from "../agents/types"; /** * Formats multiple agent results into the structured block form injected back into the main agent. */ export function formatResultCollectorOutput(results: AgentResult[]): string { return results .map((result) => { const payload = escapeXmlText(result.responseText ?? result.error ?? ""); const agentName = escapeXmlAttribute(result.agentName); return `\n${payload}\n`; }) .join("\n\n"); } function escapeXmlAttribute(value: string): string { return value .replaceAll("&", "&") .replaceAll("<", "<") .replaceAll(">", ">") .replaceAll('"', """) .replaceAll("'", "'"); } function escapeXmlText(value: string): string { return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); }