Skip to content

Commit 0ad00df

Browse files
committed
docs: Add prompt structure documentation to advanced usage sidebar
1 parent 351c260 commit 0ad00df

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Prompt Structure
2+
3+
This page explains the technical structure of prompts in Roo Code - how messages are constructed and sent to the Large Language Model (LLM).
4+
5+
## Core Message Types
6+
7+
Roo Code uses three primary message types when communicating with LLMs:
8+
9+
- **System Prompt**: The initial instructions that define Roo's capabilities, persona, and operational rules
10+
- **User Messages**: Content sent by you (the user) to Roo
11+
- **Assistant Messages**: Responses generated by the LLM based on your requests
12+
13+
Understanding these message types helps you work more effectively with Roo and can be valuable for troubleshooting or advanced customization.
14+
15+
## System Prompt
16+
17+
The system prompt is the foundation of Roo's behavior. It contains:
18+
19+
- **Role Definition**: The core persona instructions based on the selected mode (Code, Ask, Debug, etc.)
20+
- **Tool Descriptions**: Detailed information about available tools, including parameters and examples
21+
- **Tool Use Guidelines**: Rules for how tools should be used (sequential execution, waiting for results)
22+
- **Capabilities**: Description of what Roo can do in the current environment
23+
- **Available Modes**: List of all available modes and their descriptions
24+
- **Operational Rules**: Critical guidelines for handling files, project structure, and user interaction
25+
- **System Information**: Details about your environment (OS, shell, working directory)
26+
- **Custom Instructions**: Your global and mode-specific customizations
27+
28+
The system prompt is generated dynamically each time you interact with Roo, adapting to your current mode, available tools, and custom settings.
29+
30+
### Custom System Prompts
31+
32+
Advanced users can create custom system prompts for specific modes by placing a `.roo/system-prompt-<mode_slug>` file in their workspace. When present, Roo uses this file instead of generating the standard system prompt sections, allowing for complete customization of Roo's behavior in that mode.
33+
34+
## User Messages
35+
36+
User messages contain your direct inputs to Roo, plus additional contextual information:
37+
38+
- **Your Query**: The text you type in the chat interface
39+
- **Images**: Any images you include in your message (for supported models)
40+
- **Environment Details**: Automatically appended information about your workspace state:
41+
- Open files/tabs
42+
- Cursor position
43+
- Active terminals with output
44+
- Recently modified files
45+
- Current time and token/cost information
46+
- Current mode
47+
- File listing (on initial connection)
48+
49+
This automatic context enrichment helps Roo understand your workspace without requiring you to explicitly describe it.
50+
51+
## Assistant Messages
52+
53+
Assistant messages are the LLM's responses, which may include:
54+
55+
- **Text Responses**: Direct answers to your queries
56+
- **Thinking**: Internal reasoning process (visible when enabled)
57+
- **Tool Calls**: Requests to use specific tools like reading files or executing commands
58+
- **Tool Results**: The outcome of executed tools
59+
60+
## Message Flow
61+
62+
Here's how these components work together:
63+
64+
1. **Initial Setup**: Roo generates the system prompt based on your selected mode and configuration
65+
2. **User Input**: You send a message, which is enriched with environment details
66+
3. **LLM Processing**: The LLM receives all previous messages plus your new input
67+
4. **Assistant Response**: The LLM generates a response, potentially using tools
68+
5. **Tool Execution**: If the LLM requests a tool, Roo executes it and provides the result
69+
6. **Conversation History**: All messages are maintained in a structured history for context
70+
71+
## Technical Implementation
72+
73+
Internally, Roo's prompt construction is handled by several components:
74+
75+
- **System Prompt Generation**: The `SYSTEM_PROMPT` function in `src/core/prompts/system.ts` assembles the complete system prompt
76+
- **Section Generators**: Specialized functions create each section of the system prompt
77+
- **Message Transformation**: Provider-specific transformers convert Roo's internal message format to the format required by each LLM API
78+
- **Custom Prompt Loading**: The `loadSystemPromptFile` function checks for and processes custom system prompt files
79+
80+
## Optimizing Your Interactions
81+
82+
Understanding this structure can help you:
83+
84+
- **Write Better Prompts**: Knowing what context Roo already has helps you avoid redundant information
85+
- **Troubleshoot Issues**: Understanding message flow helps identify where problems might occur
86+
- **Create Custom Modes**: With knowledge of the system prompt structure, you can create more effective custom modes
87+
- **Use Custom System Prompts**: Advanced users can create entirely custom system prompts for specialized use cases
88+
89+
This technical foundation powers all of Roo's capabilities, enabling it to understand your requests and effectively utilize available tools to complete tasks.

sidebars.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const sidebars: SidebarsConfig = {
6868
label: 'Advanced Usage',
6969
items: [
7070
'advanced-usage/prompt-engineering',
71+
'advanced-usage/prompt-structure',
7172
'advanced-usage/large-projects',
7273
'advanced-usage/rate-limits-costs',
7374
'advanced-usage/local-models',

0 commit comments

Comments
 (0)