> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cubic.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom agents

> Discover, create, and manage custom agents across your repositories

Custom agents are review rules that enforce your organization's specific best practices across pull requests.

Use the rules library to create agents, adopt community rules, and choose which repositories use them.

<img src="https://mintcdn.com/cubic-2/AzoJeLhtvGZBEz71/ai-review/images/rules-library.png?fit=max&auto=format&n=AzoJeLhtvGZBEz71&q=85&s=7d6a1ad6818665c8b7bf7247e9a6c586" alt="Rules library with categories and multi-repo management" className="border border-zinc-800 rounded-lg" width="3504" height="2126" data-path="ai-review/images/rules-library.png" />

## Rules library

Manage your agents from the [rules library](https://www.cubic.dev/rules-library).

## Creating custom agents

To create a new agent, navigate to the **[Rules library](https://www.cubic.dev/rules-library)** in cubic and click "Add rule". You can also adopt existing agents from the community library with a single click.

Each custom agent includes:

1. **A Name**\
   A concise title, like "Prevent N+1 Queries" or "Require Sentry Error Handling."

2. **A Description**\
   A clear, natural-language instruction the AI will use, such as "Flag code that may cause multiple database calls inside loops."

   <Tip>
     Be as clear and explicit as possible; the more specific you are, the better the results.
   </Tip>

3. **Linked instruction files**
   For repository-specific agents, open **Advanced** and enter one repo-relative path per line, such as `docs/style-guide.md` or `.cubic/review-agent.md`. You can use linked files together with text instructions. You can also define linked files in `cubic.yaml` with a `file_paths` list. cubic reads those files from the pull request head commit when the review runs, so updates to the file apply to future reviews without editing the agent.

   File-backed agents are best when your team already maintains detailed style, framework, or architecture rules in the repository. General context files help cubic understand the codebase, but custom agents are the right place for checks you want cubic to actively flag.

   <Note>
     The agent text and linked files share one 10,000 character limit. cubic uses the first 10,000
     characters and ignores the rest. The multi-repository rules-library dialog still creates
     text-only agents; use repository-scoped agents or `cubic.yaml` for linked files.
   </Note>

4. **Optional Path Filters**
   Use [Glob patterns](https://en.wikipedia.org/wiki/Glob_\(programming\)) to limit where the agent applies (or exclude certain paths). This is especially helpful for monorepos, where different directories often require different agents. For example:
   * **Include**: `backend/**` to apply the agent only to files under a `backend` folder.
   * **Exclude**: `!tests/**` to ignore test files and focus on production code.

<img src="https://mintcdn.com/cubic-2/AzoJeLhtvGZBEz71/ai-review/images/add-custom-rule-modal.png?fit=max&auto=format&n=AzoJeLhtvGZBEz71&q=85&s=cf1653786f78e6da3a6b78284e3b3a43" alt="Add agent" className="border border-zinc-800 rounded-lg" width="1366" height="1114" data-path="ai-review/images/add-custom-rule-modal.png" />

## Agent attribution in comments

When a custom agent flags an issue, the review comment will indicate which agent triggered it. This helps you understand which agents are working and allows you to iterate on your agent instructions over time.

<img src="https://mintcdn.com/cubic-2/rRTibIhzKbTPCyhf/ai-review/images/custom-rule-comment.png?fit=max&auto=format&n=rRTibIhzKbTPCyhf&q=85&s=55704e872dcc4d02316ec1007522f67f" alt="Review comment showing which custom agent triggered the feedback" className="border border-zinc-800 rounded-lg" width="1950" height="1268" data-path="ai-review/images/custom-rule-comment.png" />

## Managing agents across repositories

Create an agent once and select the repositories that use it. Updating the agent updates its instructions for all selected repositories. Enable or disable it for each repository independently.

## Limitations

* **Agent limit**: Each repository can have a maximum of 5 enabled custom agents at a time. The rules library allows you to define more agents but only 5 can be active per repository.
* **Instruction length**: Text instructions and resolved file instructions use the same 10,000 character limit per custom agent. cubic concatenates the text and files in order and uses only the first 10,000 characters; the rest is not included in the review prompt. The dashboard shows how many characters are left or truncated before you save.
* **File paths**: File-backed agents accept repo-relative file paths only. Absolute paths, globs, parent-directory traversal, directories, binary files, and unreadable files are rejected or shown as warnings. Markdown and YAML files are read as plain text; cubic does not parse them as structured rule definitions.
* **Potential false positives**: Occasionally, the AI might incorrectly flag or overlook certain scenarios. Consider AI feedback as helpful guidance rather than definitive judgments.

## Tips for effective custom agents

* Describe the code to flag and explain why it matters. Include examples when the rule is easy to misinterpret.
* Combine related checks when they share the same scope.
* Use path filters to keep rules relevant to the files being reviewed.
* Focus on checks that linters do not cover, such as business logic and team-specific conventions.

## Next steps

* [**Rules library**](https://www.cubic.dev/rules-library): Explore community agents and manage your custom agents across repositories.
* [**AI review settings**](/ai-review/ai-review-settings): Configure AI review behavior for your repositories.
* [**Introduction**](/ai-review/introduction): Understand how cubic reviews pull requests by default.
