Beta
Optional
Beta
conditionalBeta
documentThe source document the transformation will use as input.
Optional
Beta
forceBy default, agent actions will never write to a published document.
Instead, they will force the use of a draft ID ("drafts.some-id") instead of the published ID ("some-id"), even when a published ID is provided.
Actions will use state from an existing draft if it exists, or use the published document to create a draft, if no draft exists.
Successful responses contains the _id that was mutated by the action.
When forcePublishedWrite: true an agent action will write to the exact id provided. The action will also not fallback to published state for draft ids.
When an ID on the form "versions.forcePublishedWrite: true
.
That is, only the exact document state of the id provided is considered and mutated.
Beta
instructionInstruct the LLM how to transform the input to th output.
String template with support for $variable from instructionParams
.
Capped to 2000 characters, after variables has been injected.
Optional
Beta
instructionparam values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
client.agent.action.generate({
schemaId,
documentId,
instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
instructionParams: {
topic: 'Grapefruit'
},
})
client.agent.action.transform({
schemaId,
documentId,
instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
instructionParams: {
topic: {
type: 'constant',
value: 'Grapefruit'
},
},
})
client.agent.action.transform({
schemaId,
documentId,
instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
instructionParams: {
pte: {
type: 'field',
path: ['pteField'],
},
},
target: {path: 'keywords' }
})
client.agent.action.transform({
schemaId,
documentId,
instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
instructionParams: {
document: {
type: 'document',
},
},
target: {path: 'keywords' }
})
client.agent.action.transform({
schemaId,
documentId,
instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
instructionParams: {
list: {
type: 'groq',
query: '* [_type==$type].title',
params: {type: 'article'}
},
},
target: {path: 'title'}
})
Optional
Beta
localeWhen localeSettings is provided on the request, instruct can write to date and datetime fields. Otherwise, such fields will be ignored.
A valid Unicode BCP 47 locale identifier used to interpret and format natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
This affects how phrases like "next Friday" or "in two weeks" are parsed, and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
A valid IANA time zone identifier used to resolve relative and absolute date expressions to a specific point in time. Examples include "America/New_York", "Europe/Paris", or "Asia/Tokyo".
This ensures phrases like "tomorrow at 9am" are interpreted correctly based on the user's local time.
Beta
schemaschemaId as reported by sanity deploy / sanity schema store
Optional
Beta
targetTarget defines which parts of the document will be affected by the instruction. It can be an array, so multiple parts of the document can be separately configured in detail.
Omitting target implies that the document itself is the root.
Notes:
maxPathDepth
Default max depth for transform: 12
To transform an existing image, directly target an image asset path.
For example, all the following will transform the image into the provided asset:
target: {path: ['image', 'asset'] }
target: {path: 'image', include: ['asset'] }
Image transform can be combined with regular content targets:
target: [{path: ['image', 'asset'] }, {include: ['title', 'description']}]
Image transform can have per-path instructions, just like any other target paths:
target: [{path: ['image', 'asset'], instruction: 'Make the sky blue' }
Optional
Beta
targetThe source document's content is first copied to the target, then it is transformed according to the instruction.
When omitted, the source document (documentId) is also the target document.
Optional
Beta
temperatureControls how much variance the instructions will run with.
Value must be in the range [0, 1] (inclusive).
Defaults:
When a type or field in the schema has a function set for
hidden
orreadOnly
, it is conditional.By default, Generate will not output to conditional
readOnly
andhidden
fields, ie, they are considered to resolve toreadOnly: true
/hidden: true
.conditionalPaths
param allows setting the default conditional value forhidden
andreadOnly
to false, or individually sethidden
andreadOnly
state for individual document paths.Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate, and cannot be changed via conditionalPaths
conditionalPaths state only apply to fields and types that have conditional
hidden
orreadOnly
in their schema definition.Consider using
hidden: () => true
in schema config, if a field should be writeable only by Generate and never visible in the studio – then make the field visible to the Generate usingconditionalPaths
.