Overview
Artifacts is a structured tool return format used to render rich content (HTML, code, charts, etc.) in the Trajectory area instead of displaying raw text.Background
Current tool return results have the following issues:- Inconsistent formats: Different tools return different formats
- Difficult frontend parsing: Relies on regex to detect content types
- Limited rendering: Cannot distinguish renderable content from plain text
- Poor extensibility: Every new type requires modifying frontend detection logic
Data Structure Design
ToolResultContent
Structured representation of tool return content with the following fields:| Field | Type | Description |
|---|---|---|
type | string | Content type (see table below) |
data | string | Content data |
language | string (optional) | Programming language identifier |
title | string (optional) | Title |
meta | object (optional) | Additional metadata |
ToolResult
Standard tool return format:| Field | Type | Description |
|---|---|---|
success | boolean | Whether successful |
message | string | Result message |
content | ToolResultContent (optional) | Structured content |
file_path | string (optional) | Associated file path |
Content Types
| type | Description | Rendering Method |
|---|---|---|
text | Plain text | <pre> or <p> |
html | HTML content | <iframe> sandbox rendering |
markdown | Markdown | Markdown renderer |
code | Code | Syntax-highlighted CodeBlock |
json | JSON data | JSON Viewer |
image | Image | <img> |
error | Error message | Red error styling |
Frontend Rendering
The frontend selects the corresponding rendering component based on thecontent.type field: HTML content uses sandbox iframe preview, Markdown uses a renderer, code uses syntax highlighting, JSON uses a tree viewer, images are displayed directly, and errors use red styling.
Backward Compatibility
- The frontend supports both new and old formats
- Old format (plain text) is wrapped as content with
type: "text" - Progressive migration without affecting existing functionality