---
title: "Provide context"
description: "Learn how to add context to user messages"
canonical_url: "https://tiptap.dev/docs/content-ai/capabilities/agent/features/context"
---

# Provide context

Learn how to 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.

```ts
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](https://tiptap.dev/docs/editor/extensions/nodes/mention.md).

## Add files and URLs to context

The `context` option only accepts strings, not file objects. To add files as context, follow the steps below:

1. Upload the file to your server. Obtain an identifier for it.
2. Add the file identifier to the `context` option.
3. In [your backend](https://tiptap.dev/docs/content-ai/capabilities/agent/custom-llms.md), define a [custom server-side tool](https://tiptap.dev/docs/content-ai/capabilities/agent/custom-llms/server-side-tools.md) that lets your 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](https://tiptap.dev/docs/content-ai/capabilities/agent/custom-llms/server-side-tools.md) 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](https://tiptap.dev/docs/content-ai/capabilities/agent/features/selection-awareness.md).
