Add context to user messages
In AI Agents, context is data that complements the user's request. Sometimes, it's essential to help it complete the task.
For example, in a multi-document AI Agent, if the user mentions a document, the document's ID should be sent as context, too.
Provide context when you create a user message by using the context
option.
provider.addUserMessage('Summarize the selected document', {
context: 'The selected document ID is: 12345',
})
Inserting context with mentions
In many AI chatbots, users can reference files and other users by mentioning them: @John
, #file-123
, etc. You can implement this behaviour with Tiptap by defining
the prompt input as a Tiptap text editor, and installing the Mention extension.
Adding selected content as context
Sending the editor selection as context to the AI Agent can help it understand the user's request and make precise edits to the selection only.
To let the AI model know about the selected content, set the addSelection
option to true
. This will send the selected content as context to the AI Agent.
provider.addUserMessage('Summarize the selected document', {
addSelection: true, // Defaults to false
})