Skip to main content

Scenario

By default, Enneo carries out the automatic execution (background processing) of AI agents only for the first incoming email of a ticket and only when exactly one AI agent has been identified. The standard background processing therefore does not apply in two situations:
  1. Multiple AI Agents Recognized: A customer raises multiple concerns in one email, e.g., a cancellation and a revocation. Enneo recognizes both AI agents, but for security reasons does not automatically execute either.
  2. Sequential Replies: A customer replies again to an existing ticket. AI processing does occur (tags, AI agent recognition, parameter extraction), but automatic execution is not triggered again.
In both cases, the ticket is instead assigned to a human processor. This behavior can be adjusted using an Event Hook.

Possible Solution

An Event Hook responds to incoming tickets or customer responses, checks the recognized AI agents, and triggers the automatic execution for each one.

Step 1: Create an Event Hook

Under Settings -> External System Integration -> Events, create one or both of the following Event Hooks:
  • TicketCreated — is triggered after receiving a new ticket and the completion of AI processing. Use when multiple AI agents on the initial email should be automatically executed.
  • TicketResponse — is triggered when a response to an existing ticket has been received from the customer and AI processing has been completed. Use when AI agents should also be automatically executed in the case of sequential responses.
The following code can be used for both events. It loads all recognized AI Agents (Intents) in ready status and executes each one individually:
POST /api/mind/ticket/:ticketId/autoexecute?executeAgentId=:aiAgentId&allowMultipleIntents=true&allowWithReplies=true
The executeAgentId parameter is the numerical ID of the AI agent that should be executed. It is set per call for each AI agent.The allowMultipleIntents=true parameter allows automatic execution even when multiple AI agents have been recognized on the ticket. Without this parameter, execution is rejected for security reasons when multiple agents have been identified.The allowWithReplies=true parameter allows automatic execution even when the ticket already contains incoming customer responses. Without this parameter, execution is rejected as soon as a customer response exists on the ticket. This parameter is only relevant for the TicketResponse event.
For clarity, error handling is deliberately omitted in this code example.
<?php

use EnneoSDK\ApiEnneo;

require(getenv()['SDK'] ?? 'sdk.php');

/** @var stdClass $in - contains all defined input parameters from the event */

// Load ticket data
$ticket = ApiEnneo::getTicket($in->ticketId);

// Only process open tickets
if ($ticket->status !== 'open') {
    echo json_encode(['autoExecute' => false, 'reason' => 'Ticket is not open']);
    return;
}

// Load Intents (recognized AI agents)
$intents = ApiEnneo::get(endpoint: '/api/mind/intent/byTicketId/' . $in->ticketId);

// Collect all Intents in "ready" status
$readyIntents = array_filter($intents->intents, fn($i) => $i->status === 'ready');

if (empty($readyIntents)) {
    echo json_encode(['autoExecute' => false, 'reason' => 'No Intents found in ready status']);
    return;
}

// Optional: Further checks, e.g., customer recognition or tags
// if (!$ticket->contractId) {
//     echo json_encode(['autoExecute' => false, 'reason' => 'No Contract recognized']);
//     return;
// }

// Optional: Only automatically execute certain AI agents
// $allowedAgentIds = [4, 5, 12, 34];
// $readyIntents = array_filter($readyIntents, fn($i) => in_array($i->aiAgentId, $allowedAgentIds));

// Execute each recognized AI agent individually
$results = [];
foreach ($readyIntents as $intent) {
    $result = ApiEnneo::post(
        endpoint: '/api/mind/ticket/' . $in->ticketId . '/autoexecute?executeAgentId=' . $intent->aiAgentId . '&allowMultipleIntents=true&allowWithReplies=true'
    );
    $results[] = ['agentId' => $intent->aiAgentId, 'name' => $intent->name, 'result' => $result];
}

echo json_encode(['autoExecute' => true, 'executedAgents' => count($results), 'results' => $results]);

Step 2: Automatic Processing by Enneo

After each call to the Autoexecute endpoint, Enneo automatically performs the following steps:
  1. The customer is sent the reply created by the AI agent.
  2. The ticket is closed.
  3. The ticket is marked as having been processed fully automatically (L5).
In the case of multiple AI agents, each is executed separately and the results are processed sequentially.

Notes

  • The TicketCreated event is suitable for the initial email with multiple issues. The TicketResponse event is suitable for sequential responses. Both events can be configured simultaneously with the same code.
  • The allowWithReplies=true parameter is necessary because Enneo by default blocks automatic execution as soon as a customer response exists on the ticket. For the TicketCreated event, this parameter is ineffective as there are not yet any responses.
  • The allowMultipleIntents=true parameter is necessary because without it, execution is rejected for security reasons when multiple agents are identified.
  • The executeAgentId parameter ensures that only the desired AI agent is executed per call.
  • It is recommended to maintain a whitelist (allowedAgentIds) of the AI agents that are allowed for automatic execution in the code.