This guide assumes you have already completed the Generating an Artifact in a Conversation guide.
Step 1: Define the edit_artifact Tool
First, define the schema for a tool that allows the assistant to edit an artifact. The schema must include parameters to identify which artifact to edit (artifactId and version) and what changes to make (instructions).
Step 2: The Role of the version
In our workflow, the version is the unique messageId of the assistant’s response that contains the artifact.
Using the messageId as a version provides a stable reference to a specific, point-in-time snapshot of the artifact as it exists in the conversation history. When the LLM requests an edit, your backend can use this version to reliably retrieve the exact content that needs to be modified.
Step 3: Handle the Tool Call in Your Backend
When a user asks to make a change, the LLM will use youredit_presentation tool. Your backend must handle this tool call by retrieving the old content, calling the C1 Artifacts API in “edit mode,” and streaming back the updated result.
The key steps are:
- Use the
versionfrom the tool call to fetch the previous assistant message content from your database. - Generate a new
messageIdwhich will serve as the new version of the artifact. - Call the C1 Artifacts API, providing the old content and the new editing instructions.
- Stream the updated artifact into a C1 Response object.
- Return a
tool_resultto the main LLM with the new version. - Stream the LLM’s final text confirmation into the same C1 Response object.
Step 4: The Final Updated Response
As in the creation step, the main LLM will receive the successfultool_result and generate a final confirmation (e.g., “I’ve updated the presentation with the new slide.”). Your backend streams this text into the same C1 Response object, completing the request. The frontend then receives and renders the new assistant message containing the fully updated artifact.
View the code
Find more examples and complete code on our GitHub repository.