Sanity Library Reference Docs
    Preparing search index...

    Variable useAgentTransformConst Alpha

    useAgentTransform: () => (
        options: AgentTransformOptions,
    ) => Subscribable<unknown> = ...

    Transforms an existing document or selected fields using Sanity Agent Actions.

    Type declaration

    This hook provides a stable callback to apply AI-powered transformations to document content.

    Features:

    • Accepts instruction and instructionParams (constants, fields, documents, GROQ queries).
    • Can write to the same or a different targetDocument (create/edit), and target specific paths.
    • Supports per-path image transform instructions and image description operations.
    • Optional 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>
    }