Retrieving metrics¶
The Python API provides two ways to query metrics. Time-series queries return individual observations. Bucket queries combine values over time intervals, such as hours or days. Both read stored monitoring data; they do not start data collection.
In the following examples, client is an AgentManagementClient created as described in The main AgentManagementClient class.
Finding supported metrics¶
Metric availability depends on the selected agents and their configuration. First check which metric identifiers are available and which query methods support them.
agent = client.get_agent("production", "support-agent")
for metric in agent.get_available_metric_ids():
print(metric["id"], metric["supportsTimeSeries"], metric["supportsBuckets"])
# Union of supported metrics across all readable agents:
available = client.get_available_metric_ids()
A supported metric may have no stored observations yet. client.get_available_metric_ids(agent_filter=selection) and the equivalent platform method restrict discovery to a selection.
Retrieving time-series values¶
Use qualified identifiers such as reliability.uptime_test_status, performance.uptime_test_response_time_ms, and business-kpi.<id>. These have stored individual values. Activity counts, token totals, estimated costs, and aggregated latency metrics require bucket queries instead.
from datetime import datetime, timezone
series = agent.get_metric_time_series(
metrics=[
"reliability.uptime_test_status",
"performance.uptime_test_response_time_ms",
],
from_time=datetime(2026, 1, 1, tzinfo=timezone.utc),
to_time=datetime(2026, 1, 8, tzinfo=timezone.utc),
)
for group in series:
for row in group["rows"]:
print(dict(zip(group["columns"], row)))
Each group contains infrastructureName, agentId, columns, and chronological rows. timestamp values are Python datetimes with their timezone set to UTC. Metrics sharing a timeline are grouped together; each business KPI has its own series.
Retrieving the latest observations¶
latest = agent.get_metric_time_series(
metrics=["reliability.uptime_test_status"],
latest_only=True,
)
Omit both time bounds with latest_only=True. Otherwise from_time is required and to_time defaults to the current time. A latest-only query returns at most one row per series. It does not search separately for the latest non-null value of each metric.
Retrieving bucketed metrics for one agent¶
The following example combines activity, estimated cost, and average latency.
results = agent.get_metric_buckets(
metrics=[
"activity.interactions",
"consumption.cost.total",
"performance.interaction_latency_ms.avg",
],
bucket="DAY",
from_time=datetime(2026, 1, 1, tzinfo=timezone.utc),
to_time=datetime(2026, 1, 8, tzinfo=timezone.utc),
)
table = results.series()
for row in table["rows"]:
print(dict(zip(table["columns"], row)))
The unified table contains start, end, and the requested metrics in request order. Missing values are None. Use single_series(metric_id) for (start, end, value) tuples, or raw_data() to retain the original grouped response.
daily_cost = results.single_series("consumption.cost.total")
values = results.values_at_time(
datetime(2026, 1, 3, 12, tzinfo=timezone.utc)
)
print(values)
values_at_time() returns the values in the bucket containing the instant, or an empty dictionary when no bucket contains it.
Retrieving metrics for several agents¶
Use the client or platform method with an AgentFilter to retrieve metrics for several agents in one request.
from dataikuapi import AgentFilter
selection = (
AgentFilter()
.with_platform_ids("production")
.with_agent_ids("support-agent", "sales-agent")
.with_states(AgentFilter.STATE_MANAGED)
)
results = client.get_metric_buckets(
metrics=["activity.interactions", "reliability.uptime_pct"],
bucket="DAY",
agent_filter=selection,
from_time=datetime(2026, 1, 1, tzinfo=timezone.utc),
to_time=datetime(2026, 1, 8, tzinfo=timezone.utc),
)
for platform_id, agent_id in results.agents():
table = results.agent_series(platform_id, agent_id)
print(platform_id, agent_id, table)
The multi-agent result also provides agent_single_series(), agent_values_at_time(), and raw_agent_data(), each taking platform and agent IDs.
Conversation counts and statistics¶
activity.conversations counts distinct stored conversation identifiers for each agent within each time bucket. Statistics such as activity.interactions_per_conversation.avg group the interactions in the bucket by these identifiers.
Agent Management resolves conversation identifiers during ingestion and can assign a synthetic identifier when the source does not provide one. An interaction without a source-provided conversation identifier can therefore count as a separate conversation. These metrics do not necessarily correspond to business sessions defined by the source.
Older stored rows may still have missing or blank conversation identifiers. Such rows are excluded from conversation counts and statistics.
Query limits¶
Time-series and bucket queries have the following limits. Requests exceeding them are rejected.
Dimension |
Limit |
|---|---|
Agents |
At most 1,000 selected agents. |
Metrics |
From 1 to 100 distinct, non-empty metric identifiers per request. |
Time range |
At most 366 days, with |
For large inventories, query each platform in batches of at most 1,000 explicit agent IDs using
AgentFilter.with_platform_ids() and
with_agent_ids(). Split metric lists and time ranges into separate requests when necessary. The client does not paginate or split metric queries automatically.
Time bounds and metric units¶
Time bounds accept integer milliseconds since the Unix epoch or Python datetimes that include a timezone. The start time is included in the query; the end time is excluded. Bucket queries require from_time.
Buckets are HOUR, DAY, WEEK, or MONTH. Their boundaries use the global Agent Management timezone; weeks also use the configured first day of the week. The returned start and end datetimes use UTC.
Latency metrics use milliseconds, and percentages such as reliability.uptime_pct range from 0 to 100. Estimated costs use the configured cost currency. Missing observations do not represent zero. For statistics, request a suffix such as .avg or .percentile.95; platform-provided metrics use their published identifiers.
For the full list of metric identifiers and aggregation behavior, see get_metric_buckets().
Reference documentation¶
Classes¶
|
Bucketed metrics for multiple agents, retaining the original grouped series. |
|
Bucketed metrics for a single agent, with grouped and unified accessors. |
Agent filter accepted by search, metric retrieval and bulk action methods. |
Functions¶
|
Return a unified |
|
Return chronological |
|
Return all requested metric values in the bucket containing |
|
Return represented agents as |
|
Returns a handle to an agent. |
|
Lists the metric identifiers supported by readable agents matching the filter. |
Lists metric identifiers supported by this agent and their query compatibility. |
|
|
Lists the union of metric identifiers supported by readable agents in this platform. |
|
Returns bucketed metrics for the selected agents. |
|
Returns bucketed metrics for this agent. |
|
Returns stored, non-aggregated metric values for the selected agents. |
|
Returns stored time-series values for this agent. |
|
Return the original grouped dictionaries, including metadata and UTC-aware datetimes. |
|
Return the original grouped dictionaries, or an empty list if no agent data was returned. |
|
Return a unified |
|
Return |
|
Return values for |
|
|
|
|
|
