Sanity Library Reference Docs
    Preparing search index...

    Interface ContentAgentProvider

    A Content Agent provider instance returned by createContentAgent.

    Provides two modes of interaction:

    • Conversation threads via .agent() — stateful, multi-turn conversations with server-side message history.
    • One-shot prompts via .prompt() — stateless, single-turn interactions.
    interface ContentAgentProvider {
        agent(threadId: string, settings?: AgentSettings): LanguageModelV3;
        applications(): Promise<
            {
                bundleVersion?: string;
                intentBaseUrl?: string;
                key?: string;
                name?: string;
                resource?: { id?: string; type?: "dataset" };
                schemaDescriptorId?: string;
                title?: string;
            }[],
        >;
        prompt(
            settings: GenerateSettings,
            options: GenerateOptions,
        ): Promise<GenerateResult>;
    }
    Index

    Methods

    • Creates a Vercel AI SDK LanguageModelV1 for a conversation thread.

      The thread ID identifies the conversation and maintains message history server-side. If a thread with that ID already exists, the conversation continues. If not, a new thread is automatically created.

      Use the returned model with generateText or streamText from the ai package.

      Parameters

      • threadId: string

        Unique identifier for the conversation thread.

      • Optionalsettings: AgentSettings

        Optional agent settings (application, capabilities, filters, etc.).

      Returns LanguageModelV3

      import { generateText, streamText } from 'ai'

      const model = contentAgent.agent('my-thread-id', {
      application: { key: 'projectId.datasetName' },
      config: {
      capabilities: { read: true, write: false },
      },
      })

      // Non-streaming
      const { text } = await generateText({ model, prompt: 'What blog posts do I have?' })

      // Streaming
      const { textStream } = await streamText({ model, prompt: 'Summarize my content' })
      for await (const chunk of textStream) {
      process.stdout.write(chunk)
      }
    • Lists available applications for the organization.

      Returns all Sanity Studio applications the authenticated user has access to. Use the key from a returned application to target it when creating an agent.

      Returns Promise<
          {
              bundleVersion?: string;
              intentBaseUrl?: string;
              key?: string;
              name?: string;
              resource?: { id?: string; type?: "dataset" };
              schemaDescriptorId?: string;
              title?: string;
          }[],
      >

      const apps = await contentAgent.applications()
      const app = apps.find((app) => app.title === "My Studio")

      const model = contentAgent.agent("my-thread", {
      application: { key: app.key },
      })
    • Sends a one-shot prompt to the Content Agent (stateless).

      Unlike .agent(), this does not create or use a conversation thread. Each call is independent with no message history or persistence. Ideal for simple, single-turn interactions.

      Parameters

      • settings: GenerateSettings

        Generation settings (application, capabilities, instructions, etc.).

      • options: GenerateOptions

        The prompt message and request options.

      Returns Promise<GenerateResult>

      const { text } = await contentAgent.prompt(
      {
      application: { key: 'projectId.datasetName' },
      config: { capabilities: { read: true, write: false } },
      instructions: 'Be concise',
      },
      { message: 'List my 5 most recent posts' },
      )