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

# Rules

> Write natural language rules that tell a Ravenna Agent how to handle specific requests: triggers, audience, drafts and publishing, versions, and reuse across agents.

Rules are natural language instructions that define how your agent handles specific scenarios. Each rule teaches your agent a capability using prompts that reference Ravenna resources like forms (Structured intake forms with custom fields) and knowledge folders (Searchable documentation and resources).

## Resource access model

Agents operate on an explicit-access model. They do not have automatic access to all workspace resources. Access is granted through two mechanisms:

* **`@` mentions in rules or escalation instructions** grant access to forms, tools, knowledge bases, categories, tags, and statuses. If a form is not referenced in any rule, the agent cannot use it.
* **Knowledge configuration** grants access to specific knowledge folders via the agent's **Knowledge** tab.

This means:

* A form must be `@`-mentioned in at least one rule for the agent to create tickets of that type.
* Tools are referenced with `@` in rules to specify when they should be used.
* Knowledge folders are selected in the agent's knowledge configuration.

Agents cannot trigger workflows. Hand off to a workflow through ticket state instead. For example, submit a form, set a category, or change a tag or status, and configure a workflow to fire on that ticket event.

***

## Rule audience

Every rule carries an `audienceType` and, when applicable, an `allowedGroups` list. These fields are the admin-configured access control on the rule and are enforced at match time, before the rule is offered to the model.

### Audience types

| `audienceType` | Admits |
| - | - |
| `OrganizationMembers` (default; UI label: **Organization members**) | Requesters whose `OrganizationMember.role` is anything but `GUEST`. Organization guests and requesters with no organization membership are rejected. |
| `Everyone` (UI label: **Everyone**) | All requesters, including organization guests, unresolved users, and anonymous portal or guest-chat sessions. |
| `WorkspaceMembers` (UI label: **Workspace members**) | Requesters whose resolved participant role is `Member` or `Admin` on the workspace. Guests and unresolved roles are rejected. |
| `Specific` (UI label: **User groups**) | Requesters who are members of at least one group in `allowedGroups`. Membership counts both direct users and integration-linked users on the group. |

A `Specific` rule with an empty `allowedGroups` array matches nobody. The publish preview flags it (`matchesNobody`).

Group ids on a rule are org-scoped: when the rule is saved, Ravenna verifies each id resolves to a group visible in the rule's workspace. Ids from another org are rejected, so an id leaked out of context cannot be used to open access.

### Runtime evaluation

The agent runs the audience gate once per turn, before rule matching:

1. It reads the **latest non-bot author** on the ticket as the invoker. The requester is not used, so in a mixed thread a member's reply makes member-audience rules matchable even if a guest opened the ticket. The tool then executes as that member, so read scope is bounded to what they could open themselves.
2. For each enabled rule, the agent evaluates the invoker against the rule's audience:
   * `Everyone` always admits.
   * `OrganizationMembers` admits when the invoker's organization role is not `GUEST`. The role is read once per turn, and only when an enabled rule on the agent uses this audience.
   * `WorkspaceMembers` admits only when the invoker's resolved participant role is `Admin` or `Member`. Guest and unknown roles are rejected.
   * `Specific` admits when the invoker belongs to any group in the rule's `allowedGroups`. Membership is resolved once per turn across the union of group ids referenced by all `Specific` rules on the agent, rules with other audiences do not trigger group lookups.
3. Rules the invoker does not satisfy are dropped from the candidate set. The semantic matcher and the prompt's rules section never see them.

Disabled rule relations are skipped by the audience gate entirely, since they contribute no tools or matching behavior downstream.

### Fails closed on unknown roles

The audience gate has no execution backstop. Unknown or unresolved invoker roles are therefore treated as non-members, so `OrganizationMembers`, `WorkspaceMembers`, and `Specific` rules are withheld. Only `Everyone` rules survive when the requester's identity cannot be resolved.

### A rule's tools don't change its audience

Audience is the only thing that decides who can match a rule, and anyone it admits can run every tool the rule carries. Tools don't check the requester's workspace role on their own: the rule's input settings decide what a tool can act on, though a target policy such as `admin-for-others` still judges who some tools act on. Tools that read tickets, such as `search_tickets`, run as the requester and see only what they could open themselves. `search_access_entitlements` shows a requester who isn't an organization admin access to the apps and groups they own, plus their own access when `user_ids` is limited to the requester, which makes "check my own access" self-service. On a scheduled, webhook, or event run nobody is asking, so it says entitlements aren't available. `query_analytics_chart` charts only a guest's own tickets. `okta_search_system_logs` looks up only a requester's own events unless they're a workspace member or admin, or the rule sets the person. `list_users` and `list_workspace_members` refuse a requester who isn't a workspace member or admin, since nothing narrows the people they list. Agent tools never return private notes or the files posted on them, whoever asks. `OrganizationMembers` still admits employees who are guests in this workspace, so use `WorkspaceMembers` on any rule whose actions should stay with workspace members.

The audience gate applies on both rule paths: the standard semantic matcher and the activation path that skips matching to run a named rule from an activation cron or approved batch. Skipping the matcher is not a reason to skip the audience gate, since a guest can reply in a scheduled run's thread.

***

## Rule-writing patterns

### Effective rule structure

A well-written rule has three parts:

1. **Trigger condition** describes when the rule activates. Be specific about the scenarios, keywords, or kinds of request.
2. **Action sequence** describes what the agent should do, referencing resources with `@` mentions. For multi-step processes, use numbered steps.
3. **Outcome definition** tells the agent what to communicate back to the user after completing the action.

### Multi-resource rules

A single rule can reference multiple resources. Common combinations:

* **Knowledge + form:** Check `@Knowledge Base` first. If the answer resolves the question, respond with it. If not, create a ticket with `@Form Name`.
* **Tool + tool:** Use `@Look up device with Fleet` to get device info, then `@Run query with Fleet` to run diagnostics. Analyze results before responding.
* **Form + workflow handoff:** Collect information via `@Form Name` and submit it on the ticket. A workflow triggered by that form submission handles the backend processing.
* **Application + access levels:** Use `@List Applications` to find the app, then `@List Access Levels` to determine available permission tiers before creating a request.

### Rule design recommendations

* **One scenario per rule.** A rule that handles password resets, software access, and hardware issues is too broad. Split into three rules.
* **Include fallback behavior.** Tell the agent what to do if the primary action fails or does not apply. For example: "If no matching article is found, create a support ticket."
* **Specify user communication.** Tell the agent what to say to the user at each step: confirmation messages, expected timelines, next steps.
* **Avoid overlapping triggers.** The agent applies only one rule per request. If two rules fit a message equally well, the agent asks the user which one they meant before acting. Frequent clarification questions mean your rules overlap. Distinct trigger conditions produce fewer questions and more predictable behavior.

### Channel awareness

Each turn, the agent identifies which channel a message arrived on: a Slack channel, direct message, the Portal (Self-service home where end users chat with the agent and submit requests), email, or an external ticketing integration such as Jira. This context is automatic and requires no rule configuration.

> [!NOTE]
>
> When a workspace connects a published agent to its portal, that agent powers the portal chat: it answers from knowledge, creates tickets, and routes them to the right team. See the [Portal](https://docs.ravenna.ai/documentation/platform/portal.md#chat-with-the-ai-agent).

Channel awareness prevents **circular redirects**. If a rule or knowledge base article tells users to "post in `#it-help`" and the user is already messaging from `#it-help`, the agent recognizes the redirect points at their current location. Instead of echoing the instruction back, the agent reads the article as a script: it collects the inputs the human responder will need, then escalates the ticket. The full conversation becomes the handoff context for the assignee.

For redirects to a **different** channel (for example, a user in `#general` who needs to post in `#it-help`), the agent relays the instruction verbatim so the user knows where to go next.

> [accordion] When it applies
>
> The agent applies channel-aware self-reference handling when it can identify a specific end-user channel:
>
> * Slack channels (channel name known)
> * External ticketing integrations such as Jira, where the project or system is known
>
> Redirects from direct messages, the Portal, email, and automated sources are always treated as legitimate cross-channel advice and relayed to the user.

> [accordion] Example
>
> **Rule or KB article:**
>
> > For laptop replacements, post in `#it-help` with your asset tag, preferred model, and shipping address.
>
> **User messages from `#it-help`:**
>
> > My laptop screen is cracked, can I get a replacement?
>
> **Agent behavior:** Instead of repeating "post in `#it-help`," the agent asks for the asset tag, preferred model, and shipping address one item at a time, then publishes a ticket with the collected information for a human responder.

> [accordion] Channel drift
>
> When a ticket spans multiple channels (for example, a user opens a request in Slack and replies later by email), the agent treats follow-ups as continuations of the same ticket. It carries forward what the user already provided and does not redirect them back to the original channel.

***

## Workspace vs agent-level rules

| Aspect | Workspace-level | Agent-specific |
| - | - | - |
| Scope | Shared across multiple agents | Single agent only |
| Editing | Centralized. Changes propagate to all attached agents | Edited per agent |
| Best for | Common scenarios (password resets, software access) | Agent-specific behavior for a particular channel or team |

A workspace-level rule cannot be deleted while it is attached to any agent. Remove it from all agents first.

### Duplicating vs attaching

* **Attach** a workspace-level rule when multiple agents should share identical behavior. Edits propagate to all agents using that rule.
* **Duplicate** a rule when you need an independent variation. The copy can be modified without affecting the original, and changes to the original do not propagate to the copy.

***

## Constraints

* **Form access requires rule reference.** The agent cannot use a form unless it is `@`-mentioned in at least one rule.
* **Only Published forms are surfaced.** Draft and Archived forms are filtered out at runtime, even if they are `@`-mentioned in a rule. The agent treats them as unavailable and continues with other rules or escalates. Publish the form to make it usable.
* **Agents cannot trigger workflows.** Hand off through ticket state (form submitted, category assigned, tags changed, status changed) and let a workflow fire on that event.
* **Single rule selection.** The agent applies only one rule per request, preferring the most specific match. When several rules tie, the agent asks the user which one they meant and has no rule-scoped tools until the user answers. After two replies that don't pick a rule, the agent proceeds as if no rule matched: with knowledge connected it searches it for the original request and escalates if nothing answers it, and without knowledge it escalates. Predictability improves when rules have distinct, non-overlapping trigger conditions.
* **Rule audience gates matching, not just display.** Rules whose `audienceType`/`allowedGroups` do not admit the current invoker are dropped before the matcher runs. Unresolved and anonymous requesters see only `Everyone` rules. See [Rule audience](#rule-audience).
* **Workspace-level rule deletion is blocked** while the rule is attached to any agent.


## Related topics

- [Delete a rule](https://docs.ravenna.ai/api/rules/delete-a-rule.md)
- [Writing agent rules](https://docs.ravenna.ai/guides/best-practices/writing-agent-rules.md)
- [Attach a rule to an agent](https://docs.ravenna.ai/api/rules/attach-a-rule-to-an-agent.md)
- [Create a new rule](https://docs.ravenna.ai/api/rules/create-a-new-rule.md)
- [Detach a rule from an agent](https://docs.ravenna.ai/api/rules/detach-a-rule-from-an-agent.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.