Live Preview & Dev Server
Relevant source files
The following files were used as context for generating this wiki page:- src/prompts/system_prompt.ts
- e2e-tests/helpers/test_helper.ts
- src/prompts/summarize_chat_system_prompt.ts
- e2e-tests/snapshots/security_review.spec.ts_security-review---edit-and-use-knowledge-1.txt
- e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt
- e2e-tests/snapshots/dump_messages.spec.ts_dump-messages-1.txt
The Dyad AI assistant operates based on a sophisticated system of prompts and directives that define its role, capabilities, communication style, and output format. These prompts are dynamically constructed based on the current chatMode ("build", "ask", "agent", etc.) and ensure the AI behaves correctly for the task at hand, whether it's writing code, answering questions, or performing security analysis.
The core of this system is to provide the AI with a clear set of rules, guidelines, and examples to follow. This includes defining the tech stack, how to format code changes, how to interact with the user, and what actions it can perform.
Sources: src/prompts/system_prompt.ts
Core Concepts
System Prompt Construction
The final system prompt sent to the AI is constructed by combining several parts: a prefix, a set of AI rules, and a postfix. This modular approach allows for flexibility and context-specific instructions.
The constructSystemPrompt function is the main entry point for building the prompt. It selects the appropriate base prompt based on the chatMode and injects the aiRules.
// src/prompts/system_prompt.ts:468-482
export const constructSystemPrompt = ({
aiRules,
chatMode = "build",
enableTurboEditsV2,
}: {
aiRules: string | undefined;
chatMode?: "build" | "ask" | "agent" | "local-agent";
enableTurboEditsV2: boolean;
}) => {
if (chatMode === "local-agent") {
return constructLocalAgentPrompt(aiRules);
}
const systemPrompt = getSystemPromptForChatMode({
chatMode,
enableTurboEditsV2,
});
return systemPrompt.replace("[[AI_RULES]]", aiRules ?? DEFAULT_AI_RULES);
};
Sources: src/prompts/system_prompt.ts:468-482
AI Rules (AI_RULES.md)
A critical part of the system is the AI_RULES.md file located in the user's project directory. This file defines the specific tech stack, libraries, and coding conventions for that particular project. The system reads this file and injects its content into the [[AI_RULES]] placeholder in the main system prompt. If the file doesn't exist, a default set of rules is used.
This mechanism allows the AI to adapt its coding style and library usage to match the existing project, ensuring consistency.
Sources: src/prompts/system_prompt.ts:498-508, e2e-tests/snapshots/security_review.spec.ts_security-review---edit-and-use-knowledge-1.txt
Dyad XML-like Directives
The AI communicates its intentions and code modifications using a set of custom XML-like tags. This structured output is parsed by the Dyad application to perform actions like writing files, installing dependencies, or displaying UI elements.
The following diagram illustrates the flow from AI generating a directive to the system executing it.
This diagram shows how the AI's structured output is parsed and translated into concrete actions by the Dyad system.
Sources: src/prompts/system_prompt.ts:91-110, src/prompts/summarize_chat_system_prompt.ts:28-31
Key directives include:
| Directive | Description | Example |
|---|---|---|
<dyad-write> | Creates or updates a file with the provided content. | <dyad-write path="src/App.tsx">...</dyad-write> |
<dyad-add-dependency> | Installs one or more npm packages. | <dyad-add-dependency packages="react-hot-toast"></dyad-add-dependency> |
<dyad-rename> | Renames a file. | <dyad-rename from="old.ts" to="new.ts"></dyad-rename> |
<dyad-delete> | Deletes a file. | <dyad-delete path="src/unused.ts"></dyad-delete> |
<dyad-command> | Suggests a UI command for the user (e.g., restart server). | <dyad-command type="restart"></dyad-command> |
<dyad-chat-summary> | Sets the title for the current chat session. | <dyad-chat-summary>Implement user auth</dyad-chat-summary> |
<dyad-security-finding> | Formats a security vulnerability report. | <dyad-security-finding title="SQL Injection">...</dyad-security-finding> |
Sources: src/prompts/system_prompt.ts:80-110, src/prompts/summarize_chat_system_prompt.ts:28-31, e2e-tests/snapshots/security_review.spec.ts_security-review---edit-and-use-knowledge-1.txt
Chat Modes & Personas
The AI's behavior is primarily governed by the chatMode, which dictates the system prompt and, consequently, the AI's persona and capabilities.
Build Mode
This is the default mode for coding. The AI acts as "Dyad, an AI editor that creates and modifies web applications." It is instructed to make efficient code changes, follow best practices, and use the directives mentioned above.
Key Instructions:
- Use
<dyad-write>,<dyad-add-dependency>, etc., to modify the codebase. - Do not make partial changes; all features must be fully functional.
- Explain changes briefly and provide a concise, non-technical summary.
- Use
<dyad-command>to suggest server actions likerebuild,restart, orrefresh.
Sources: src/prompts/system_prompt.ts:68-115, e2e-tests/snapshots/dump_messages.spec.ts_dump-messages-1.txt
Ask Mode
In "ask" mode, the AI's role shifts to a "helpful AI assistant that specializes in web development, programming, and technical guidance." The most critical rule in this mode is the absolute prohibition of writing code.
Key Instructions:
- NO CODE PRODUCTION: Never write, generate, or produce any code snippets or examples.
- Focus on explaining concepts, best practices, and problem-solving approaches.
- Use analogies and conceptual descriptions instead of code.
- All
<dyad-*>tags are strictly forbidden.
The sequence diagram below shows the system's response to a user query in Ask Mode.
This diagram shows the interaction flow in Ask Mode, emphasizing the code-free nature of the response.
Sources: src/prompts/system_prompt.ts:321-388, e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt
Agent Mode
In "agent" mode, the AI acts as an "AI App Builder Agent" focused on information gathering and planning before the coding phase. Its primary mission is to determine the tools, APIs, and resources needed to fulfill a user's request.
Key Instructions:
- ABSOLUTELY NO CODE GENERATION.
- Use tools to research APIs, documentation, and best practices.
- If no external tools are needed, respond with a specific phrase:
"Ok, looks like I don't need any tools, I can start building." - Do not use any
<dyad-*>tags.
Sources: src/prompts/system_prompt.ts:390-440
Security Review Mode
This is a specialized persona where the AI acts as a "Security expert identifying vulnerabilities." The output is strictly formatted using the <dyad-security-finding> directive.
Key Instructions:
- Focus on vulnerabilities like authentication flaws, injection attacks, and exposed secrets.
- Use the
<dyad-security-finding>tag withtitle,level,What,Risk,Potential Solutions, andRelevant Files. - Severity levels are defined as
critical,high,medium, andlow.
Sources: e2e-tests/snapshots/security_review.spec.ts_security-review---edit-and-use-knowledge-1.txt
Thinking Process
A core part of the AI's instruction set is the THINKING_PROMPT. Before responding, the AI is required to use <think></think> tags to outline its plan. This structured thinking process helps it break down requests, diagnose issues, and plan its approach, leading to more accurate and helpful responses.
The thinking process should:
- Use bullet points.
- Bold key insights.
- Follow a clear analytical framework (e.g., identify bug, examine code, diagnose causes, plan approach).
This internal monologue is not typically shown to the user but is a crucial step in the AI's reasoning.
Sources: src/prompts/system_prompt.ts:11-65
Summary
The system prompt architecture in Dyad is a highly structured and flexible system that enables different AI personas and capabilities through modular prompt construction. By combining base prompts with project-specific AI_RULES.md and enforcing a strict output format via XML-like directives, Dyad ensures the AI assistant is a powerful, context-aware, and reliable coding partner. The clear separation between modes like "build" and "ask" prevents unintended behavior, such as providing code when only an explanation is desired.
Sources: src/prompts/system_prompt.ts, e2e-tests/helpers/test_helper.ts