AgentSea

Guide

Formatting

Ask an agent for text, Markdown, HTML or React output, and read the formatted field on the response.

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 with data-component attributes, 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.

TS
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: adds hasCodeBlocks, hasTables, hasLists and links.
  • sanitizeHtml removes <script> tags and javascript: links inhref attributes. It applies to html and react output.
  • highlightCode: adds the hljs class to code blocks, for highlight.js.
  • theme: 'light', 'dark' or 'auto'. Applies to html output and sets data-theme on 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.

TS
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.

BASH
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

The controller writes the request's format to the shared agent object, so the change stays for later requests. Two requests with different formats can overwrite each other. Use a separate agent per format, or do not allow per-request formats.

06React components

The @lov3kaizen/agentsea-react package exports AgentResponse, StreamingResponse, useFormattedContent and useStreamingContent. The components ship without styles.

Note

Confirm the props and hook arguments against your react package version.

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.