KPIs

KPIs add business measurements, such as customer satisfaction, to agent monitoring. A manual KPI reads values and their timestamps from a dataset. Several agents can use the same global KPI definition, with each agent reading values from its own dataset.

In the following examples, client is an AgentManagementClient created as described in The main AgentManagementClient class. Changing the dataset assigned to an agent KPI requires agent administration rights.

Adding a manual KPI to an agent

Prepare a dataset such as AGENTMONITORING.customer_satisfaction with a timestamp column of type date and a numeric value column. The caller must be able to use this dataset.

agent = client.get_agent("production", "support-agent")
settings = agent.get_settings()
settings.get_raw()["configuration"]["businessKPIs"].append({
    "origin": "INLINE",
    "id": "customer-satisfaction",
    "label": "Customer satisfaction",
    "description": "Customer satisfaction score",
    "type": "MANUAL",
    "valueType": "PERCENTAGE",
    "higherIsBetter": True,
    "datasetId": "AGENTMONITORING.customer_satisfaction",
})
settings.save()

KPI IDs must be non-empty and unique within the agent. Use AMOUNT instead of PERCENTAGE for an amount. Update an existing definition instead of adding another entry with the same ID. Type and origin cannot be changed after creation.

Defining a reusable global KPI

A global definition supplies shared metadata. Each agent still needs its own dataset assignment. Changing global settings requires instance administration rights.

settings = client.get_settings()
settings.get_raw()["businessKPIs"].append({
    "id": "customer-satisfaction",
    "label": "Customer satisfaction",
    "description": "Customer satisfaction score",
    "type": "MANUAL",
    "valueType": "PERCENTAGE",
    "higherIsBetter": True,
})
settings.save()

settings = agent.get_settings()
settings.get_raw()["configuration"]["businessKPIs"].append({
    "origin": "GLOBAL",
    "type": "MANUAL",
    "valueType": "PERCENTAGE",
    "referenceParams": {"globalKPIId": "customer-satisfaction"},
    "datasetId": "AGENTMONITORING.customer_satisfaction",
})
settings.save()

Choose either the agent-specific definition or the global definition for a given KPI ID. Do not assign both to the same agent with that ID.

Querying KPI values

The metric identifier is business-kpi.<id>. The following example reads the latest stored value.

latest = agent.get_metric_time_series(
    metrics=["business-kpi.customer-satisfaction"],
    latest_only=True,
)
print(latest)

KPI bucket queries use the latest dataset value within each bucket. For time ranges and methods to read the results, see Retrieving metrics. To alert when a KPI crosses a threshold, see Managing alert configurations.

Reference documentation

Classes

dataikuapi.agentmanagement.agent.AgentSettings(...)

The settings of a monitored agent.

dataikuapi.agentmanagement.settings.Settings(...)

The global Agent Management settings.

Functions

get_agent(platform_id, agent_id)

Returns a handle to an agent.

get_metric_time_series(metrics[, from_time, ...])

Returns stored time-series values for this agent.

get_raw()

Returns the raw settings of this agent.

get_raw()

Returns the raw Agent Management settings, including global business KPI definitions in businessKPIs.

get_settings()

Returns the global Agent Management settings.

get_settings()

Returns the settings of this agent.

save()

Saves the settings of this agent, checking fetchedRevision read by get_settings.

save([confirm_metric_reset])

Saves the global Agent Management settings.