Versions and how to go back

Check which agent version is published and compare it with the draft before publishing changes. To recover earlier settings, restore them into the draft or return to a previous publication with rollback.

Each saved change to versioned configuration creates a fixed version. Versions aren't changed or deleted from the history.

An agent tracks two versions:

  • The draft is the version you edit. Every change you save creates a new version and moves the draft to it. Your customers don't see it.
  • The published version is the version that answers your customers. It only changes when you publish or roll back.
What you doWhat changes
Edit the draftThe draft. The published version stays the same
Restore a versionThe draft. The published version stays the same
PublishThe published version
Roll backThe published version. The draft stays the same

An agent's version 1 is published when you create it. The name, photo, status, owners and file and tool connections apply immediately and aren't part of versions.

Before you start

You need an agent with its id in AGENT_ID.

To use the platform, see Drafts and versions and History and publishing.

  1. Check the draft and published version

    (Get an agent)

    import { Platic } from "platic-sdk";
    
    const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! });
    const agentId = process.env.AGENT_ID!;
    
    const agent = await platic.agents.get(agentId);

    draft.versionId is the draft and publication.versionId is the published version. hasUnpublishedChanges is true when the draft has something your customers don't see yet.

  2. See the versions and compare two

    The list goes from newest to oldest, each with its number, who made it (createdBy), where from (source) and its note. (List versions)

    for await (const version of platic.agents.versions.iterate(agentId)) {
      console.log(version.versionId, version.createdBy, version.note);
    }

    The list doesn't include each version's configuration. To see it in full, use Get a version.

    The comparison returns changed sections with their previous (before) and new (after) content. Before publishing, compare the published version with the draft. (Compare versions)

    const diff = await platic.agents.versions.compare(agentId, "v3", "v5");

    The first version is the before and the one in with is the after. Use the versionId of the published version and of the draft.

  3. Validate before publishing

    Validate changes against the draft without saving them. The response tells you whether they can be saved and published, and lists any problems. (Validate the draft)

    const check = await platic.agents.draft.validate(agentId, {
      instructions: "You are the sales assistant for Acme. Answer in under 50 words and offer free shipping.",
    });

    valid says whether it could be saved and publishable, whether it could then be published. Each problem comes in issues, with its path and its explanation. To also know whether the agent answers better, test it.

  4. Publish a specific version

    If you omit versionId, you publish the draft. If you include it, you publish that version. (Publish)

    await platic.agents.publish(agentId, { versionId: "v5", note: "Shorter answers" });

    From the next message on, the agent answers with that version. The note is optional and stays in the publication history.

  5. Restore a version into the draft

    Bring an old version back to keep editing from there. It creates a new version with its content and moves the draft to it. The published version doesn't change. (Restore the draft)

    await platic.agents.draft.restore(agentId, { versionId: "v3" });

    History is not rewritten: the new version says which one it was copied from in restoredFromVersionId. When you have reviewed it, publish it.

  6. Go back to a previous publication

    Roll back to return to a version that was previously published. This changes the version the agent uses and keeps the draft unchanged. (List publications, Roll back)

    const { data: history } = await platic.agents.publications.list(agentId);
    
    await platic.agents.rollback(agentId, { versionId: "v3" });

    In the history, each entry has the version that was published (versionId) and the one that was before (previousVersionId). Rolling back only accepts a version that was already published; for any other, publish it instead.

    Use rollback to return to an earlier publication. To edit from an earlier version, restore it into the draft and publish it when it's ready.

Check it worked

Get the agent again: publication.versionId is the version you published or rolled back to, draft.versionId is where you left the draft, and hasUnpublishedChanges tells you whether they differ.

Next steps