Agent Actions

Agent Actions introduction

Get to know Agent Actions and how to start using them.

Experimental feature

Agent Actions let you programmatically run schema-aware AI instructions to create and modify Sanity documents. You can run instructions from anywhere you can execute code, such as Sanity Functions, custom components, webhook listeners, CI/CD pipelines, migration scripts, and more.

  • Add AI-assisted content suggestions.
  • Generate draft documents with new content.
  • Generate images based on fields within your document.
  • Translate documents automatically or on demand.
  • See live AI presence so your editors know when the Instruct API works on a document.

You can create powerful AI-driven workflows, by combining Agent Actions with Functions, Content Releases, the Actions API, and the rest of Content Lake's APIs.

Requirements

  • You'll need a place to execute code, such as a custom component, cloud functions, a webhook listener, or any service that can run the JavaScript client or initiate HTTP requests.
  • Sanity client (@sanity/client) version 7.1.0 or later and API version vX.

Presence support

Install and enable the AI Assist plugin for Sanity Studio to enable presence support.

Image and reference support

Some Agent Actions, like Generate, can create images and connect references. To enable automation for image and reference fields, further setup is required.

Core Concepts

Get to know the actions

Agent Actions all share the same core, but are specialized for different uses.

Generate

When you want to create brand new content, you want Generate. It excels at creating new content based on the information you pull in from your existing Sanity documents.

  • Create full, structured documents in a single command.
  • Reference multiple documents to use as the source for new documents.
  • Generate images and make reference connections to existing documents.

Transform

When you need to modify existing documents, Transform can walk through your document fields and make changes. It keeps the formatting and style, while only making the changes you tell it to make.

  • Change a document's tone.
  • Rename a product across your entire site.

Translate

A specialized version of Transform, Translate is designed with internationalization in mind. It supports both document-level translation and field-level translation. It's a fast way to translate documents into multiple languages.

Prompt

Need to make prompts to an LLM without reaching for another service? Prompt allows you to use your content in Sanity to make requests, then process that information however you like.

Patch

Agent Actions are schema-aware, which lets them validate and safely modify your documents. Now you can use this same approach with Patch. No LLMs involved.

Operations

Should an action create a new document? Should it edit an existing one? Operations tell each Action Action how to act on your data.

Instructions

Agent Actions use the concept of instructions to describe what tasks you want them to perform. These are combined with each action's configuration.

Actions understand your schema

Actions know about your content model, which allow them to map content accurately to your documents and fields. However, you must deploy an up-to-date schema version to make this work.

If you're already hosting Studio at Sanity, you're all set. Run sanity deploy from your project to ensure the latest schema is uploaded. If you're hosting Studio elsewhere, you can manually deploy the schema.

Refer to any of the quick start guides for instructions on deploying your schema.

How Agent Actions compare to AI Assist

AI Assist is a plugin for Sanity Studio. The intended user is the content creator or Studio manager. While powerful, the nature of the manual, on-demand triggering of AI workflows is limited for cases where automation would be more efficient. Manual workflows don't scale well for batch operations, can't be triggered by external events, and require human intervention for each execution.

Agent Actions let you trigger, or invoke, AI workflows from anywhere you can make an API call or run the Sanity client. They also allow you to supply additional contextual information beyond what lives in a single Sanity document or field.

Usage and spending limits

Agent Actions usage is shared across the organization. For details on your plan's limits, see the pricing page.

You can set spending limits and view your remaining budget in your Organization's settings in Manage.

  • Navigate to Manage, or run sanity manage from the CLI.
  • Select your Organization.
  • Navigate to Settings, then Spending Limits.
The spending limits settings page located in your Organization settings.

Limitations

The following field types are not supported:

The following field types are supported, but with limitations:

  • Slug: Agent Actions don't perform uniqueness validation to check if the slug conflicts with others.
  • URL: Agent Actions only write to this field type if the instruction includes links.

The following types require additional setup:

Agent Actions won't write to explicitly hidden or readOnly fields. These are fields with readOnly: true and hidden: true defined in the schema. They do support conditionally readOnly or hidden fields. See the common patterns guide for more details.

Was this page helpful?