1# Prompting & Prompt Library
2
3## Using Prompts {#using-prompts}
4
5Prompts are an essential part of interacting with AI assistants in Zed. They help guide the AI's responses and ensure you get the most relevant and useful information.
6
7Every new chat will start with the [default prompt](#default-prompt), which can be customized.
8
9Remember that effective prompting is an iterative process. Experiment with different prompt structures and wordings to find what works best for your specific needs and the model you're using.
10
11Here are some tips for using prompts effectively:
12
131. Be specific: Clearly state what you want the AI to do or explain.
142. Provide context: Include relevant information about your project or problem.
153. Use examples: If applicable, provide examples to illustrate your request.
164. Break down complex tasks: For multi-step problems, consider breaking them into smaller, more manageable prompts.
17
18## Prompt Library {#prompt-library}
19
20The Prompt Library is an interface for writing and managing prompts. Like other text-driven UIs in Zed, it is a full editor with syntax highlighting, keyboard shortcuts, etc.
21
22You can use the inline assistant right in the prompt editor, allowing you to automate and rewrite prompts.
23
24### Opening the Prompt Library
25
261. Open the assistant panel.
272. Click on the menu in the top right corner.
283. Select "Prompt Library" from the dropdown.
29
30You can also use the `assistant: deploy prompt library` command while in the assistant panel.
31
32### Managing Prompts
33
34Once a prompt is selected, you can edit it directly in the editor. Its title can be changed from the editor title bar as well.
35
36Prompts can be duplicated, deleted, or added to the default prompt using the buttons in the prompt editor.
37
38## Creating a Prompt {#creating-a-prompt}
39
40To create a prompt, simply open the Prompt Library and click the "+" button. Prompts are stored locally and can be accessed from the library at any time.
41
42Having a series of prompts specifically tailored to prompt engineering can also help you write consistent and effective prompts.
43
44The process of writing and refining prompts commonly called "prompt engineering".
45
46More on prompt engineering:
47
48- [Anthropic: Prompt Engineering](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/overview)
49- [OpenAI: Prompt Engineering](https://platform.openai.com/docs/guides/prompt-engineering)
50
51## Editing the Default Prompt {#default-prompt}
52
53Zed allows you to customize the default prompt used when interacting with LLMs. Or to be more precise, it uses a series of prompts that are combined to form the default prompt.
54
55To edit prompts, select "Prompt Library" from the menu icon (three horizontal lines) in the upper right hand corner or using the `cmd-k l` keyboard shortcut.
56
57A default prompt might look something like:
58
59```plaintext
60[-] Default
61 [+] Today's date
62 [+] You are an expert
63 [+] Don't add comments
64```
65
66Each of the above prompts can be individually expanded, and since Zed's assistant is all text, they can also be edited directly. Edits here will not propagate to the saved prompts.
67
68You can add prompts to the default prompt by clicking the icon in the top right (the "sparkle" icon) of the prompt editor. This will add the prompt to the default prompt.
69
70_Changes to the default prompt will not affect existing contexts. You can remove the default prompt and manually re-add it with `/default` to update an existing context._
71
72Default prompts will show at the top of the prompt list, and will be included with every new chat.
73
74You can manually add the default prompt using the `/default` command.
75
76> **Note:** Remember, commands are only evaluated when the context is created, so a command like `/now` won't continuously update, or `/file` commands won't keep their contents up to date.
77
78## Commands in Prompts
79
80[Commands](./commands.md) can be used in prompts to insert dynamic content or perform actions. For example, if you want to create a prompt where it is important for the model to know the date, you can use the `/now` command to insert the current date.
81
82> **Note:** Slash commands in prompts **must** be on their own line.
83
84See the [Commands](./commands.md) docs for more information on commands, and what slash commands are available.
85
86### Example:
87
88```plaintext
89You are an expert Rust engineer. The user has asked you to review their project and answer some questions.
90
91Here is some information about their project:
92
93/file Cargo.toml
94```
95
96In the above example, the `/file` command is used to insert the contents of the `Cargo.toml` file (or all `Cargo.toml` files present in the project) into the prompt.
97
98## Nesting Prompts
99
100Similar to adding prompts to the default prompt, you can nest prompts within other prompts with the `/prompt` command.
101
102You might want to nest prompts to:
103
104- Create templates on the fly
105- Break collections like docs or references into smaller, mix-and-matchable parts
106- Create variants of a similar prompt (e.g., `Async Rust - Tokio` vs. `Async Rust - Async-std`)
107
108### Example:
109
110```plaintext
111Title: Zed-Flavored Rust
112
113## About Zed
114
115/prompt Zed: Zed (a prompt about what Zed is)
116
117## Rust - Zed Style
118
119/prompt Rust: Async - Async-std (zed doesn't use tokio)
120/prompt Rust: Zed-style Crates (we have some unique conventions)
121/prompt Rust - Workspace deps (bias towards reusing deps from the workspace)
122```
123
124_The (text) above are comments and are not part of the prompt._
125
126> **Note:** While you technically _can_ nest a prompt within itself, we wouldn't recommend it (in the strongest of terms.) Use at your own risk!
127
128By using nested prompts, you can create modular and reusable prompt components that can be combined in various ways to suit different scenarios.
129
130## Advanced Concepts
131
132### Prompt Templates
133
134Zed uses prompt templates to power internal assistant features, like the terminal assistant, or the content prompt used in the inline assistant.
135
136Zed has the following internal prompt templates:
137
138- `content_prompt.hbs`: Used for generating content in the editor.
139- `terminal_assistant_prompt.hbs`: Used for the terminal assistant feature.
140- `suggest_edits.hbs`: Used for generating the model instructions for the XML Suggest Edits should return.
141
142At this point it is unknown if we will expand templates further to be user-creatable.
143
144### Overriding Templates
145
146> **Note:** It is not recommended to override templates unless you know what you are doing. Editing templates will break your assistant if done incorrectly.
147
148Zed allows you to override the default prompts used for various assistant features by placing custom Handlebars (.hbs) templates in your `~/.config/zed/prompt_overrides` directory.
149
150The following templates can be overridden:
151
1521. [`content_prompt.hbs`](https://github.com/zed-industries/zed/tree/main/assets/prompts/content_prompt.hbs): Used for generating content in the editor.
153
1542. [`terminal_assistant_prompt.hbs`](https://github.com/zed-industries/zed/tree/main/assets/prompts/terminal_assistant_prompt.hbs): Used for the terminal assistant feature.
155
1563. [`suggest_edits.hbs`](https://github.com/zed-industries/zed/tree/main/assets/prompts/suggest_edits.hbs): Used for generating the model instructions for the XML Suggest Edits should return.
157
158> **Note:** Be sure you want to override these, as you'll miss out on iteration on our built-in features. This should be primarily used when developing Zed.
159
160You can customize these templates to better suit your needs while maintaining the core structure and variables used by Zed. Zed will automatically reload your prompt overrides when they change on disk.
161
162Consult Zed's [assets/prompts](https://github.com/zed-industries/zed/tree/main/assets/prompts) directory for current versions you can play with.