Business Logic Samples
API-based Agents
Outsource and extend business logic flexibly
Tip
API-based agents enable the outsourcing of complex business logic to external services. They combine the power of AI agents with the flexibility of external APIs to automate demanding processes and seamlessly integrate existing systems. These agents are ideal for scenarios requiring specialized calculations, access to external data sources, or integration with existing microservices.
API-based agents form the bridge between the Enneo platform and your custom IT landscape. They allow for the entire business logic to be outsourced to external services while retaining full control over data flows and processing steps. Standardized communication via HTTP enables any systems to be connected – from internal microservices to external SaaS solutions.
Unlike rule-based agents, whose logic is directly implemented in Enneo, API-based agents focus on a clear separation between the Enneo platform and the actual business logic. This not only allows for higher scalability and better maintainability, but also enables the reuse of existing services and infrastructures.
<?php
use EnneoSDK\Api;
use EnneoSDK\IntentInfo;
use EnneoSDK\IntentOption;
use EnneoSDK\Interaction;
require(getenv()['SDK'] ?? 'sdk.php');
/** @var stdClass $in */
// Create a mocked API response:
//{
// "data": {
// "_action": null
// },
// "options": [
// {
// "type": "success",
// "name": "Ok",
// "icon": "check",
// "recommended": true,
// "order": 0,
// "handler": ""
// }
// ],
// "infos": [
// {
// "type": "success",
// "message": "API-Aufruf erfolgreich",
// "extraInfo": null,
// "code": null
// }
// ]
//}
$interaction = new Interaction($in);
$interaction->infos[] = new IntentInfo(
type: 'success',
message: 'API-Aufruf erfolgreich'
);
$interaction->options[] = new IntentOption(
type: 'success',
name: 'Ok',
recommended: true
);
// TODO: replace this "echo" API call by your own API call. Use ApiEnneo::executeUdf to use custom code.
// E.g.:
//ApiEnneo::executeUdf(
// 'customApiCall',
// [
// "method" => "POST",
// "api" => sprintf('contract/%s/anyApi', $in->_metadata->inputParameters->contractId),
// "params" => (array) $in
// ]
//);
$response = Api::call(
method: 'POST',
url: 'https://echo.enneo.ai',// echo.enneo.ai
params: json_decode(json_encode($interaction), true)
);
$result = $response;
echo json_encode($result);
exit();
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)
# Create a mocked API response:
# {
# "data": {
# "_action": null
# },
# "options": [
# {
# "type": "success",
# "name": "Ok",
# "icon": "check",
# "recommended": true,
# "order": 0,
# "handler": ""
# }
# ],
# "infos": [
# {
# "type": "success",
# "message": "API-Aufruf erfolgreich",
# "extraInfo": null,
# "code": null
# }
# ]
# }
input_data = sdk.load_input_data()
interaction = sdk.Interaction(data=input_data)
interaction.infos.append(
sdk.IntentInfo(
type='success',
message='API-Aufruf erfolgreich'
)
)
interaction.options.append(
sdk.IntentOption(
type='success',
name='Ok',
recommended=True
)
)
# TODO: replace this "echo" API call by your own API call. Use ApiEnneo::executeUdf to use custom code.
# E.g.:
# sdk.ApiEnneo.executeUdf(
# 'customApiCall',
# {
# "method": "POST",
# "api": f'contract/{input_data["contractId"]}/anyApi',
# "params": input_data
# }
# )
response = sdk.Api.call(
method='POST',
url='https://echo.enneo.ai', # echo.enneo.ai
params=json.loads(json.dumps(interaction.model_dump()))
)
result = response
print(json.dumps(result))