Business Logic Samples
API-based Agents
Outsource and expand Business Logic flexibly
Tip
API-based agents facilitate the outsourcing of complex business logic to external services. They merge the power of AI agents with the flexibility of external APIs to automate intricate processes and flawlessly 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 bridge the gap between the Enneo platform and your individual 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. By communicating standardly over HTTP, any system can be connected to - from internal microservices to external SaaS applications.
In contrast to rule-based agents, whose logic is implemented directly in Enneo, API-based agents rely on a clear distinction between the Enneo platform and actual business logic. This not only allows for greater scalability and better maintainability but also the reusability 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))