Sanity Library Reference Docs
    Preparing search index...

    Interface GenerateRequestBaseBeta

    interface GenerateRequestBase {
        conditionalPaths?: {
            defaultHidden?: boolean;
            defaultReadOnly?: boolean;
            paths?: { hidden: boolean; path: AgentActionPath; readOnly: boolean }[];
        };
        forcePublishedWrite?: boolean;
        instruction: string;
        instructionParams?: AgentActionParams;
        localeSettings?: { locale: string; timeZone: string };
        schemaId: string;
        target?: GenerateTarget | GenerateTarget[];
        temperature?: number;
    }

    Hierarchy

    • AgentActionRequestBase
      • GenerateRequestBase
    Index

    Properties

    conditionalPaths?: {
        defaultHidden?: boolean;
        defaultReadOnly?: boolean;
        paths?: { hidden: boolean; path: AgentActionPath; readOnly: boolean }[];
    }

    When a type or field in the schema has a function set for hidden or readOnly, it is conditional.

    By default, Generate will not output to conditional readOnly and hidden fields, ie, they are considered to resolve to readOnly: true / hidden: true.

    conditionalPaths param allows setting the default conditional value for hidden and readOnly to false, or individually set hidden and readOnly 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 or readOnly 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 using conditionalPaths.

    GenerateRequestBase#target

    forcePublishedWrite?: boolean

    By 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..some-id" is provided, agent actions will always behave as if forcePublishedWrite: true. That is, only the exact document state of the id provided is considered and mutated.

    instruction: string

    Instruct the LLM how it should generate content. Be as specific and detailed as needed.

    The LLM only has access to information in the instruction, plus the target schema.

    String template with support for $variable from instructionParams.

    instructionParams?: AgentActionParams

    param 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.generate({
    schemaId,
    documentId,
    instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
    instructionParams: {
    topic: {
    type: 'constant',
    value: 'Grapefruit'
    },
    },
    })
    client.agent.action.generate({
    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.generate({
    schemaId,
    documentId,
    instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
    instructionParams: {
    document: {
    type: 'document',
    },
    },
    target: {path: 'keywords' }
    })
    client.agent.action.generate({
    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' }
    })
    localeSettings?: { locale: string; timeZone: string }

    When localeSettings is provided on the request, instruct can write to date and datetime fields. Otherwise, such fields will be ignored.

    Type declaration

    schemaId: string

    schemaId as reported by sanity deploy / sanity schema store

    Target 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:

    • instruction can only affect fields up to maxPathDepth
    • when multiple targets are provided, they will be coalesced into a single target sharing a common target root. It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)

    Generate will generate images the same was as AI Assist, for images that have been configured using AI Assist schema options.

    To generate images without changing the schema, directly target an image asset path.

    For example, all the following will generate an image into the provided asset:

    • target: {path: ['image', 'asset'] }
    • target: {path: 'image', include: ['asset'] }

    Image generation can be combined with regular content targets:

    • target: [{path: ['image', 'asset'] }, {include: ['title', 'description']}]

    Since Generate happens in a single LLM pass, the image will be contextually related to other generated content.

    AgentActionRequestBase#conditionalPaths

    temperature?: number

    Controls how much variance the instructions will run with.

    Value must be in the range [0, 1] (inclusive).

    Defaults:

    • generate: 0.3
    • translate: 0
    • transform: 0