Prompt Library
Relevant source files
The following files were used as context for generating this wiki page:
- src/prompts/system_prompt.ts
- e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt
- e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---default-build-mode-1.txt
- src/tests/problem_prompt.test.ts
- e2e-tests/snapshots/mention_app.spec.ts_mention-app-without-pro-1.txt
- e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---read-then-edit-1.aria.yml
- e2e-tests/snapshots/problems.spec.ts_problems-auto-fix---complex-delete-rename-write-2.txt
The Dyad AI's behavior, capabilities, and persona are defined by a modular system prompt architecture. This system constructs a specific "system prompt" based on the selected operational mode (e.g., building code, answering questions) and project-specific guidelines. This architecture ensures the AI operates within a well-defined set of rules and can switch contexts effectively for different tasks.
The core of this system is located in src/prompts/system_prompt.ts, which contains the templates for various modes and the logic to assemble them with project-specific rules from an AI_RULES.md file.
Prompt Construction Flow
The final system prompt sent to the AI is dynamically generated by the constructSystemPrompt function. This function takes the current chatMode and project-specific aiRules to create a tailored prompt for the AI model.
The following diagram illustrates this construction process:
This diagram shows how constructSystemPrompt selects a base prompt template based on the chatMode and injects the AI_RULES to create the final prompt.
Sources: src/prompts/system_prompt.ts:503-521
Core Prompt Templates
Several constant strings define the foundational behavior for each mode. These are combined and customized to generate the final prompt.
| Constant | Purpose |
|---|---|
BUILD_SYSTEM_PROMPT | The main prompt for code generation and modification. It defines the AI's role as a web application editor and specifies the use of custom <dyad-*> tags for file operations. |
ASK_MODE_SYSTEM_PROMPT | A restrictive prompt for a Q&A mode where the AI is strictly forbidden from writing any code and must only provide explanations. |
AGENT_MODE_SYSTEM_PROMPT | A prompt for an analysis mode where the AI gathers information and determines requirements before any coding begins. It also prohibits code generation. |
THINKING_PROMPT | A set of instructions encouraging the AI to use a <think> block to structure its thought process before responding, ensuring a more robust and analytical approach. |
Sources: src/prompts/system_prompt.ts:8-501
Operational Modes (Chat Modes)
The system supports several distinct operational modes, each with a unique system prompt and set of capabilities.
Build Mode
This is the default mode for creating and modifying code. The AI acts as a real-time editor.
Key Features:
- Code Generation: The AI writes, renames, and deletes files using custom XML-like tags.
- Structured Thinking: The AI is instructed to use
<think>tags to outline its plan before making changes. - Command Suggestions: The AI can suggest UI commands like
rebuildorrestartusing the<dyad-command>tag.
The following tags are used to perform file system operations and other actions:
| Tag | Attributes | Description |
|---|---|---|
<dyad-write> | path, description | Creates a new file or overwrites an existing one with the provided content. |
<dyad-rename> | from, to | Renames a file or directory. |
<dyad-delete> | path | Deletes a file. |
<dyad-add-dependency> | packages | Adds one or more npm packages to the project. |
<dyad-command> | type | Suggests a command for the user to run (e.g., rebuild, restart). |
<dyad-chat-summary> | Sets a concise summary for the current chat session. |
Sources: src/prompts/system_prompt.ts:71-294, e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---default-build-mode-1.txt
Ask Mode
In "Ask Mode," the AI's role shifts to that of a helpful assistant for technical guidance, strictly prohibiting any code generation.
Key Principles:
- No Code Production: The prompt contains an "ABSOLUTE PRIMARY DIRECTIVE" that forbids writing or generating code, including snippets, syntax examples, or using
<dyad-*>tags. - Conceptual Explanations: The AI is instructed to use analogies, plain language, and high-level descriptions instead of implementation details.
- Focus on "Why": The goal is to be educational, explaining the reasoning and trade-offs behind technical recommendations.
Sources: src/prompts/system_prompt.ts:329-436, e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt
Agent Mode
This mode is designed for the initial phase of a request, where the AI's job is to analyze the user's goal and gather information.
Key Features:
- Requirement Analysis: The AI determines what tools, APIs, or external resources are needed.
- Tool Usage Framework: The prompt provides a decision framework for when to use tools (e.g., for external APIs, real-time data) and when not to (e.g., for simple, self-contained apps).
- No Code Generation: Like Ask Mode, this mode has critical constraints against writing any code or using
<dyad-*>tags.
Sources: src/prompts/system_prompt.ts:438-499
Local Agent Mode
This mode is handled by a separate prompt construction function, constructLocalAgentPrompt. While the full prompt is not in system_prompt.ts, its invocation and related test snapshots indicate it's used for autonomous tasks that involve reading and editing files on the user's behalf.
Sources: src/prompts/system_prompt.ts:505-507, e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---read-then-edit-1.aria.yml
AI Rules (AI_RULES.md)
The system prompts are designed to be customized on a per-project basis using an AI_RULES.md file at the root of the user's project.
The readAiRules function attempts to read this file. If it's not found, it falls back to a DEFAULT_AI_RULES constant. This allows the AI to be aware of the specific tech stack, available libraries, and coding conventions of the project it's working on.
This diagram shows the logic for loading project-specific AI rules.
An example of default rules includes specifying the tech stack (React, TypeScript), file structure conventions, and available libraries like shadcn/ui and lucide-react.
Sources: src/prompts/system_prompt.ts:523-533, src/prompts/system_prompt.ts:300-327, e2e-tests/snapshots/mention_app.spec.ts_mention-app-without-pro-1.txt
Special-Purpose Prompts
Problem Fixing Prompt
When the application has build or compile-time errors, a specialized prompt is generated to guide the AI in fixing them. The createProblemFixPrompt function (referenced in tests) formats a ProblemReport object into a clear, actionable message for the AI, listing each error with its file, location, message, and a code snippet.
Sources: src/tests/problem_prompt.test.ts:5-15, e2e-tests/snapshots/problems.spec.ts_problems-auto-fix---complex-delete-rename-write-2.txt