01Output formats
text: plain text with no processing. This is the default.markdown: keeps the Markdown and adds metadata about code blocks, tables, lists and links.html: converts Markdown to HTML, with optional sanitizing, a code highlighting class and a theme wrapper.react: HTML withdata-componentattributes, for hydration in React.
02Set the format on an agent
outputFormat and formatOptions are agent config fields. When the format is not text, the response carries a formatted object with raw, format, rendered and metadata. content still holds the raw text.
import { Agent, AnthropicProvider, ToolRegistry } from '@lov3kaizen/agentsea-core';
const agent = new Agent(
{ name: 'docs-writer', description: 'Writes docs', model: 'claude-sonnet-4-6', provider: 'anthropic', outputFormat: 'markdown', formatOptions: { includeMetadata: true } },
new AnthropicProvider(),
new ToolRegistry(),
);
const response = await agent.execute('Explain closures', { conversationId: 'conv-1', sessionData: {}, history: [] });
console.log(response.formatted?.rendered, response.formatted?.metadata);03Format options
includeMetadata: addshasCodeBlocks,hasTables,hasListsandlinks.sanitizeHtmlremoves<script>tags andjavascript:links inhrefattributes. It applies tohtmlandreactoutput.highlightCode: adds thehljsclass to code blocks, for highlight.js.theme:'light','dark'or'auto'. Applies tohtmloutput and setsdata-themeon the wrapper.
Note
sanitizeHtml is a pattern-based filter, not an HTML parser. It also strips quoted event handler attributes such as onclick="...", but it does not catch every form of unsafe markup. Turn sanitizeHtml on for any HTML users see, and treat it as a floor, not a complete defence.04Format a string directly
ContentFormatter.format(content, format, options) and ContentFormatter.detectFormat(content) work without an agent.
import { ContentFormatter } from '@lov3kaizen/agentsea-core';
const formatted = ContentFormatter.format('# Title', 'html', {
sanitizeHtml: true,
highlightCode: true,
theme: 'dark',
});
console.log(formatted.rendered);
console.log(ContentFormatter.detectFormat('<h1>Hello</h1>'));05Override the format per request
The NestJS execute route accepts outputFormat and formatOptions in the request body.
curl -X POST http://localhost:3000/agents/assistant/execute \
-H "Content-Type: application/json" \
-d '{"input": "Explain async/await", "outputFormat": "html", "formatOptions": {"sanitizeHtml": true}}'Warning
06React components
The @lov3kaizen/agentsea-react package exports AgentResponse, StreamingResponse, useFormattedContent and useStreamingContent. The components ship without styles.
Note
07Styling
The sample CSS targets .agentsea-response and the data-theme attribute. Syntax highlighting needs highlight.js or a similar library, with its CSS imported in the app.