-
Notifications
You must be signed in to change notification settings - Fork 63
AI Chat documentation #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bryantgillespie
wants to merge
11
commits into
main
Choose a base branch
from
bry/ai-chat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f79e1bf
first pass
bryantgillespie 0b521eb
add images and video
bryantgillespie b0d27d3
clarify token window
bryantgillespie 9428d82
add note about sharing single api key
bryantgillespie d6cb8da
remove extra callout
bryantgillespie 4947470
one liner for tool settings storage
bryantgillespie 5d76045
shorten to brest practices
bryantgillespie 767743a
Update content/guides/10.ai/1.chat/5.security.md
bryantgillespie 94077eb
Update content/guides/10.ai/1.chat/2.usage.md
bryantgillespie b61ee60
Update content/guides/10.ai/1.chat/1.setup.md
bryantgillespie 03ca636
Merge branch 'main' into bry/ai-chat
bryantgillespie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| title: AI Chat | ||
| headline: AI Chat | ||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| --- | ||
| title: Overview | ||
| description: Chat with an AI assistant directly inside Directus. Create content, manage your schema, trigger automations, and explore your data through natural conversation. | ||
| --- | ||
|
|
||
| Directus AI Chat is an embedded conversational assistant that helps you interact with your Directus instance through natural language. | ||
|
|
||
| <video title="AI Chat creating a blog post" autoplay playsinline muted loop controls class="rounded-md"> | ||
| <source src="/video/ai-chat-blog-post.mp4" type="video/mp4" /> | ||
| </video> | ||
|
|
||
| ::callout{icon="material-symbols:science" color="warning"} | ||
| **AI Chat is currently in beta.** Features and tools may change as we refine the experience based on feedback. | ||
| :: | ||
|
|
||
| ::callout{icon="material-symbols:info" color="info"} | ||
| **AI Chat requires an OpenAI or Anthropic API key.** Administrators [configure API keys](/guides/ai/chat/setup) in Settings → AI. | ||
| :: | ||
|
|
||
| ::callout{icon="material-symbols:person" color="info"} | ||
| **AI Chat is available to Data Studio users only.** Users with API-only access cannot use AI Chat. | ||
| :: | ||
|
|
||
| ## What can AI Chat do? | ||
|
|
||
| - **Content Management**: Create, update, and organize items across your collections | ||
| - **Schema Operations**: Explore your data model, add new fields and collections | ||
| - **Flow Automation**: Create new Flows and trigger them manually | ||
| - **Data Exploration**: Query your data and understand your schema structure | ||
|
|
||
| ## Supported Models | ||
|
|
||
| ### :icon{name="i-simple-icons-openai" class="align-middle mr-1 size-5"} OpenAI | ||
|
|
||
| | Model | Model ID | Context | | ||
| |-------|----------|---------| | ||
| | GPT-5 Nano | `gpt-5-nano` | 400k | | ||
| | GPT-5 Mini | `gpt-5-mini` | 400k | | ||
| | GPT-5 | `gpt-5` | 400k | | ||
|
|
||
| ### :icon{name="i-simple-icons-claude" class="align-middle mr-1 size-5"} Anthropic | ||
|
|
||
| | Model | Model ID | Context | | ||
| |-------|----------|---------| | ||
| | Claude Haiku 4.5 | `claude-haiku-4-5` | 200k | | ||
| | Claude Sonnet 4.5 | `claude-sonnet-4-5` | 200k | | ||
|
|
||
| Want additional models or features? [Submit a request on our roadmap](https://roadmap.directus.io/). | ||
|
|
||
| ## Key Features | ||
|
|
||
| - **Tool Approval**: All tools require approval by default. [Configure per-tool settings](/guides/ai/chat/tools#tool-behavior). | ||
| - **Uses Your Permissions**: The AI operates with your existing Directus role and access policies. | ||
| - **Streaming Responses**: Responses stream in real-time. Stop or retry at any time. | ||
|
|
||
| ::callout{icon="material-symbols:warning" color="warning"} | ||
| **Conversations are stored in your browser only.** They are not saved to the server or shared between devices. Closing your browser or clearing localStorage will delete your conversation history. | ||
| :: | ||
|
|
||
| --- | ||
|
|
||
| ## Get Started | ||
|
|
||
| ::card-group | ||
|
|
||
| :::card{title="Admin Setup" icon="material-symbols:settings" to="/guides/ai/chat/setup"} | ||
| Configure API keys and customize the AI assistant behavior. | ||
| ::: | ||
|
|
||
| :::card{title="User Guide" icon="material-symbols:chat" to="/guides/ai/chat/usage"} | ||
| Learn how to use AI Chat effectively in your daily workflow. | ||
| ::: | ||
|
|
||
| :::card{title="Available Tools" icon="material-symbols:construction" to="/guides/ai/chat/tools"} | ||
| Reference of all tools the AI can use to interact with Directus. | ||
| ::: | ||
|
|
||
| :::card{title="Tips & Best Practices" icon="material-symbols:lightbulb" to="/guides/ai/chat/tips"} | ||
| Get the most out of AI Chat with practical tips and example prompts. | ||
| ::: | ||
|
|
||
| :::card{title="Security" icon="material-symbols:security" to="/guides/ai/chat/security"} | ||
| Access control, data protection, and security considerations. | ||
| ::: | ||
|
|
||
| :: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| --- | ||
| title: Setup | ||
| description: Configure AI Chat by adding your AI provider API keys and customizing assistant behavior. | ||
| headline: AI Chat | ||
| --- | ||
|
|
||
| AI Chat requires an API key from an supported AI provider. This page covers the administrator setup process. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Administrator access to your Directus instance | ||
| - API key from OpenAI or Anthropic (see below) | ||
| - Users must have **App access** - Public (non-authenticated) or API-only users cannot use AI Chat | ||
|
|
||
| ## Get an API Key | ||
|
|
||
| You'll need an API key from at least one provider. Choose based on which models you want to use. | ||
|
|
||
| ::accordion{type="single"} | ||
|
|
||
| :::accordion-item{label="OpenAI" icon="i-simple-icons-openai"} | ||
|
|
||
| OpenAI provides GPT-5 models (Nano, Mini, Standard). | ||
|
|
||
| 1. Go to [platform.openai.com](https://platform.openai.com/) and sign in or create an account | ||
| 2. Navigate to **API Keys** in the left sidebar (or go directly to [platform.openai.com/api-keys](https://platform.openai.com/api-keys)) | ||
| 3. Click **Create new secret key** | ||
| 4. Give it a name like "Directus AI Chat" | ||
| 5. Copy the key immediately - you won't be able to see it again | ||
|
|
||
| ::callout{icon="material-symbols:info" color="info"} | ||
| OpenAI requires a payment method and has usage-based pricing. Set spending limits in **Settings → Limits** to control costs. | ||
| :: | ||
|
|
||
| ::: | ||
|
|
||
| :::accordion-item{label="Anthropic" icon="i-simple-icons-anthropic"} | ||
|
|
||
| Anthropic provides Claude models (Haiku 4.5, Sonnet 4.5). | ||
|
|
||
| 1. Go to [console.anthropic.com](https://console.anthropic.com/) and sign in or create an account | ||
| 2. Navigate to **API Keys** in the settings | ||
| 3. Click **Create Key** | ||
| 4. Give it a name like "Directus AI Chat" | ||
| 5. Copy the key immediately | ||
|
|
||
| ::callout{icon="material-symbols:info" color="info"} | ||
| Anthropic requires a payment method and has usage-based pricing. Monitor usage in the Console dashboard. | ||
| :: | ||
|
|
||
| ::: | ||
|
|
||
| :: | ||
|
|
||
| ## Configure API Keys in Directus | ||
|
|
||
| ::steps{level="3"} | ||
|
|
||
| ### Navigate to AI Settings | ||
|
|
||
| Go to **Settings → AI** in the Directus admin panel. | ||
|
|
||
|  | ||
|
|
||
| ### Enter Your API Key | ||
|
|
||
| Add your API key for one or both providers: | ||
|
|
||
| - **OpenAI API Key** - Enables GPT-5 models | ||
| - **Anthropic API Key** - Enables Claude models | ||
|
|
||
| ::callout{icon="material-symbols:security" color="info"} | ||
| API keys are encrypted at rest in the database and masked in the UI. | ||
| :: | ||
|
|
||
| ### Save Settings | ||
|
|
||
| Click **Save** to apply your changes. AI Chat is now available to all users with [App access](/guides/auth/access-control#studio-users). | ||
|
|
||
| :: | ||
|
|
||
| ## Custom System Prompt | ||
|
|
||
| Optionally customize how the AI assistant behaves in **Settings → AI → Custom System Prompt**. | ||
|
|
||
| The [default system prompt](https://github.com/directus/directus/blob/main/api/src/ai/chat/constants/system-prompt.ts) provides the AI with helpful instructions on how to interact with Directus and is tuned to provide good results. | ||
|
|
||
| If you choose to customize the system prompt, it's recommended to use the following template as a starting point: | ||
|
|
||
| ::accordion{type="single"} | ||
|
|
||
| :::accordion-item{label="View Default System Prompt" icon="material-symbols:code"} | ||
|
|
||
| ```xml | ||
| <behavior_instructions> | ||
| You are **Directus Assistant**, a Directus CMS expert with access to a Directus instance through specialized tools | ||
|
|
||
| ## Communication Style | ||
|
|
||
| - **Be concise**: Users prefer short, direct responses. One-line confirmations: "Created collection 'products'" | ||
| - **Match the audience**: Technical for developers, plain language for content editors | ||
| - **NEVER guess**: If not at least 99% about field values or user intent, ask for clarification | ||
|
|
||
| ## Tool Usage Patterns | ||
|
|
||
| ### Discovery First | ||
|
|
||
| 1. Understand the user's task and what they need to achieve. | ||
| 2. Discover schema if needed for task - **schema()** with no params → lightweight collection list or **schema({ keys: ["products", "categories"] })** → full field/relation details | ||
| 3. Use other tools as needed to achieve the user's task. | ||
|
|
||
| ### Content Items | ||
|
|
||
| - Use `fields` whenever possible to fetch only the exact fields you need | ||
| - Use `filter` and `limit` to control the number of fetched items unless you absolutely need larger datasets | ||
| - When presenting repeated structured data with 4+ items, use markdown tables for better readability | ||
|
|
||
| ### Schema & Data Changes | ||
|
|
||
| - **Confirm before modifying any schema**: Collections, fields, relations always need approval from the user. | ||
| - **Check namespace conflicts**: Collection folders and regular collections share namespace. Collection folders are distinct from file folders. | ||
|
|
||
| ### Safety Rules | ||
|
|
||
| - **Deletions require confirmation**: ALWAYS ask before deleting anything | ||
| - **Warn on bulk operations**: Alert when affecting many items ("This updates 500 items") | ||
| - **Avoid duplicates**: Never create duplicates if you can't modify existing items | ||
| - **Use semantic HTML**: No classes, IDs, or inline styles in content fields (unless explicitly asked for by the user) | ||
| - **Permission errors**: Report immediately, don't retry | ||
|
|
||
| ### Behavior Rules | ||
|
|
||
| - Call tools immediately without explanatory text | ||
| - Use parallel tool calls when possible | ||
| - If you don't have access to a certain tool, ask the user to grant you access to the tool from the chat settings. | ||
| - If there are unused tools in context but task is simple, suggest disabling unused tools (once per conversation) | ||
|
|
||
| ## Error Handling | ||
|
|
||
| - Auto-retry once for clear errors ("field X required") | ||
| - Stop after 2 failures, consult user | ||
| - If tool unavailable, suggest enabling in chat settings | ||
| </behavior_instructions> | ||
| ``` | ||
|
|
||
| ::: | ||
|
|
||
| :: | ||
|
|
||
| Leave blank to use the default behavior. | ||
|
|
||
| ## Managing Costs | ||
|
|
||
| ::callout{icon="material-symbols:warning" color="warning"} | ||
| **AI Chat uses your own AI provider API keys.** Every message and tool call costs money. Be mindful of usage, especially with larger models. You are responsible for the costs of your usage. | ||
| :: | ||
|
|
||
| **Tips for controlling costs:** | ||
| - Use faster, cheaper models (GPT-5 Nano, Claude Haiku 4.5) for simple tasks | ||
| - Disable unused tools - disabled tools are not loaded into context, reducing token usage | ||
| - Set spending limits in your [OpenAI](https://platform.openai.com/settings/organization/limits) or [Anthropic](https://console.anthropic.com/) dashboard | ||
|
|
||
| ## Next Steps | ||
|
|
||
| ::card-group | ||
|
|
||
| :::card{title="User Guide" icon="material-symbols:chat" to="/guides/ai/chat/usage"} | ||
| Learn how users interact with AI Chat. | ||
| ::: | ||
|
|
||
| :::card{title="Available Tools" icon="material-symbols:construction" to="/guides/ai/chat/tools"} | ||
| See what actions the AI can perform. | ||
| ::: | ||
|
|
||
| :::card{title="Tips & Best Practices" icon="material-symbols:lightbulb" to="/guides/ai/chat/tips"} | ||
| Get the most out of AI Chat. | ||
| ::: | ||
|
|
||
| :::card{title="Security" icon="material-symbols:security" to="/guides/ai/chat/security"} | ||
| Access control and data protection. | ||
| ::: | ||
|
|
||
| :: | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.