Prompt System
MyDeskBot's prompt system is the core component responsible for generating and managing prompts that interact with AI models.
Prompt Principles
What is a Prompt
A Prompt is the input text that interacts with an AI model, which:
- 📝 Defines Tasks - Clearly tells the AI what to do
- 🎯 Provides Context - Gives the AI enough background information
- 📋 Specifies Format - Defines the output format and structure
- ⚙️ Sets Constraints - Limits the AI's behavior and output
Prompt Structure
MyDeskBot's prompts typically include:
System Prompt
- Defines the AI's role and goals
- Sets behavioral guidelines
- Specifies response style
User Prompt
- User's specific request
- Relevant context information
- Input data
Auxiliary Information
- Examples (Few-shot)
- Constraints
- Output format
Built-in Prompts
Code Completion
You are a code completion assistant. Complete the code snippet based on the provided context. Maintain consistent code style and follow best practices.
Context: [Relevant code, files]
Code to complete: [Selected code]
Completed code: :::
Code Review
You are a professional code review expert. Review the following code and identify issues and improvement suggestions.
Review criteria:
- Code quality: readability, maintainability
- Potential issues: bugs, security vulnerabilities
- Performance: performance optimization opportunities
- Best practices: follow industry best practices
Code: [Code snippet]
Please output in the following format: 🔴 Critical issues 🟡 Moderate issues 🟢 Improvement suggestions ✅ Good practices
Code Refactoring
You are a code refactoring expert. Refactor the following code to improve readability, maintainability, and performance.
Refactoring principles:
- Maintain functionality unchanged
- Improve code quality
- Follow SOLID principles
- Add necessary comments
Original code: [Code snippet]
Refactored code: [Refactored code]
Refactoring explanation: [Explanation of refactoring]
Documentation Generation
You are a technical documentation writing expert. Generate clear documentation for the following code.
Documentation requirements:
- Include function/class purpose description
- Parameter descriptions (type, meaning)
- Return value description
- Usage examples
- Notes and considerations
Code: [Code snippet]
Generated documentation:
Custom Prompts
Prompt Formats
MyDeskBot prompts support two variable formats:
V1 Format (Traditional)
Uses Handlebars template syntax, variables are wrapped in three curly braces:
{{{ input }}}
{{{ @currentFile }}}
{{{ @codebase }}}V1 format requires explicit specification of user input with {{{ input }}}.
V2 Format (Recommended)
Use the @ symbol to reference context providers, more concise and intuitive:
@currentFile
@codebase
@fileV2 format automatically appends user input to the end of the prompt, no manual specification required.
This document uses V2 format for all examples.
Format Recognition Rules
MyDeskBot automatically recognizes prompt formats through the following rules:
- Recognized as V1 format if the prompt contains
{{{ input }}} - Otherwise recognized as V2 format
If a prompt contains both {{{ input }}} and @variable, it will be recognized as V1 format. In this case, @variable must be wrapped with {{{ }}} to be rendered.
Therefore, in practice, you should not mix the two formats. Choose one uniformly.
Prompt Variables
Prompts use the @ symbol to reference context providers:
| Provider | Description |
|---|---|
@file | Reference specific file |
@url | Reference URL content |
@clipboard | Clipboard content |
@repo-map | Repository map |
@currentFile | Current file |
@os | Operating system info |
@problems | Problem list |
@codebase | Codebase content |
@tree | File tree |
@open | Open files |
@debugger | Debug info |
@terminal | Terminal output |
@diff | Diff content |
Creating Custom Prompts
You can create custom prompts in two ways:
Method 1: Configuration File
Define prompts in your config.yaml:
# ~/.mydeskbot/config.yaml
prompts:
- name: "My Custom Prompt"
description: "Prompt for specific tasks"
prompt: |
You are a professional developer assistant
Current file:
@currentFileMethod 2: Prompt File
Create a separate prompt file in ~/.mydeskbot/prompts/:
# ~/.mydeskbot/prompts/code-review.prompt
name: "Code Review"
description: "Review code quality, security, and performance"
prompt: |
You are a senior code review engineer, focused on code quality, security, and performance.
Review the following code:
@currentFile
Output format:
1. List of issues
2. Severity level
3. Fix suggestionsWhen using a prompt file, it will be automatically converted to an available slash command.
Using Custom Prompts
Type / in the chat input box to trigger slash commands, then select your defined prompt:
/prompt-nameYou can also type the prompt name directly after the / to use it.
Advanced Techniques
Few-shot Learning
Provide examples to improve results:
You are a code conversion assistant. Convert JavaScript code to TypeScript.
Example 1: Input:
javascriptfunction greet(name) { return "Hello " + name; }Output:
typescriptfunction greet(name: string): string { return "Hello " + name; }Example 2: Input:
javascriptconst users = [ { name: "Alice", age: 25 }, { name: "Bob", age: 30 }, ];Output:
typescriptinterface User { name: string; age: number; } const users: User[] = [ { name: "Alice", age: 25 }, { name: "Bob", age: 30 }, ];Now convert the following code: Input:
javascript{ code; }Output:
typescript
Chain of Thought
Guide AI to reason step by step:
You are a problem-solving expert. Please think step by step and solve the problem.
Problem: Specific problem description
Please think through the following steps:
- Understand the problem
- Analyze requirements
- Design solution
- Implement solution
- Verify results
Step 1: Understand the problem AI's thought process
Step 2: Analyze requirements ...
Final answer:
Self-Correction
Ask AI to check and improve:
You are a code review expert.
Task:
- Generate code
- Review the generated code
- If there are issues, fix the code
- Review again
Original request: User's request
Step 1: Generate code AI generates code
Step 2: Review code AI reviews its own code
Step 3: Fix code (if needed) AI fixes code
Final code:
Best Practices
1. Clear Instructions
Good prompt:
Create a Python function that calculates the number of working days between two dates (excluding weekends and holidays). Function signature: def count_workdays(start_date: date, end_date: date) -> int
Bad prompt:
Write a function to calculate dates
2. Provide Context
With context:
This is a Django view function that handles user registration. Current issues with the code:
- No email format validation
- Password is not encrypted before storage
Please improve this function.
Code:
pythonActual code content
Without context:
Improve this function
3. Specify Format
With format specified:
Explain the following concept using this format:
- Definition
- Example code
- Use cases
- Notes and considerations
Concept: JavaScript closure
Without format specified:
Explain closures
4. Set Constraints
With constraints:
Generate a quicksort algorithm. Constraints:
- Language: Python
- Code lines: Not more than 20 lines
- Add detailed comments
- Include usage examples