11. Annex 2. AI Agent Code

The source code of this project is available in the ATOS GitLab repository. Examining the code you can see that 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.

jobs:
  # Orchestration configuration
  - name: atos-ai-agent
    image:
      repository: atosresearch/osm-ai-agent
      tag: latest
      imagePullPolicy: Always
    schedule: "* * * * *"
    failedJobsHistoryLimit: 2
    successfulJobsHistoryLimit: 2
    concurrencyPolicy: Allow
    restartPolicy: OnFailure
    config:
      executions:
        - active: True
          # AIAgents interfaces
          # AI Model Configuration
          model:
            endpoint: "http://192.168.137.46:8501/v1/models/CPU-forecast-model:predict"
          # Monitoring Service Configuration
          monitoring:
            endpoint: "http://192.168.137.34:4000"
          # Threshold evaluation Configuration
          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