# Complaint Agent

The **Complaint Agent** is a prebuilt solution provided by Emporix as part of the Agents Library. Like other prebuilt agents, it runs in the background and integrates into existing business workflows. It steps in when needed, reducing the need for manual intervention in complaint management.

{% hint style="warning" %}
The Complaint Agent is designed to support B2B cases only as its configuration requires Company Contact Information to properly handle the issues.
{% endhint %}

## Purpose

The Complaint Agent aims to solve common business challenges immediately related to customer complaints. By automating aspects of complaint handling, it helps to reduce manual work and workflows, thereby saving time and contributing to a more efficient and customer-friendly operation.

## Key benefits

Enabling the Complaint Agent offers several pros.

| Benefit                              | Description                                                                                                   |
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------- |
| **Streamlined complaint management** | It is specifically designed to make the process how customer complaints are handled more efficient.           |
| **Reduced manual work**              | It helps reduce the manual effort required from your team, freeing them to focus on other areas.              |
| **Increased efficiency**             | The agent contributes to a more efficient operation by handling routine tasks automatically.                  |
| **Enhanced customer experience**     | It helps merchants deliver a more customer-friendly operation.                                                |
| **Immediate solution**               | As a prebuilt agent, it provides a ready-to-use solution to address complaint management challenges promptly. |
| **Scalability**                      | It enables businesses to scale operations without adding complexity to their complaint handling processes.    |

## How it works

The Complaint Agent is designed to handle customer complaints in a structured and automated way. You can trigger the agent by API calls, typically as part of a value stream in your own environment.

You can view the exact steps and actions that are predefined for Complaint Agent type in the **Template Prompt** field.

{% hint style="success" %}
The **Template Prompt** cannot be modified, but gives the insights into the agent workings. You can use it as a base if you want to create a custom agent.
{% endhint %}

### Triggers

Trigger the Complaint Agent, for example, when:

* an email arrives in the customer support inbox
* a support ticket is created in Jira or Zendesk, or other tool
* a new customer issue is detected by another tool or workflow you integrate with

You have full freedom to integrate the Complaint Agent into your existing processes and tools.

{% hint style="success" %}
The easiest and recommended way of importing agents into your workflows is by using an agent within a value stream step. You need to establish a connection with the specific agent and configure the value stream step to incorporate it. For more information about the value streams, see the [OE Value Streams](/oe/value-streams/working-with-value-streams/creating-value-streams.md) and [VSM Value Streams](https://app.gitbook.com/s/rSc4haeKWrTrOPHzdrMO/value-streams/dp-introduction) documentation.

You can also use a standard API to call the Agent from external system. For more information, check the [AI Service API Reference](/api-references/api-guides/artificial-intelligence/ai-service.md).
{% endhint %}

### Custom entities

Upon the installation, the Complaint Agent automatically creates two **custom entity types** with corresponding mixin schemas defined:

* **Complaint Agent Context**
* **Support Agent Context**

<figure><img src="/files/S6OxSvpHTcZrRmNzOZTH" alt="Custom Entities"><figcaption></figcaption></figure>

{% hint style="info" %}
For more information about custom entities, see the [Custom Entities](/ce/management-dashboard/settings/custom-entities.md).

For more information about mixin schemas, see the [Mixin Schemas](https://app.gitbook.com/s/bTY7EwZtYYQYC6GOcdTj/management-dashboard/settings/mixin=schemas).
{% endhint %}

Whenever an agent of the `COMPLAINT_AGENT` type comes into action, the instances of these entities are created and stored in the system for the monitoring purposes.

#### Complaint Agent Context

Each time a Complaint Agent is triggered in any of your workflows, for example in a value stream, the system records this event in a created instance of the Complaint Agent Context. Thanks to that, you are able to check when and how the agent was invoked, and what was the undertaken activity. The Complaint Agent Context stores the following information about complaints:

* **Action Input** - The source of the incoming complaint, for example, email content.
* **Action Summary** - The action generated by the agent.
* **Automatic Action** - The indicator whether the action was automatically resolved by the agent or required some collaboration from other agents or humans in the loop.
* **Category** - The categorization of the complaint. The agent analyzes the information included in the complaint source and assigns a specific [category](#categories) according to the prompt in the agent definition.

<figure><img src="/files/Dmnk5ZlcHbbCxWH8DXlr" alt="Complaint Agent Context"><figcaption></figcaption></figure>

#### Support Agent Context

If a Complaint Agent requires collaboration, an instance of the Support Agent Context is created and stored in the **Custom Instances**. The Support Agent Context keeps the following information:

* Collaboration tool used
* Slack Channel ID created for the complaint case
* Conversation history
* Invited participants

{% hint style="warning" %}
Currently only Slack tool is supported.
{% endhint %}

<figure><img src="/files/JELCEIZrGW365gwWQcox" alt="Support Agent Context"><figcaption></figcaption></figure>

#### Contact Info mixin

Additionally, installing the Complaint Agent adds the **Contact Info** mixin to the **Company** entity. This mixin stores information about the contacts within a company.

The Collaboration Agent uses the emails from the **Company Info** to match the company contacts with Slack users and invites them as participants to a collaboration channel.

<figure><img src="/files/aRRrdRYun4o2F4ZIzvgi" alt="Company Contact Info"><figcaption></figcaption></figure>

## Agent configuration

The Complaint Agent offers flexibility in the way how the customer complaints are handled. You can define **automatic** actions that the agent is able to handle by itself. For more complex use cases that require involving human interactions through the communication tool (for example, Slack), you can define **semi-automatic** agent actions.

### Scopes

Select the scopes required to trigger the agent. If you want the agent to be triggered by your existing ticketing system, use the **Integration** scope.

### User Prompt

The default prompt defines the following rules for the Complaint Agent:

```
<rules>
  <rule>For `MISSING_INVOICE`: Send the invoice using the `send-invoice` tool.</rule>
  <rule>For `INCORRECT_INVOICE`: Start the collaboration process using the handoff tool.</rule>
  <rule>For `DELIVERY_TOO_LATE`: Start the collaboration process using the handoff tool.</rule>
  <rule>For `PRODUCT_DAMAGED`: Start the collaboration process using the handoff tool.</rule>
  <rule>For `OTHER`: Return information that no action has been performed.</rule>
</rules>      
```

When creating an agent from the **Complaint Agent** template, you can configure the agent to you liking by adjusting the rules for the agent's behavior in the **User Prompt** field.

Using the prompt `<rules>`, define the expected [categories](#categories) of the complaints that might occur and specify the corresponding agent's actions for each category. For instance, you can add new complaint categories, disable automatic actions (such as invoice resending), or even extend the custom entities with new fields.

{% hint style="warning" %}
If you extend custom entities, update the prompt accordingly to instruct the agent on how to populate the new fields.
{% endhint %}

#### Categories

The categories define the agent's responses to certain triggers. The agent recognizes a category of a complaint in the complaint source and undertakes a specific action as defined for a particular category.

The predefined categories:

* Missing Invoice - The agent automatically resends the invoice using the `send-invoice` tool. The invoice is sent to the email address associated with the order, not to the sender’s email.

{% hint style="warning" %}
The `send-invoice` tool is enabled by default. Removing the tool prevents the automatic action.
{% endhint %}

* Incorrect Invoice - The Agent starts a collaboration process:
  * It creates a Support Agent Context instance.
  * Using the Collaboration Agent under-the-hood, it invites the relevant people into a Slack channel based on company **Contact Info**.
  * Once collaboration is set up, the Complaint Agent finishes its job.
  * Further interaction is handled by the [Support Agent](/agentic-commerce-intelligence/agentic-intelligence/agent-library/support-agent.md).
* Delivery Too Late - The Agent initiates automatic and semi-automatic actions:
  * Using the Collaboration Agent, a Slack channel is created with relevant merchants, context about the issue is passed with the email to the customer reporting an issue.
  * The merchant is able to ask the Support Agent to update the actual delivery date on the order level and send the relevant message to the customer.
* Product Damaged - The Agent starts a collaboration process:
  * Using the Collaboration Agent, the communication space is created with relevant people involved.
  * The merchant is able to decide how to proceed further depending on the exact issue and send an appropriate email to the customer.
* Other Complaints - The agent takes **no action**. This prevents unnecessary collaboration or automation for unrelated emails.

Use the predefined categories as a starting point to configure your Complaint Agent to your needs.

{% hint style="success" %}
For automation of fetching and updating the actual data from/to an external system (ERP, CRM etc), register a custom MCP Server with relevant AI tools and enable them directly for the Agent. This approach allows you to let the Agent take care of more tasks for you.
{% endhint %}

### AI Tools

The Complaint Agent requires the connection to the **Slack AI Tool** to work properly. First, create the Slack AI bot in the **Agentic AI** -> **AI Tools**.

{% hint style="info" %}
For more information on how to create a bot, see the [Slack AI Tool](/agentic-commerce-intelligence/agentic-intelligence/configuration/tools/slack.md).
{% endhint %}

Once the Slack AI Tool is ready, establish the connection with the bot by selecting the AI Tool in the **Native Tools** list.

<figure><img src="/files/PLFgpinCUtfyYlhJNJ7e" alt="Slack Tool" width="375"><figcaption></figcaption></figure>

This way, the Complaint Agent can trigger the Support Agent directly within the Slack workspace.

### Collaboration

The Complaint Agent has a predefined connection to the [Collaboration Agent](/agentic-commerce-intelligence/agentic-intelligence/agent-library/collaboration-agent.md). The Collaboration Agent acts as a **handoff agent** that works in the background taking care of creating a space for communication and notifications. You can add more collaboration agents when configuring your Complaint Agent, to enable smooth cooperation between team of agents to solve different cases.

{% hint style="danger" %}
**Agent Dependencies**

For its correct operation, the Complaint Agent requires the following:

* the **AI tools** from the Extensibility MCP server
* the **custom entities** automatically created during the agent installation

Be careful NOT TO remove them accidentally.
{% endhint %}

{% hint style="info" %}
All Agents operations are tracked in the **AI Logs** view. You can check the details of the requests, jobs, and sessions for monitoring and evaluation purposes. For more information, see the [AI Logs](/agentic-commerce-intelligence/agentic-intelligence/logs.md).
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.emporix.io/agentic-commerce-intelligence/agentic-intelligence/agent-library/complaint-agent.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
