Events & Webhooks
Example: Automate Smart AI Agents
Approach to automatically execute smart AI agents based on your own security criteria
Scenario
By default, Enneo processes rule-based AI agents per dark processing for emails and letters, but not purely prompt-based ones. The reason is that the reliability of text produced purely by AI is less predictable than that of a rule value.
However, there are certain customer inquiries – e.g. password reset instructions or login problems with the Android or Apple app – which can be fully automated with a certain level of reliability. Instead of using the standard dark processing, the smart AI agent itself should decide whether an answer is secure enough to be sent automatically.
Possible Solution
The approach consists of four steps: A custom AI tool marks safe answers, an Event Hook checks the marking and triggers the automatic execution.
Step 1: Create Custom AI Tool
Under Settings -> AI Customization -> AI Tools, create a new tool, e.g. with the name mark_answer_as_safe. This tool will be invoked by the smart AI agent when it is confident that the answer can be sent automatically.
In the smart AI Agent's prompt, there must be a reference to the tool, e.g.:
The following types of inquiries should be marked as safe: (a) Password reset or (b) Login problems with the Android or Apple app. In these cases, invoke the
mark_answer_as_safetool.
Step 2: Mark Ticket in Tool as Automatically Executable
In the mark_answer_as_safe tool's code, the ticket is marked as automatically executable via the API, for example with the following code:
<?php
use EnneoSDK\ApiEnneo;
require(getenv()['SDK'] ?? 'sdk.php');
ApiEnneo::patch(
endpoint: '/api/mind/ticket/' . $in->ticketId,
body: [
'additionalData' => [
'markedAsSafe' => 'true'
]
]
);
echo json_encode(['success' => true]);import importlib.util
import os
import json
file_path = os.getenv('SDK', 'sdk.py')
spec = importlib.util.spec_from_file_location('sdk', file_path)
sdk = importlib.util.module_from_spec(spec)
spec.loader.exec_module(sdk)
in_data = sdk.load_input_data()
sdk.ApiEnneo.patch(
endpoint=f'/api/mind/ticket/{in_data["ticketId"]}',
body={
'additionalData': {
'markedAsSafe': 'true'
}
}
)
print(json.dumps({'success': True}))Step 3: Create Event Hook for TicketCreated
Under Settings -> System Integration -> Events, create a new Event Hook for the Event TicketCreated. This event is triggered after a new ticket has been received and the AI processing has been completed.
The customer-specific code checks whether the ticket has been marked as safe. If needed, additional checks can be performed, e.g. whether certain tags are set or the customer has been clearly identified.
If all criteria are met, the automatic execution is triggered:
POST /api/mind/ticket/:ticketId/autoexecute?executeAgentId=:aiAgentIdThe executeAgentId parameter is the numeric ID of the AI agent that should be executed. All other potentially recognized AI agents are ignored.
Info
This code example intentionally omits error handling to improve clarity.
<?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);
// Check if the ticket was marked as safe
$markedAsSafe = $ticket->additionalData->markedAsSafe ?? null;
if ($markedAsSafe !== 'true') {
echo json_encode(['autoExecute' => false, 'reason' => 'Not marked as safe']);
return;
}
// Optional: Additional checks, e.g. customer recognition or tags
// if (!$ticket->contractId) {
// echo json_encode(['autoExecute' => false, 'reason' => 'No contract recognized']);
// return;
// }
// ID of the AI agent to be executed
$aiAgentId = 123; // Adjust to the actual agent ID
// Trigger automatic execution
$result = ApiEnneo::post(
endpoint: '/api/mind/ticket/' . $in->ticketId . '/autoexecute?executeAgentId=' . $aiAgentId
);
echo json_encode(['autoExecute' => true, 'result' => $result]);import importlib.util
import os
import json
file_path = os.getenv('SDK', 'sdk.py')
spec = importlib.util.spec_from_file_location('sdk', file_path)
sdk = importlib.util.module_from_spec(spec)
spec.loader.exec_module(sdk)
# Load input parameters from the event
in_data = sdk.load_input_data()
# Load ticket data
ticket = sdk.ApiEnneo.get_ticket(in_data['ticketId'])
# Check if the ticket was marked as safe
marked_as_safe = ticket.get('additionalData', {}).get('markedAsSafe')
if marked_as_safe != 'true':
print(json.dumps({'autoExecute': False, 'reason': 'Not marked as safe'}))
exit()
# Optional: Additional checks, e.g. customer recognition or tags
# if not ticket.get('contractId'):
# print(json.dumps({'autoExecute': False, 'reason': 'No contract recognized'}))
# exit()
# ID of the AI agent to be executed
ai_agent_id = 123 # Adjust to the actual agent ID
# Trigger automatic execution
result = sdk.ApiEnneo.post(
endpoint=f'/api/mind/ticket/{in_data["ticketId"]}/autoexecute?executeAgentId={ai_agent_id}',
body={}
)
print(json.dumps({'autoExecute': True, 'result': result}))Step 4: Automatic Processing by Enneo
After calling the Autoexecute endpoint, Enneo automatically carries out the following steps:
- The answer created by the AI agent is sent to the customer.
- The ticket is closed.
- The ticket is marked as fully automated processing (L5).