11. Annex 2. AI Agent Code¶
In the AI Agents for OSM functionality, AI Agents are built using the same approach as the configuration file used to run them. There is an orchestrator and a set of interfaces that implement each section of the configuration file.
config:
executions:
- active: True
model:
endpoint: "http://192.168.137.46:8501/v1/models/CPU-forecast-model:predict"
monitoring:
endpoint: "http://192.168.137.34:4000"
threshold:
function_name: evaluator
logic: "evaluator = lambda x: True if x['predictions'][0][0] >= 0.8 else False"
11.1. AI Agent Orchestrator¶
-
class
aiagent.agent.
AIAgent
¶ -
__init__
()¶ Orchestrator that executes proactive scaling for a VNF in a scheduled job running inside the EE of OSM
-
request_scale_action
(operational_data, ai_result)¶ Final action that the AIAgent triggers. Currently supporting Scaling action
- Parameters
ai_result (bool) – Result from the evaluation of the threshold with the output of the AI Model
operational_data (dict) – Relevant information obtained from OSM
-
run
()¶ Main method that executes a single sequence of the AIAgent workflow. Extract monitoring metrics –> feed metrics to AI Model –> evaluate AI Model output with threshold
-
11.2. Interfaces¶
Model Interface¶
-
class
aiagent.interfaces.model_interface.
ModelInterface
(model_d)¶ -
__init__
(model_d)¶ Interface for the parameterization, configuration and request to the AI Model server.
- Parameters
model_d (dict) – dictionary of the selected model, in which you can find the endpoint of the model you will work with
-
ai_evaluation
(model_input)¶ AI evaluation Requests the forecast from the AI Server and stores it in the forecast data
- Parameters
model_input (dict) – metrics data to feed to AI Model
Returns (dict): Returns the requested data from the execution of the AI Model
-
get_health
()¶ Check that the AI Model Server is accessible.
-
Monitoring Interface¶
-
class
aiagent.interfaces.monitoring_interface.
MonitoringInterface
(monitoring_d, operational_data)¶ -
__init__
(monitoring_d, operational_data)¶ Interface to extract monitoring metrics that will be fed to an AI Model
- Parameters
monitoring_d (dict) – dictionary from which the endpoint is obtained
operational_data (dict) – Relevant information obtained from OSM
-
get_metrics
()¶ Exposed method to request monitoring metrics from the configured endpoint
- Returns (dict):
metrics {‘instances’: metrics_l}
-
Threshold Interface¶
-
class
aiagent.interfaces.threshold_interface.
ThresholdInterface
(threshold_d)¶ -
__init__
(threshold_d)¶ Class in charge of evaluating the AI Result from a AI Model using a user defined threshold.
- Parameters
threshold_d (dict) – Configuration dict extracted from the AI Agent values.yml
-
ai_threshold
(forecast_data)¶ AI Forecast evaluates Forecast Data by the threshold defined in helm charm
- Parameters
forecast_data (dict) – data of the chosen model
Returns (bool): Evaluation of the threshold defined
-