Agent Actions

Creating instructions

Learn more about instructions and style guides, and how to use them.

Instructions tell Agent Actions how to manipulate your data. Some actions, like Generate, rely almost entirely on your instructions and your schema. Others, like Translate use instructions to further refine their default behavior. If you've used other AI tools, instructions are like prompts.

There are two types of instructions:

  • instruction: Used by Generate and Transform. This pairs with the instructionParams option to pass data into the instruction.
  • styleGuide: Used by Translate. This pairs with the styleGuideParams option to pass data into the instruction.

Aside from the difference in syntax, the concepts are the same for both instruction and styleGuide.

Sanity Client

Basic instructions

At their most basic, instructions are a string telling the Agent Action what you want it to do.

Adding instructionParams

You can provide additional information to the instructions by defining and passing instructionParams (and styleGuideParams for Translate).

Here's an example that uses a basic constant value.

There are two essential things to note about this example:

  • The parameter names (topic, old, new, and tone) can be any variable name.
  • The parameter name is passed into the instruction by prepending $.

This example was a constant value, but there multiple types of parameters.

Constant

You've already seen the shorthand version of the constant parameter type in the previous example. Here's the full version:

Field

The field type parameter picks the value from a field in the source document (if one exists), then passes that to the instruction with the $-prefixed parameter syntax.

You can also provide an optional documentId along with the field path to pick a value from any document in your dataset.

The path should be a full path to the field in the document. For examples of paths, see the common patterns guide.

Document

The document sets the parameter to the full contents of a document. For larger documents, this might become too large and cause issues with the accuracy of the instruction.

This can be useful for passing in singleton-style documents, or using existing documents as background context.

GROQ

If field and document aren't powerful enough, you can also write GROQ queries to populate the contents of your instruction parameters.

GROQ queries accept filters and projections, and can receive their own parameters as seen in the example.

Multiple parameters

The examples so far have only been single parameter instructions, but you can mix any combination of parameter types to build your instruction.

Per-path instructions

Some Agent Actions support per-patch instructions. For example, you can provide a top-level instruction for all fields, and then specific instructions for individual fields. Learn more about this approach in the targets and paths documentation.

Instruction size considerations

These instruction settings are only part of what Agent Actions use when creating content. They also know about your schema and any document used as the source.

As instructions get larger, they can exceed the max size accepted by the large language models. If you're experiencing inconsistent or unexpected results, try reducing the information you pass in to the instructions.

Was this page helpful?