Provide context
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',
})
Insert 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.
Add files and URLs to context
The context
option only accepts strings, not file objects. To add files as context, follow the steps below:
- Upload the file to your server. Obtain an identifier for it.
- Add the file identifier to the
context
option. - In your backend, define a custom server-side tool that lets the AI Agent read the contents of the file.
The same applies to URLs. If the user provides a URL, you can include it as a string in the context
option and define a custom tool to search the web and retrieve the content of that URL.
Add the editor's selection to context
To make the AI Agent aware of the selected content in the editor, activate selection awareness.