Clarify when to use artifacts runtime functions vs artifacts tool

Make it clear that runtime functions are ONLY for programmatically generated
content (by code), not for content the LLM authors directly.

Changes:
- Add WHEN TO USE and DO NOT USE sections to runtime provider description
- Emphasize that createOrUpdateArtifact is for code-generated content
- Point users to artifacts tool for LLM-authored content like summaries
This commit is contained in:
Mario Zechner 2025-10-10 02:10:36 +02:00
parent 2e56f77599
commit ab9137542c

View file

@ -186,27 +186,38 @@ ${ARTIFACTS_RUNTIME_EXAMPLE}
// ============================================================================ // ============================================================================
export const ARTIFACTS_RUNTIME_PROVIDER_DESCRIPTION = ` export const ARTIFACTS_RUNTIME_PROVIDER_DESCRIPTION = `
Artifact Management (persistent session files you can access/modify programmatically): Artifact Management from within executed code (HTML/JavaScript REPL).
- await listArtifacts() - Get list of all artifact filenames, returns string[]
* Example: const files = await listArtifacts(); // ['data.json', 'notes.md', 'chart.png']
- await getArtifact(filename) - Read artifact content, returns string or object
* Auto-parses .json files to objects, otherwise returns raw string content
* Example: const data = await getArtifact('data.json'); // Returns parsed object
* Example: const markdown = await getArtifact('notes.md'); // Returns string
- await createOrUpdateArtifact(filename, content, mimeType?) - Create or update a persistent artifact
* Automatically creates if new, updates if exists
* Auto-stringifies objects for .json files
* Example: await createOrUpdateArtifact('data.json', {items: []}) // Auto-stringifies
* Example: await createOrUpdateArtifact('research-notes.md', '# Research Notes\\n', 'text/markdown')
* Full content replacement (not diff-based) when updating
- await deleteArtifact(filename) - Delete an artifact
* Example: await deleteArtifact('old-notes.md')
Powerful pattern for evolving data: WHEN TO USE THESE FUNCTIONS:
const files = await listArtifacts(); - ONLY when writing code that programmatically generates/transforms data
const data = files.includes('data.json') ? await getArtifact('data.json') : {items: []}; - Examples: Web scraping results, processed CSV data, generated charts saved as JSON
data.items.push(newScrapedItem); - The artifact content is CREATED BY THE CODE, not by you directly
await createOrUpdateArtifact('data.json', data);
DO NOT USE THESE FUNCTIONS FOR:
- Summaries or notes YOU write (use artifacts tool instead)
- Content YOU author directly (use artifacts tool instead)
Functions:
- await listArtifacts() - Get list of all artifact filenames, returns string[]
* Example: const files = await listArtifacts(); // ['data.json', 'notes.md']
- await getArtifact(filename) - Read artifact content, returns string or object
* Auto-parses .json files to objects
* Example: const data = await getArtifact('data.json'); // Returns parsed object
- await createOrUpdateArtifact(filename, content, mimeType?) - Create/update artifact FROM CODE
* ONLY use when the content is generated programmatically by your code
* Auto-stringifies objects for .json files
* Example: await createOrUpdateArtifact('scraped-data.json', results)
* Example: await createOrUpdateArtifact('chart.png', base64ImageData, 'image/png')
- await deleteArtifact(filename) - Delete an artifact
* Example: await deleteArtifact('temp.json')
Example - Scraping data and saving it:
const response = await fetch('https://api.example.com/data');
const data = await response.json();
await createOrUpdateArtifact('api-results.json', data);
Binary data must be converted to a base64 string before passing to createOrUpdateArtifact. Binary data must be converted to a base64 string before passing to createOrUpdateArtifact.
Example: Example: