Events & Webhooks
Example: Executing Smart AI Agents Automatically
Approach to automatically execute smart AI agents based on your own security criteria
Scenario
By default, Enneo only processes rule-based AI agents via dark processing for emails and letters, but not purely prompt-based ones. The reason for this is that the reliability of text purely generated by AI is less predictable than that of a rule value.
However, there are specific customer requests – e.g., password reset instructions or login problems with the Android or Apple app – which can be answered fully automatically with reasonable reliability. Instead of using the standard dark processing method, the smart AI agent itself should decide whether an answer is secure enough to be sent automatically.
Solution Approach
The approach consists of four steps: A user-defined AI tool marks safe responses, and an event hook checks the label and triggers automatic execution.
Step 1: Create User-defined 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 called by the smart AI agent when it is confident the response can be sent automatically.
In the prompt of the smart AI agent, reference should be made to the tool, e.g.:
The following types of requests should be marked as safe: (a) Reset password or (b) Login issues with Android or Apple app. Call the tool
mark_answer_as_safein these cases.
Step 2: Mark Ticket in the Tool as Automatically Executable
In the code of the mark_answer_as_safe tool, 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 -> Integration into systems -> 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 secure. If necessary, additional checks can be performed, e.g., whether certain tags are set or the customer has been clearly recognized.
If all criteria are met, the automatic execution is triggered:
POST /api/mind/ticket/:ticketId/autoexecute?executeAgentId=:aiAgentIdThe parameter executeAgentId is the numeric ID of the AI agent to be executed. Any other possibly recognized AI agents will be ignored.
Info
In this code example, error handling is deliberately avoided for clarity.
<?php
use EnneoSDK\ApiEnneo;
require(getenv()['SDK'] ?? 'sdk.php');
/** @var stdClass $in - contains all defined input parameters from the event */
// Loading ticket data
$ticket = ApiEnneo::getTicket($in->ticketId);
// Checking whether the ticket was marked as safe
$markedAsSafe = $ticket->additionalData->markedAsSafe ?? null;
if ($markedAsSafe !== 'true') {
echo json_encode(['autoExecute' => false, 'reason' => 'Not marked safe']);
return;
}
// Optional: Additional checks, e.g., for 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)
# Loading input parameters from the event
in_data = sdk.load_input_data()
# Loading ticket data
ticket = sdk.ApiEnneo.get_ticket(in_data['ticketId'])
# Checking whether 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 safe'}))
exit()
# Optional: Additional checks, e.g., for 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 executes 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 (L5).