Sanity Library Reference Docs
    Preparing search index...

    Function createContentAgent

    • Creates a Content Agent provider instance.

      The provider is the main entry point for interacting with the Sanity Content Agent API. It returns an object with methods for conversation threads and one-shot prompts.

      Parameters

      Returns ContentAgentProvider

      import { createContentAgent } from 'content-agent'

      const contentAgent = createContentAgent({
      organizationId: 'your-org-id',
      token: 'your-sanity-token',
      })
      import { createContentAgent } from 'content-agent'
      import { generateText, streamText } from 'ai'

      const contentAgent = createContentAgent({
      organizationId: 'your-org-id',
      token: 'your-sanity-token',
      })

      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)
      }
      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' },
      )