Const AlphaA stable callback that triggers the action and yields a Subscribable stream.
This hook provides a stable callback to apply AI-powered transformations to document content.
Features:
instruction and instructionParams (constants, fields, documents, GROQ queries).targetDocument (create/edit), and target specific paths.temperature, async, noWrite, conditionalPaths.import {useAgentTransform} from '@sanity/sdk-react'
function SummarizeArticle({documentId}: {documentId: string}) {
const transform = useAgentTransform()
const handleSummarize = () => {
transform({
documentId,
instruction: 'Summarize the following content into 2-3 sentences: $body',
instructionParams: {
body: {type: 'field', path: 'body'},
},
targetPaths: ['summary'],
}).subscribe({
complete: () => console.log('Summary generated'),
error: (err) => console.error('Transform failed:', err),
})
}
return <button onClick={handleSummarize}>Generate Summary</button>
}
import {useAgentTransform} from '@sanity/sdk-react'
function CreateVariant({sourceDocumentId}: {sourceDocumentId: string}) {
const transform = useAgentTransform()
const handleCreateVariant = () => {
transform({
documentId: sourceDocumentId,
instruction: 'Rewrite this product description for a younger audience: $description',
instructionParams: {
description: {type: 'field', path: 'description'},
},
targetDocument: {
operation: 'create',
_type: 'product',
},
targetPaths: ['description'],
}).subscribe({
next: (result) => console.log('New document:', result),
complete: () => console.log('Variant created'),
})
}
return <button onClick={handleCreateVariant}>Create Youth Variant</button>
}
Transforms an existing document or selected fields using Sanity Agent Actions.