prompting.md

  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 context 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 `prompt-library: toggle` command.
 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 in new context editors. Or to be more precise, it uses a series of prompts that are combined to form the default prompt.
 54
 55A default prompt might look something like:
 56
 57```plaintext
 58[-] Default
 59  [+] Today's date
 60  [+] You are an expert
 61  [+] Don't add comments
 62```
 63
 64Each 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.
 65
 66You 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.
 67
 68_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._
 69
 70Default prompts will show at the top of the prompt list, and will be included with every new context.
 71
 72You can manually add the default prompt using the `/default` command.
 73
 74> **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.
 75
 76## Commands in Prompts
 77
 78[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.
 79
 80> **Note:** Slash commands in prompts **must** be on their own line.
 81
 82See the [Commands](./commands.md) docs for more information on commands, and what slash commands are available.
 83
 84### Example:
 85
 86```plaintext
 87You are an expert Rust engineer. The user has asked you to review their project and answer some questions.
 88
 89Here is some information about their project:
 90
 91/file Cargo.toml
 92```
 93
 94In 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.
 95
 96## Nesting Prompts
 97
 98Similar to adding prompts to the default prompt, you can nest prompts within other prompts with the `/prompt` command.
 99
100You might want to nest prompts to:
101
102- Create templates on the fly
103- Break collections like docs or references into smaller, mix-and-matchable parts
104- Create variants of a similar prompt (e.g., `Async Rust - Tokio` vs. `Async Rust - Async-std`)
105
106### Example:
107
108```plaintext
109Title: Zed-Flavored Rust
110
111## About Zed
112
113/prompt Zed: Zed (a prompt about what Zed is)
114
115## Rust - Zed Style
116
117/prompt Rust: Async - Async-std (zed doesn't use tokio)
118/prompt Rust: Zed-style Crates (we have some unique conventions)
119/prompt Rust - Workspace deps (bias towards reusing deps from the workspace)
120```
121
122_The (text) above are comments and are not part of the prompt._
123
124> **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!
125
126By using nested prompts, you can create modular and reusable prompt components that can be combined in various ways to suit different scenarios.
127
128## Advanced Concepts
129
130### Prompt Templates
131
132Zed uses prompt templates to power internal assistant features, like the terminal assistant, or the content prompt used in the inline assistant.
133
134Zed has the following internal prompt templates:
135
136- `content_prompt.hbs`: Used for generating content in the editor.
137- `terminal_assistant_prompt.hbs`: Used for the terminal assistant feature.
138- `edit_workflow.hbs`: Used for generating the edit workflow prompt.
139- `step_resolution.hbs`: Used for generating the step resolution prompt.
140
141At this point it is unknown if we will expand templates further to be user-creatable.
142
143### Overriding Templates
144
145> **Note:** It is not recommended to override templates unless you know what you are doing. Editing templates will break your assistant if done incorrectly.
146
147Zed allows you to override the default prompts used for various assistant features by placing custom Handlebars (.hbs) templates in your `~/.config/zed/prompts/templates` directory.
148
149The following templates can be overridden:
150
1511. `content_prompt.hbs`: Used for generating content in the editor.
152   Format:
153
154   ```handlebars
155   You are an AI programming assistant. Your task is to
156   {{#if is_insert}}insert{{else}}rewrite{{/if}}
157   {{content_type}}{{#if language_name}} in {{language_name}}{{/if}}
158   based on the following context and user request. Context:
159   {{#if is_truncated}}
160     [Content truncated...]
161   {{/if}}
162   {{document_content}}
163   {{#if is_truncated}}
164     [Content truncated...]
165   {{/if}}
166
167   User request:
168   {{user_prompt}}
169
170   {{#if rewrite_section}}
171     Please rewrite the section enclosed in
172     <rewrite_this></rewrite_this>
173     tags.
174   {{else}}
175     Please insert your response at the
176     <insert_here></insert_here>
177     tag.
178   {{/if}}
179
180   Provide only the
181   {{content_type}}
182   content in your response, without any additional explanation.
183   ```
184
1852. `terminal_assistant_prompt.hbs`: Used for the terminal assistant feature.
186   Format:
187
188   ```handlebars
189   You are an AI assistant for a terminal emulator. Provide helpful responses to
190   user queries about terminal commands, file systems, and general computer
191   usage. System information: - Operating System:
192   {{os}}
193   - Architecture:
194   {{arch}}
195   {{#if shell}}
196     - Shell:
197     {{shell}}
198   {{/if}}
199   {{#if working_directory}}
200     - Current Working Directory:
201     {{working_directory}}
202   {{/if}}
203
204   Latest terminal output:
205   {{#each latest_output}}
206     {{this}}
207   {{/each}}
208
209   User query:
210   {{user_prompt}}
211
212   Provide a clear and concise response to the user's query, considering the
213   given system information and latest terminal output if relevant.
214   ```
215
2163. `edit_workflow.hbs`: Used for generating the edit workflow prompt.
217
2184. `step_resolution.hbs`: Used for generating the step resolution prompt.
219
220> **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.
221
222You 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.
223
224Consult Zed's [assets/prompts](https://github.com/zed-industries/zed/tree/main/assets/prompts) directory for current versions you can play with.