# Configuring the Deviation Agent (QMS)

In Vaults using Veeva AI for Quality, Veeva QMS provides a Deviation Agent that can generate a narrative summary of the investigation or CAPA plan for a _Deviation_. The summary includes information from key related records, such as _Investigations_ and _Root Causes_ for an investigation summary, and _CAPA Actions_ for a CAPA plan summary. The Deviation Agent can also answer questions about a _Deviation_ record and its related records via Veeva AI Chat.

See below for definitions of terms used in this article:

* **Agent:** Defines a set of Agent Actions that can be performed on a document or object record in your Vault.
* **Agent Objective**: A description of the Agent's roles and responsibilities, similar to a job description.
* **Agent Context:** Defines the information an Agent knows about your Vault, allowing the Agent Action to summarize this information in a response. Agent Context can include data from an object record such as fields and object relationships.
* **Agent Actions:** The actions that the Agent can perform. Agents perform Agent Actions based on the provided Objective, Context, and instructions.
* **Agent Tools:** Tools are assigned to Agent Actions, and provide the structure for the Agent's response in order to ensure a consistent output format. Agent Tools are not editable.

## Supported Objects & Object Types {#objects}

The Deviation Agent supports the following objects and object types:

* _Deviation_: All standard object types
* _Quality Event_: _Deviation_ and _GCP Deviation_ object types

The Deviation Agent does not support custom objects and object types.

Your Vault may process deviations using either a standalone _Deviation_ object or a _Quality Event_ object of the _Deviation_ or _GCP Deviation_ object type. In this article, these objects are collectively referred to as _Deviations_. All configuration steps in this article also apply to the _Deviation_ and _GCP Deviation_ object types of the _Quality Event_ object.

## Supported Agent Actions

The following Agent Actions are available for the Deviation Agent on supported objects and object types:

* **Ask Questions about the Deviation**: Lets users ask the Deviation Agent questions about a _Deviation_ record via the Veeva AI Chat interface.
* **Generate Investigation Summary**: Lets users summarize an investigation by clicking the **Generate Summary** (<img class="inline" src="https://platform.veevavault.help/assets/images/quality-qms-nsg-icon.png" alt="Narrative Summary Generation Icon" style="" />) icon next to the _Investigation Summary & Conclusion_ field on a _Deviation_ record.
* **Generate CAPA Summary**: Lets users summarize a CAPA plan by clicking the **Generate Summary** (<img class="inline" src="https://platform.veevavault.help/assets/images/quality-qms-nsg-icon.png" alt="Narrative Summary Generation Icon" style="" />) icon next to the _CAPA Plan Summary_ field on a _Deviation_ record.

## Configuration Overview

To configure the Deviation Agent, complete the following steps:

* [Activate][1] the Deviation Agent
* [Configure][2] summary fields on the _Deviation_ object
* Optional: [Configure][3] Agent Actions
* Optional: [Configure][4] custom Agent Context
* [Configure][5] user permissions

## Activating Agents {#activate}

You must activate the Agents in order to make them available for use. To activate, navigate to **Admin > Configuration > Agents > Deviation Agent**, and set the _Status_ of the Agent to _Active_.

## Configuring Object Fields {#fields}

Activate the following Rich Text fields on the _Deviation_ object and add them to the [relevant object types][6] and layouts:

* _CAPA Plan Summary_ (`capa_plan_summary_rt__v`)
* _Investigation Summary & Conclusion_ (`investigation_summary_conclusion_rt__v`)

We recommend hiding these fields via [Atomic Security](/en/lr/47850/) or [layout rules](/en/lr/51632/) in earlier lifecycle states and exposing them only during the later stages of the lifecycle, when your data is expected to be most complete for summary generation.

<div class="note-border alert-info">
  <div class="alert alert-info" role="alert">
    <div><i class="far fa-info-circle"></i></div>
    <div class="alert-text">
      <p><strong>Note</strong>: The Rich Text fields listed above are distinct from the similarly labelled <em>CAPA Plan Summary</em> (<code class="language-plaintext highlighter-rouge">capa_plan_summary__v</code>) and <em>Investigation Summary &amp; Conclusion</em> (<code class="language-plaintext highlighter-rouge">investigation_summary_conclusion__v</code>) Text fields on the <em>Deviation</em> object. These fields are not supported for narrative summary generation.</p>
    </div>
  </div>
</div>



## Configuring Agent Actions {#actions}

You can optionally configure standard Agent Actions by adding custom context and corresponding _Supplemental Instructions_ to let that action know that custom context exists for the action. See [Configuring Context][4] for more information about creating custom context.

You can also optionally configure new custom Agent Actions in order to extend the capabilities of the Deviation Agent to address your business needs.

## Configuring Agent Context {#context}

You can optionally configure custom Agent Context in order to define additional related records and fields for the Agents to summarize. If using custom context, we recommend including similar objects, fields, and relationships as the standard context for optimal results.

1. Navigate to **Admin > Configuration > Agents > Deviation Agent**.
2. Expand the **Context** section and click **Create**.
3. From the **Type** drop-down, select **Object Data**.
4. Enter a **Label**.
5. Enter a **Name**.
6. Optional: Enter a **Description**.
7. Select an option for **Always Include**. This determines if the Agent always summarizes the information specified in this context.
8. In the _Configuration_ section, click **Generate Default** to populate the _Object Fields_ box with the default context for the Agent. You can modify the related objects and fields referenced in the generated context to suit your business needs. You can also write your own context using the same syntax as in [Word formatted output templates](/en/lr/796234/).
9. Click **Save**.
10. Navigate back to the Agent and select an **Action** from the _Actions_ section.
11. In the _Available Context_ section, click **Add**.
12. In the dialog, select the context you created.
13. Click **OK**.
14. On the Action, click **Edit**.
15. Optional: Add **Supplemental Instructions** to let the Agent know that custom context exists for this Action.
16. Click **Save**.

If you wish to only use a custom context for any of the available Agent Actions, you can inactivate the standard context by navigating to the context and setting the _Status_ to _Inactive_.

### Data Model Migration Considerations for Custom Context

When migrating to a standalone [quality event data model](/en/lr/722050/), any custom context configured for the Deviation Agent must be deleted, and recreated after migration is complete. Vault automatically updates the object and field references for standard context. If you are not using custom context, no action is required to reconfigure the Agents after transitioning to a standalone data model.

## Limitations

The following limitations affect the Deviation Agent:

* Summarize up to 10 related records per object relationship. For instance, the summary of an _Investigation_ can include up to 10 related _Root Cause_ records.
* A summary cannot be generated in a custom target field. You must use the standard _Investigation Summary & Conclusion_ and _CAPA Plan Summary_ fields.
* Generated summaries can contain up to 5,000 characters.
* Agents cannot summarize field values on the _Deviation_ record that have been edited without saving the record. Edits to related records made while editing the primary _Deviation_ are included in the summary.

## User Permissions {#user-permissions}

To interact with the Deviation Agent, users must have the following permissions:

<table>
  <tr>
   <th>Type</th>
   <th>Permission Label</th>
   <th>Controls</th>
  </tr>
  <tr>
   <td>Security Profile</td>
   <td>Agents: Deviation Agent: Execute</td>
   <td>Ability to generate a narrative summary using the Deviation Agent.</td>
  </tr>
  <tr>
   <td>Security Profile</td>
   <td>Application: Vault Actions: Veeva AI Chat: Use Chat</td>
   <td>Ability to view and interact with Veeva AI Chat.</td>
  </tr>
  <tr>
   <td>Security Profile</td>
   <td>Agents: Super Agent: Execute</td>
   <td>Ability to ask questions via Veeva AI Chat about a <em>Deviation</em> record.</td>
  </tr>
  <tr>
   <td>Security Profile</td>
   <td>Objects: Deviation: [object type]: Edit</td>
   <td>Ability to edit <em>Deviation</em> records of the relevant object type.</td>
  </tr>
  <tr>
   <td>Security Profile</td>
   <td>Objects: Deviation: Object Field Permissions: CAPA Plan Summary, Investigation Summary & Conclusion: Edit</td>
   <td>Ability to edit relevant fields on <em>Deviation</em> records.</td>
  </tr>
  <tr>
   <td>Atomic Security</td>
   <td>Deviation Lifecycle: [state]: Atomic Security: Fields: CAPA Plan Summary, Investigation Summary & Conclusion: Edit</td>
   <td>Ability to edit relevant fields in applicable lifecycle states of the <em>Deviation Lifecycle</em>. </td>
  </tr>
</table>

## Related Permissions

The following permissions control your ability to configure Agents:

<table>
  <tr>
   <th>Type</th>
   <th>Permission</th>
   <th>Access Details</th>
  </tr>
  <tr>
   <td>Security Profile</td>
   <td>Admin: Agents: Edit</td>
   <td>Ability to edit and configure Agents.</td>
  </tr>
  <tr>
   <td>Security Profile</td>
   <td>Admin: Tools: Edit</td>
   <td>Ability to edit Agent Tools.</td>
  </tr>
  <tr>
   <td>Security Profile</td>
   <td>Agent Instance: Read</td>
   <td>Ability to view the <em>Agent Instance</em> object.</td>
  </tr>
  <tr>
   <td>Security Profile</td>
   <td>Agent Action Execution: Read</td>
   <td>Ability to view the <em>Agent Action Execution</em> object.</td>
  </tr>
  <tr>
   <td>Security Profile</td>
   <td>Admin: Objects: Edit</td>
   <td>Ability to edit and configure Vault objects.</td>
  </tr>
  <tr>
   <td>Security Profile</td>
   <td>Admin: Permission Sets: Edit</td>
   <td>Ability to edit and configure permission sets.</td>
  </tr>
</table>

[1]: #activate
[2]: #fields
[3]: #actions
[4]: #context
[5]: #user-permissions
[6]: #objects