|
1 | 1 | --- |
2 | | -title: "Repository Rules" |
3 | | -sidebarTitle: "Repo Rules" |
| 2 | +title: "Agent Rules" |
| 3 | +sidebarTitle: "Agent Rules" |
4 | 4 | icon: "shield-check" |
5 | 5 | --- |
6 | 6 |
|
7 | | -Repository Rules in Codegen act as a persistent set of instructions or a "system prompt" for the AI agent whenever it operates on a specific repository. These rules guide the agent's behavior by enforcing coding standards and repository-specific conventions through automated reminders to the language model (LLM) during each task. |
| 7 | +Agent Rules in Codegen act as persistent instructions or "system prompts" for the AI agent, guiding its behavior by enforcing coding standards, conventions, and preferences. These rules are automatically included in the agent's context during each task to ensure consistent behavior across your organization and repositories. |
8 | 8 |
|
9 | | -Codegen supports two types of repository rules: |
10 | | -1. **Manual Repository Rules** - configured through the web interface |
11 | | -2. **Automatic Rule File Detection** - automatically discovered from your repository files |
| 9 | +## Rule Hierarchy |
| 10 | + |
| 11 | +Codegen supports a hierarchical rule system with three levels: |
| 12 | + |
| 13 | +1. **User Rules** - Personal preferences that apply to all your work across organizations |
| 14 | +2. **Organization Rules** - Apply to all repositories within your organization |
| 15 | +3. **Repository Rules** - Apply to a specific repository and override higher-level rules when conflicts exist |
| 16 | + |
| 17 | +<Note> |
| 18 | + **Rule Precedence**: Repository rules take precedence over organization rules, which take precedence over user rules when conflicts exist. This allows you to set personal defaults, organization-wide standards, and repository-specific customizations. |
| 19 | +</Note> |
| 20 | + |
| 21 | +## Types of Rules |
| 22 | + |
| 23 | +Each level supports two types of rule configuration: |
| 24 | + |
| 25 | +### Manual Rules |
| 26 | +Rules configured directly through the Codegen web interface at [codegen.com/repos](https://codegen.com/repos) (for repository rules) or organization settings (for organization rules). |
| 27 | + |
| 28 | +### Automatic Rule File Detection |
| 29 | +Rules automatically discovered from files in your repository (repository level only). |
12 | 30 |
|
13 | 31 | <Frame caption="Update repo rules at codegen.com/repos"> |
14 | 32 | <img src="/images/repo-rules.png" /> |
15 | 33 | </Frame> |
16 | 34 |
|
17 | | -## How Repository Rules Work |
| 35 | +## How Agent Rules Work |
| 36 | + |
| 37 | +When an agent is assigned a task, all applicable rules are automatically included in the agent's context as "Mandatory User Rules." The agent sees these rules alongside the actual task or prompt it receives, ensuring consistent behavior. |
| 38 | + |
| 39 | +**Rule Resolution Process:** |
| 40 | +1. **User Rules** are loaded first (if configured in your personal settings) |
| 41 | +2. **Organization Rules** are loaded next (if configured for your organization) |
| 42 | +3. **Repository Rules** are loaded next (if configured for the specific repository) |
| 43 | +4. **Higher-level rules override lower-level rules** when conflicts exist (Repository > Organization > User) |
| 44 | +5. **Automatic rule files** are discovered and included (repository level only) |
| 45 | +6. All rules are combined and presented to the agent as mandatory constraints |
| 46 | + |
| 47 | +For example, if you have a user rule "Always use semicolons in JavaScript," your organization has a rule "Use TypeScript for all new code," and a specific repository has a rule "Use JavaScript for this legacy project," the repository rule takes precedence, followed by the organization rule, then your personal user rule. |
| 48 | + |
| 49 | +## Configuring Agent Rules |
| 50 | + |
| 51 | +### User Rules |
| 52 | + |
| 53 | +User rules are personal preferences that apply to all your work across organizations. These are perfect for setting your individual coding style, preferred tools, or workflow preferences. |
| 54 | + |
| 55 | +**To configure user rules:** |
| 56 | +1. Navigate to your personal settings in the Codegen web interface |
| 57 | +2. Look for the "User Rules" or "Personal Agent Rules" section |
| 58 | +3. Enter your personal preferences and coding standards |
| 59 | +4. Click "Save" to apply them across all organizations and repositories you work with |
| 60 | + |
| 61 | +<Tip> |
| 62 | + User rules are ideal for personal preferences like "Always include detailed commit messages," "Prefer functional programming patterns," or "Use specific linting configurations." |
| 63 | +</Tip> |
| 64 | + |
| 65 | +<Note> |
| 66 | + **Coming Soon**: User-level rules are currently being implemented and will be available in an upcoming release. The infrastructure is in place, and this feature will allow you to set personal coding preferences that follow you across all organizations. |
| 67 | +</Note> |
| 68 | + |
| 69 | +### Organization Rules |
18 | 70 |
|
19 | | -When an agent is assigned a task on a repository with defined rules, those rules are automatically prepended or made available to the LLM as part of its context. This means the agent "sees" these rules alongside the actual task or prompt it receives. |
| 71 | +Organization rules apply to all repositories within your organization and serve as default behavior guidelines. |
20 | 72 |
|
21 | | -For example, if you have a rule like "Always use tabs for indentation," the agent will be reminded of this preference before it starts writing or modifying code in that repository. |
| 73 | +**To configure organization rules:** |
| 74 | +1. Navigate to your organization settings in the Codegen web interface |
| 75 | +2. Look for the "Organization Rules" section |
| 76 | +3. Enter your organization-wide rules in the text area |
| 77 | +4. Click "Save" to apply them to all repositories in your organization |
22 | 78 |
|
23 | | -## Accessing and Configuring Repository Rules |
| 79 | +<Tip> |
| 80 | + Organization rules are perfect for setting coding standards, commit message conventions, or testing requirements that should apply across all your repositories. |
| 81 | +</Tip> |
24 | 82 |
|
25 | | -You can typically find and configure Repository Rules within the settings page for each specific repository in the Codegen web UI. |
| 83 | +### Repository Rules |
26 | 84 |
|
27 | | -1. Navigate to [codegen.com/repos](https://codegen.com/repos). |
28 | | -2. Select the repository for which you want to set rules. |
29 | | -3. Look for a section titled "Repository rules" or similar in the repository's settings. |
| 85 | +Repository rules apply to a specific repository and override any conflicting organization rules. |
| 86 | + |
| 87 | +**To configure repository rules:** |
| 88 | +1. Navigate to [codegen.com/repos](https://codegen.com/repos) |
| 89 | +2. Select the repository for which you want to set rules |
| 90 | +3. Look for the "Repository Rules" section in the repository's settings |
| 91 | +4. Enter your repository-specific rules in the text area |
| 92 | +5. Click "Save" to apply them |
30 | 93 |
|
31 | 94 | <Frame caption="Update repo rules at codegen.com/repos"> |
32 | 95 | <img src="/images/repo-rules.png" /> |
33 | 96 | </Frame> |
34 | 97 |
|
35 | | -In the text area provided (as shown in the image), you can specify any rules you want the agent to follow for this repository. Click "Save" to apply them. |
36 | | - |
37 | 98 | ## Automatic Rule File Detection |
38 | 99 |
|
39 | 100 | In addition to manual repository rules, Codegen automatically discovers and includes agent rule files from your repository when the agent starts working on it. This happens automatically whenever the `set_active_codebase` tool is used. |
@@ -105,30 +166,63 @@ When rules are discovered, they are displayed in the AgentTrace under the `SetAc |
105 | 166 |
|
106 | 167 | ## Common Use Cases and Examples |
107 | 168 |
|
108 | | -Repository rules are flexible and can be used for various purposes: |
| 169 | +Agent rules are flexible and can be used for various purposes across different levels: |
| 170 | + |
| 171 | +### User-Level Rules Examples |
| 172 | + |
| 173 | +Perfect for personal preferences that should apply across all your work: |
109 | 174 |
|
110 | | -- **Enforcing Linting/Formatting:** |
111 | | - - "Remember to run the linter with `npm run lint` before committing." |
112 | | - - "Ensure all Python code follows PEP 8 guidelines. Use `black` for formatting." |
113 | | -- **Specifying Commit Message Conventions:** |
| 175 | +- **Personal Coding Style:** |
| 176 | + - "I prefer functional programming patterns over object-oriented when possible." |
| 177 | + - "Always include detailed JSDoc comments for functions with more than 2 parameters." |
| 178 | +- **Workflow Preferences:** |
| 179 | + - "Include performance considerations in code reviews for any loops or database queries." |
| 180 | + - "Prefer explicit error handling over try-catch blocks when the error is expected." |
| 181 | +- **Tool Preferences:** |
| 182 | + - "Use my preferred linting configuration and code formatting style." |
| 183 | + - "Always suggest using TypeScript strict mode for new projects." |
| 184 | + |
| 185 | +### Organization-Level Rules Examples |
| 186 | + |
| 187 | +Perfect for organization-wide standards that should apply to all repositories: |
| 188 | + |
| 189 | +- **Coding Standards:** |
| 190 | + - "All code must follow our organization's style guide. Use Prettier for JavaScript/TypeScript formatting." |
| 191 | + - "All API endpoints must include proper error handling and logging." |
| 192 | +- **Security Requirements:** |
| 193 | + - "Never commit API keys, passwords, or other secrets to the repository." |
| 194 | + - "All database queries must use parameterized statements to prevent SQL injection." |
| 195 | +- **Process Requirements:** |
114 | 196 | - "All commit messages must follow the Conventional Commits specification." |
115 | | - - "Prefix commit messages with the related Linear issue ID (e.g., `ENG-123: ...`)." |
116 | | -- **Highlighting Project-Specific Information:** |
117 | | - - "This repository uses TypeScript. All new backend code should be in the `/server/src` directory." |
| 197 | + - "Every PR must include tests for new functionality." |
| 198 | + |
| 199 | +### Repository-Level Rules Examples |
| 200 | + |
| 201 | +Perfect for repository-specific requirements that may override organization defaults: |
| 202 | + |
| 203 | +- **Technology-Specific Rules:** |
| 204 | + - "This is a Python project. Use `black` for formatting and `pytest` for testing." |
| 205 | + - "This legacy repository uses JavaScript instead of our organization's TypeScript standard." |
| 206 | +- **Project-Specific Information:** |
| 207 | + - "All new backend code should be in the `/server/src` directory." |
118 | 208 | - "Avoid using deprecated function `old_function()`. Use `new_function()` instead." |
119 | | -- **Code Style Preferences:** |
120 | | - - "Don't write super long strings, as this will break pre-commit. Do triple-quoted strings with newlines, non-indented, instead!" (As seen in your example image) |
121 | | - - "Prefer functional components over class components in React." |
122 | | -- **Reminders for Testing:** |
123 | | - - "Ensure all new features have corresponding unit tests." |
124 | | - - "Run integration tests with `npm run test:integration` after significant changes." |
| 209 | +- **Build and Deployment:** |
| 210 | + - "Run `npm run build` before committing to ensure the build passes." |
| 211 | + - "This repository deploys automatically on merge to main - ensure all tests pass." |
| 212 | + |
| 213 | +### Rule Hierarchy in Action |
| 214 | + |
| 215 | +Here's how user, organization, and repository rules work together: |
| 216 | + |
| 217 | +**User Rule:** "I prefer detailed error messages with context" |
| 218 | +**Organization Rule:** "Use TypeScript for all new code" |
| 219 | +**Repository Rule:** "This legacy project uses JavaScript - do not convert existing files" |
| 220 | +**Result:** The agent will use JavaScript for this specific repository (repository rule wins), but will still include detailed error messages (user rule applies) since there's no conflict. |
125 | 221 |
|
126 | 222 | <Tip> |
127 | | - Keep your repository rules concise and clear. Overly complex or numerous rules |
128 | | - might confuse the agent or lead to suboptimal performance. Focus on the most |
129 | | - critical guidelines for each repository. |
| 223 | + Keep your rules concise and clear. Overly complex or numerous rules might confuse the agent or lead to suboptimal performance. Focus on the most critical guidelines for your organization and repositories. |
130 | 224 | </Tip> |
131 | 225 |
|
132 | 226 | <Note> |
133 | | - Both manual repository rules and automatic rule files are applied *in addition* to any global prompting strategies or agent capabilities. They provide a repository-specific layer of instruction that helps ensure consistent behavior across your codebase. |
| 227 | + All agent rules (user, organization, repository, and automatic rule files) are applied *in addition* to any global prompting strategies or agent capabilities. They provide a hierarchical layer of instruction that helps ensure consistent behavior across your personal work, organization, and codebases. |
134 | 228 | </Note>{" "} |
0 commit comments