ioc-scope-api 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ioc_scope_api-1.0.0.dist-info/METADATA +306 -0
- ioc_scope_api-1.0.0.dist-info/RECORD +106 -0
- ioc_scope_api-1.0.0.dist-info/WHEEL +4 -0
- ioc_scope_api-1.0.0.dist-info/entry_points.txt +2 -0
- scope/__init__.py +27 -0
- scope/api/__init__.py +119 -0
- scope/api/api_v1/__init__.py +2 -0
- scope/api/api_v1/api.py +71 -0
- scope/api/api_v1/endpoints/__init__.py +2 -0
- scope/api/api_v1/endpoints/agentic_protocols_metrics.py +39 -0
- scope/api/api_v1/endpoints/applications.py +440 -0
- scope/api/api_v1/endpoints/cache.py +50 -0
- scope/api/api_v1/endpoints/concepts.py +123 -0
- scope/api/api_v1/endpoints/features.py +19 -0
- scope/api/api_v1/endpoints/helpers.py +65 -0
- scope/api/api_v1/endpoints/kg.py +195 -0
- scope/api/api_v1/endpoints/labels.py +71 -0
- scope/api/api_v1/endpoints/live_topology.py +89 -0
- scope/api/api_v1/endpoints/metrics.py +1014 -0
- scope/api/api_v1/endpoints/reasoning.py +62 -0
- scope/api/api_v1/endpoints/semanticgroups.py +144 -0
- scope/api/api_v1/endpoints/sessions.py +339 -0
- scope/api/api_v1/endpoints/spans.py +41 -0
- scope/api/api_v1/endpoints/symbolic.py +186 -0
- scope/api/api_v1/endpoints/ui.py +145 -0
- scope/api/api_v1/endpoints/waste_estimation.py +182 -0
- scope/api/api_v2/__init__.py +3 -0
- scope/api/api_v2/api.py +23 -0
- scope/api/api_v2/endpoints/__init__.py +3 -0
- scope/api/api_v2/endpoints/metrics.py +193 -0
- scope/app.py +30 -0
- scope/cache.py +64 -0
- scope/client/__init__.py +27 -0
- scope/client/_concepts.py +137 -0
- scope/client/_kg.py +64 -0
- scope/client/_labels.py +86 -0
- scope/client/_live_topology.py +912 -0
- scope/client/_metrics.py +561 -0
- scope/client/_semanticgroups.py +166 -0
- scope/client/_sessions.py +168 -0
- scope/client/_symbolic.py +1354 -0
- scope/client/_ui.py +599 -0
- scope/client/agentic_protocols.py +289 -0
- scope/client/application_charts.py +1786 -0
- scope/client/applications.py +2246 -0
- scope/client/base.py +49 -0
- scope/client/cognition_protocols.py +302 -0
- scope/client/constants.py +81 -0
- scope/client/dal.py +2382 -0
- scope/client/failures.py +70 -0
- scope/client/local.py +161 -0
- scope/client/mock/__init__.py +7 -0
- scope/client/mock/client.py +1034 -0
- scope/client/sessions.py +1688 -0
- scope/client/spans.py +95 -0
- scope/client/utils.py +392 -0
- scope/connectors/__init__.py +13 -0
- scope/connectors/base.py +52 -0
- scope/connectors/clickhouse.py +105 -0
- scope/connectors/neo4j.py +220 -0
- scope/connectors/sqlalchemy.py +131 -0
- scope/core/config.py +530 -0
- scope/core/exceptions.py +64 -0
- scope/dependencies.py +164 -0
- scope/health.py +10 -0
- scope/interfaces/__init__.py +33 -0
- scope/interfaces/data_provider.py +61 -0
- scope/interfaces/integration_example.py +310 -0
- scope/interfaces/kg_provider.py +91 -0
- scope/interfaces/metrics_provider.py +92 -0
- scope/interfaces/models.py +185 -0
- scope/models/kg.py +48 -0
- scope/models/live_topology.py +78 -0
- scope/models/otel_traces.py +1595 -0
- scope/providers/__init__.py +277 -0
- scope/providers/_graph.py +59 -0
- scope/providers/cognition_protocols.py +178 -0
- scope/providers/kg.py +702 -0
- scope/providers/kg_query_runner.py +109 -0
- scope/providers/neo4j_mce.py +18 -0
- scope/providers/scope_metrics.py +7 -0
- scope/query_builders/__init__.py +14 -0
- scope/query_builders/cognition_protocol_graph.py +191 -0
- scope/query_builders/concepts.py +112 -0
- scope/query_builders/dal.py +931 -0
- scope/query_builders/failure_graph.py +102 -0
- scope/query_builders/features.py +5 -0
- scope/query_builders/kg.py +416 -0
- scope/query_builders/labels.py +53 -0
- scope/query_builders/live_topology.py +503 -0
- scope/query_builders/metric_graph.py +196 -0
- scope/query_builders/metrics.py +354 -0
- scope/query_builders/semanticgroups.py +46 -0
- scope/query_builders/sessions.py +208 -0
- scope/query_builders/symbolic.py +615 -0
- scope/query_builders/trajectory.py +76 -0
- scope/query_builders/types.py +20 -0
- scope/query_builders/ui.py +3278 -0
- scope/query_builders/waste_estimation.py +221 -0
- scope/repositories/__init__.py +28 -0
- scope/repositories/clickhouse_otel_repository.py +135 -0
- scope/repositories/otel_repository.py +97 -0
- scope/repositories/sqlite_repository.py +215 -0
- scope/scripts/__init__.py +2 -0
- scope/scripts/seed.py +35 -0
- scope/workarounds.py +38 -0
scope/client/base.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Abstract base client for the SCOPE API.
|
|
4
|
+
|
|
5
|
+
``SCOPEAPIClient`` is the single type that consumers depend on.
|
|
6
|
+
Concrete back-ends (:class:`LocalClient`, a future ``RemoteClient``, …)
|
|
7
|
+
inherit from this class and implement the abstract methods.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from abc import ABC, abstractmethod
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SCOPEAPIClient(ABC):
|
|
17
|
+
"""Base class for all SCOPE API clients.
|
|
18
|
+
|
|
19
|
+
Concrete back-ends implement the abstract methods below. Callers
|
|
20
|
+
can also use the context-manager protocol::
|
|
21
|
+
|
|
22
|
+
with LocalClient() as client:
|
|
23
|
+
sessions = client.get_sessions(app_name="my-app")
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
# ── lifecycle ─────────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
def close(self) -> None: # noqa: B027 — intentionally empty
|
|
29
|
+
"""Release resources held by this client. Override if needed."""
|
|
30
|
+
|
|
31
|
+
def __enter__(self):
|
|
32
|
+
return self
|
|
33
|
+
|
|
34
|
+
def __exit__(self, *exc: Any) -> None:
|
|
35
|
+
self.close()
|
|
36
|
+
|
|
37
|
+
# ── common ────────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
@abstractmethod
|
|
40
|
+
def info(self, domain: str = "scope") -> str:
|
|
41
|
+
"""Return a human-readable greeting for *domain*."""
|
|
42
|
+
|
|
43
|
+
# ── UI operations ─────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
# ── KG operations ─────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
# ── Metric operations ─────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
# ── Feature operations ────────────────────────────────────────────────
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"""Cognition protocol implementations for :class:`UIClient`.
|
|
2
|
+
|
|
3
|
+
Cognition protocols are stored in the KG as (see ``scope.query_builders.cognition_protocol_graph``):
|
|
4
|
+
|
|
5
|
+
* one ``CognitionProtocolReport`` per session, listing the protocols enabled and those activated;
|
|
6
|
+
* one ``CognitionProtocolExecutionReport`` per activated protocol and session: the agents and skills
|
|
7
|
+
that had / used the protocol, plus the protocol's evaluation metrics, stored as
|
|
8
|
+
``MetricResult`` nodes that measure the report.
|
|
9
|
+
|
|
10
|
+
The API returns the metrics as a generic list, so that a new protocol or metric needs no API
|
|
11
|
+
change. A name-to-section map only groups the metrics for display.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import logging
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from scope.client.applications import (
|
|
21
|
+
_build_cognitive_failures,
|
|
22
|
+
_build_cognitive_metrics,
|
|
23
|
+
_build_session_metrics_single_query,
|
|
24
|
+
)
|
|
25
|
+
from scope.client.constants import TASK_STATUS_DONE
|
|
26
|
+
from scope.client.utils import parse_epoch_range
|
|
27
|
+
from scope.connectors.base import Connector
|
|
28
|
+
from scope.core.exceptions import DatabaseError, NotFoundError
|
|
29
|
+
from scope.models.otel_traces import (
|
|
30
|
+
SessionCognitionProtocolsResponse,
|
|
31
|
+
SessionsWithCognitionProtocolsResponse,
|
|
32
|
+
SessionWithCognitionProtocolsItem,
|
|
33
|
+
)
|
|
34
|
+
from scope.query_builders import ui as ui_queries
|
|
35
|
+
from scope.query_builders.types import Dialect
|
|
36
|
+
|
|
37
|
+
logger = logging.getLogger(__name__)
|
|
38
|
+
|
|
39
|
+
# Section of the metrics that are not listed.
|
|
40
|
+
_OTHER_SECTION = "other"
|
|
41
|
+
|
|
42
|
+
# Section of each metric, by name. Extensible: an unlisted metric goes to ``other``.
|
|
43
|
+
_METRIC_SECTIONS = {
|
|
44
|
+
# Convergence and quality of the lock.
|
|
45
|
+
"AccordConverged": "convergence",
|
|
46
|
+
"AccordPhaseCoverage": "convergence",
|
|
47
|
+
"AccordLockedTerms": "convergence",
|
|
48
|
+
"AccordLockPrecision": "convergence",
|
|
49
|
+
"AccordLockRecall": "convergence",
|
|
50
|
+
"AccordFabricatedLock": "convergence",
|
|
51
|
+
"AccordOverSelected": "convergence",
|
|
52
|
+
"AccordUnderSelected": "convergence",
|
|
53
|
+
"AccordTermUtilization": "convergence",
|
|
54
|
+
# Validity of the intent contract.
|
|
55
|
+
"AccordCanonicalValid": "contract",
|
|
56
|
+
"AccordRelayedValid": "contract",
|
|
57
|
+
"AccordContractWarnings": "contract",
|
|
58
|
+
# Token cost of the protocol.
|
|
59
|
+
"AccordProtocolPromptTokens": "cost",
|
|
60
|
+
"AccordProtocolFreshTokens": "cost",
|
|
61
|
+
"AccordProtocolCachedTokens": "cost",
|
|
62
|
+
"AccordProtocolCompletionTokens": "cost",
|
|
63
|
+
"AccordContractOverheadTokens": "cost",
|
|
64
|
+
"AccordContractOverheadShare": "cost",
|
|
65
|
+
"AccordContractOverheadPerCall": "cost",
|
|
66
|
+
# What the protocol brings to the agents.
|
|
67
|
+
"AccordGlossaryInfluence": "benefits",
|
|
68
|
+
"AccordGlossaryUptake": "benefits",
|
|
69
|
+
# CONCORD: did the run reach a commit, following the protocol.
|
|
70
|
+
"ConcordCommitted": "convergence",
|
|
71
|
+
"ConcordReachedEnd": "convergence",
|
|
72
|
+
"ConcordAllSteps": "convergence",
|
|
73
|
+
"ConcordUsedAllCandidates": "convergence",
|
|
74
|
+
"ConcordRounds": "convergence",
|
|
75
|
+
"ConcordRepairRounds": "convergence",
|
|
76
|
+
"ConcordRepairsAfterMarkMissing": "convergence",
|
|
77
|
+
"ConcordBudgetUsed": "convergence",
|
|
78
|
+
# CONCORD: how satisfied and fairly treated the agents are.
|
|
79
|
+
"ConcordWorstOffSatisfaction": "benefits",
|
|
80
|
+
"ConcordWorstOffAboveTau": "benefits",
|
|
81
|
+
"ConcordMeanSatisfaction": "benefits",
|
|
82
|
+
"ConcordSatisfiedAgents": "benefits",
|
|
83
|
+
"ConcordOutcomeSatisfied": "benefits",
|
|
84
|
+
"ConcordScoreFair": "benefits",
|
|
85
|
+
"ConcordUnfairScoreShare": "benefits",
|
|
86
|
+
"ConcordSelfPreferenceGap": "benefits",
|
|
87
|
+
# CONCORD: token cost of the run and of each phase.
|
|
88
|
+
"ConcordRunTokens": "cost",
|
|
89
|
+
"ConcordProtocolTokens": "cost",
|
|
90
|
+
"ConcordProtocolShare": "cost",
|
|
91
|
+
"ConcordTokensBeforeConcord": "cost",
|
|
92
|
+
"ConcordTokensAnchors": "cost",
|
|
93
|
+
"ConcordTokensSeeds": "cost",
|
|
94
|
+
"ConcordTokensScores": "cost",
|
|
95
|
+
"ConcordTokensRepair": "cost",
|
|
96
|
+
"ConcordTokensAfterCommit": "cost",
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _normalize_protocol(name: object) -> str:
|
|
101
|
+
"""``accord`` / ``COGNITION_ACCORD`` / ``L9-ACCORD`` -> ``ACCORD``."""
|
|
102
|
+
text = str(name).strip().upper().replace("_", "-").replace(" ", "-")
|
|
103
|
+
for prefix in ("L9-", "COGNITION-"):
|
|
104
|
+
text = text.removeprefix(prefix)
|
|
105
|
+
return text
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _names(raw: object) -> set[str]:
|
|
109
|
+
"""Normalized protocol names of a list property."""
|
|
110
|
+
if not isinstance(raw, (list, tuple, set)):
|
|
111
|
+
return set()
|
|
112
|
+
return {_normalize_protocol(n) for n in raw if n}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _protocol_statuses(
|
|
116
|
+
cognition_protocol_reports: object,
|
|
117
|
+
) -> dict[str, dict[str, bool]]:
|
|
118
|
+
"""``{protocol: {enabled, activated}}`` from the session's ``CognitionProtocolReport`` (latest wins)."""
|
|
119
|
+
reports = [r for r in (cognition_protocol_reports or []) if isinstance(r, dict)]
|
|
120
|
+
reports.sort(key=lambda r: str(r.get("reportedAt") or ""))
|
|
121
|
+
statuses: dict[str, dict[str, bool]] = {}
|
|
122
|
+
for report in reports:
|
|
123
|
+
enabled = _names(report.get("protocolsEnabled"))
|
|
124
|
+
activated = _names(report.get("protocolsActivated"))
|
|
125
|
+
statuses = {
|
|
126
|
+
name: {
|
|
127
|
+
"enabled": name in enabled or name in activated,
|
|
128
|
+
"activated": name in activated,
|
|
129
|
+
}
|
|
130
|
+
for name in sorted(enabled | activated)
|
|
131
|
+
}
|
|
132
|
+
return statuses
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _parse_json_container(raw: str) -> dict[str, Any] | list[Any] | None:
|
|
136
|
+
"""The JSON object or array in *raw*, None if it is anything else."""
|
|
137
|
+
try:
|
|
138
|
+
parsed = json.loads(raw)
|
|
139
|
+
except json.JSONDecodeError:
|
|
140
|
+
return None
|
|
141
|
+
return parsed if isinstance(parsed, (dict, list)) else None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _split_reasoning(reasoning: str) -> tuple[str, dict[str, Any] | list[Any] | None]:
|
|
145
|
+
"""Split a reasoning into its text and its structured part.
|
|
146
|
+
|
|
147
|
+
The reasoning is free text, a JSON document, or a text followed by one
|
|
148
|
+
(``"FAIR; {...}"``).
|
|
149
|
+
"""
|
|
150
|
+
whole = _parse_json_container(reasoning)
|
|
151
|
+
if whole is not None:
|
|
152
|
+
return "", whole
|
|
153
|
+
head, sep, tail = reasoning.partition("; ")
|
|
154
|
+
parsed = _parse_json_container(tail) if sep else None
|
|
155
|
+
if parsed is not None:
|
|
156
|
+
return head.strip(), parsed
|
|
157
|
+
return reasoning, None
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _build_metric(raw: dict[str, Any]) -> dict[str, Any] | None:
|
|
161
|
+
"""Map one ``MetricResult`` row to a UI metric.
|
|
162
|
+
|
|
163
|
+
``reasoning`` is the text explaining the value; the structured data some metrics add to
|
|
164
|
+
it (a JSON document) is returned parsed as ``details``.
|
|
165
|
+
"""
|
|
166
|
+
name = raw.get("name")
|
|
167
|
+
if not name:
|
|
168
|
+
return None
|
|
169
|
+
metric: dict[str, Any] = {
|
|
170
|
+
"name": str(name),
|
|
171
|
+
"section": _METRIC_SECTIONS.get(str(name), _OTHER_SECTION),
|
|
172
|
+
"value": raw.get("result"),
|
|
173
|
+
}
|
|
174
|
+
for key in ("provider", "unit", "timestamp"):
|
|
175
|
+
if raw.get(key):
|
|
176
|
+
metric[key] = str(raw[key])
|
|
177
|
+
reasoning = raw.get("reasoning")
|
|
178
|
+
if isinstance(reasoning, str) and reasoning.strip():
|
|
179
|
+
text, details = _split_reasoning(reasoning)
|
|
180
|
+
if details is not None:
|
|
181
|
+
metric["details"] = details
|
|
182
|
+
if text:
|
|
183
|
+
metric["reasoning"] = text
|
|
184
|
+
return metric
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _build_protocols(
|
|
188
|
+
cognition_protocol_reports: object, execution_reports: object
|
|
189
|
+
) -> list[dict[str, Any]]:
|
|
190
|
+
"""One protocol per name, sorted by name: its status and, if executed, its report."""
|
|
191
|
+
protocols = {
|
|
192
|
+
name: {"protocol": name, **status}
|
|
193
|
+
for name, status in _protocol_statuses(cognition_protocol_reports).items()
|
|
194
|
+
}
|
|
195
|
+
for item in execution_reports or []:
|
|
196
|
+
report = item.get("report") if isinstance(item, dict) else None
|
|
197
|
+
if not isinstance(report, dict) or not (
|
|
198
|
+
report.get("protocol") or report.get("name")
|
|
199
|
+
):
|
|
200
|
+
continue
|
|
201
|
+
name = _normalize_protocol(report.get("protocol") or report.get("name"))
|
|
202
|
+
# A protocol with an execution report ran, even if the CognitionProtocolReport is missing.
|
|
203
|
+
protocol = protocols.setdefault(
|
|
204
|
+
name, {"protocol": name, "enabled": True, "activated": True}
|
|
205
|
+
)
|
|
206
|
+
for key in (
|
|
207
|
+
"enabledEvidence",
|
|
208
|
+
"skillsEnabled",
|
|
209
|
+
"skillsActivated",
|
|
210
|
+
"agentsEnabled",
|
|
211
|
+
"agentsActivated",
|
|
212
|
+
"reportedAt",
|
|
213
|
+
):
|
|
214
|
+
if report.get(key) not in (None, "", []):
|
|
215
|
+
protocol[key] = (
|
|
216
|
+
str(report[key])
|
|
217
|
+
if key in {"enabledEvidence", "reportedAt"}
|
|
218
|
+
else report[key]
|
|
219
|
+
)
|
|
220
|
+
metrics = (_build_metric(m) for m in item.get("metrics") or [])
|
|
221
|
+
protocol["metrics"] = sorted(
|
|
222
|
+
(m for m in metrics if m), key=lambda m: (m["section"], m["name"])
|
|
223
|
+
)
|
|
224
|
+
return [protocols[n] for n in sorted(protocols)]
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _get_session_cognition_protocols(
|
|
228
|
+
db: Connector, dialect: Dialect, *, session_id: str
|
|
229
|
+
) -> SessionCognitionProtocolsResponse:
|
|
230
|
+
"""Return the Cognition protocols (with their metrics) of one session."""
|
|
231
|
+
del dialect # Neo4j-only query.
|
|
232
|
+
query, params = ui_queries.neo4j_session_cognition_protocol_reports_query(
|
|
233
|
+
session_id=session_id
|
|
234
|
+
)
|
|
235
|
+
try:
|
|
236
|
+
rows = db.execute(query, params)
|
|
237
|
+
except Exception as exc:
|
|
238
|
+
raise DatabaseError(
|
|
239
|
+
f"Failed to get Cognition protocols for session '{session_id}': {exc}"
|
|
240
|
+
) from exc
|
|
241
|
+
|
|
242
|
+
row = rows[0] if rows else {}
|
|
243
|
+
if not row.get("found"):
|
|
244
|
+
raise NotFoundError(f"Session '{session_id}' not found.")
|
|
245
|
+
return SessionCognitionProtocolsResponse(
|
|
246
|
+
sessionId=session_id,
|
|
247
|
+
protocols=_build_protocols(
|
|
248
|
+
row.get("cognitionProtocolReports"), row.get("executionReports")
|
|
249
|
+
),
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _get_application_sessions_with_cognition_protocols(
|
|
254
|
+
db: Connector,
|
|
255
|
+
dialect: Dialect,
|
|
256
|
+
*,
|
|
257
|
+
application_id: str,
|
|
258
|
+
start_time: str = "",
|
|
259
|
+
end_time: str = "",
|
|
260
|
+
) -> SessionsWithCognitionProtocolsResponse:
|
|
261
|
+
"""Return the sessions of an application with their Cognition protocol status."""
|
|
262
|
+
del dialect # Neo4j-only query.
|
|
263
|
+
start_epoch, end_epoch = parse_epoch_range(start_time, end_time)
|
|
264
|
+
if start_epoch > end_epoch:
|
|
265
|
+
raise ValueError("invalid time range")
|
|
266
|
+
|
|
267
|
+
query, params = ui_queries.neo4j_sessions_with_cognitive_observability_query(
|
|
268
|
+
application_id=application_id, start_epoch=start_epoch, end_epoch=end_epoch
|
|
269
|
+
)
|
|
270
|
+
try:
|
|
271
|
+
rows = db.execute(query, params)
|
|
272
|
+
except Exception as exc:
|
|
273
|
+
raise DatabaseError(
|
|
274
|
+
f"Failed to get Cognition protocols for '{application_id}': {exc}"
|
|
275
|
+
) from exc
|
|
276
|
+
|
|
277
|
+
sessions: list[SessionWithCognitionProtocolsItem] = []
|
|
278
|
+
for row in rows or []:
|
|
279
|
+
statuses = _protocol_statuses(row.get("cognitionProtocolReports"))
|
|
280
|
+
sessions.append(
|
|
281
|
+
SessionWithCognitionProtocolsItem(
|
|
282
|
+
sessionId=str(row["sessionId"]),
|
|
283
|
+
timestamp=str(row["startTime"]),
|
|
284
|
+
agents=row.get("agents") or [],
|
|
285
|
+
llms=[],
|
|
286
|
+
tokens=row.get("tokens") or 0,
|
|
287
|
+
status=TASK_STATUS_DONE,
|
|
288
|
+
cost=row.get("cost") or 0.0,
|
|
289
|
+
duration=row.get("duration") or 0.0,
|
|
290
|
+
session_metrics=_build_session_metrics_single_query(
|
|
291
|
+
row.get("sessionMetrics")
|
|
292
|
+
),
|
|
293
|
+
cognitionProtocols=[
|
|
294
|
+
{"protocol": n, **st} for n, st in statuses.items()
|
|
295
|
+
],
|
|
296
|
+
cognitiveObservabilityMetrics=_build_cognitive_metrics(
|
|
297
|
+
row.get("sessionMetrics")
|
|
298
|
+
),
|
|
299
|
+
cognitiveFailures=_build_cognitive_failures(row.get("failures")),
|
|
300
|
+
)
|
|
301
|
+
)
|
|
302
|
+
return SessionsWithCognitionProtocolsResponse(sessions=sessions)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Shared constants for the client layer."""
|
|
4
|
+
|
|
5
|
+
# ── Span-detail constants ────────────────────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
SPAN_TYPE_CHAT = "chat"
|
|
8
|
+
SPAN_TYPE_AGENT = "agent"
|
|
9
|
+
SPAN_TYPE_TOOL = "tool"
|
|
10
|
+
|
|
11
|
+
PROMPT_ROLE = "gen_ai.prompt.{}.role"
|
|
12
|
+
PROMPT_CONTENT = "gen_ai.prompt.{}.content"
|
|
13
|
+
COMPLETION_ROLE = "gen_ai.completion.{}.role"
|
|
14
|
+
COMPLETION_CONTENT = "gen_ai.completion.{}.content"
|
|
15
|
+
|
|
16
|
+
INPUT_TOKENS_KEY = "gen_ai.usage.input_tokens"
|
|
17
|
+
OUTPUT_TOKENS_KEY = "gen_ai.usage.output_tokens"
|
|
18
|
+
LLM_USAGE_TOTAL_TOKENS = "llm.usage.total_tokens"
|
|
19
|
+
|
|
20
|
+
COST_PER_TOKEN = 2.5e-6 # dollars per token
|
|
21
|
+
|
|
22
|
+
KEY_INPUT_TOKENS = "Input Tokens"
|
|
23
|
+
KEY_INPUT_COST = "Input Cost"
|
|
24
|
+
KEY_OUTPUT_TOKENS = "Output Tokens"
|
|
25
|
+
KEY_OUTPUT_COST = "Output Cost"
|
|
26
|
+
KEY_TOTAL_TOKENS = "Total Tokens"
|
|
27
|
+
KEY_TOTAL_COST = "Total Cost"
|
|
28
|
+
|
|
29
|
+
SCOPE_NAME_TRACER = "ioa.observe.tracer"
|
|
30
|
+
ENTITY_INPUT = "ioa_observe.entity.input"
|
|
31
|
+
ENTITY_OUTPUT = "ioa_observe.entity.output"
|
|
32
|
+
|
|
33
|
+
TRACELOOP_INPUT = "traceloop.entity.input"
|
|
34
|
+
TRACELOOP_OUTPUT = "traceloop.entity.output"
|
|
35
|
+
|
|
36
|
+
CHAT_INPUT = "chat.input"
|
|
37
|
+
CHAT_OUTPUT = "chat.output"
|
|
38
|
+
|
|
39
|
+
INIT_RUN = "__init_run"
|
|
40
|
+
|
|
41
|
+
ERROR_STATUS = "Error"
|
|
42
|
+
EXCEPTION_MESSAGE = "exception.message"
|
|
43
|
+
|
|
44
|
+
# Number of time periods for monitor application level timeline
|
|
45
|
+
PERIODS_COUNT = 12
|
|
46
|
+
|
|
47
|
+
# Status constants for monitor tasks
|
|
48
|
+
TASK_STATUS_DONE = "done"
|
|
49
|
+
|
|
50
|
+
# Separator constants for agent name display
|
|
51
|
+
DASH_SEPARATOR = "-"
|
|
52
|
+
SPACE_SEPARATOR = " "
|
|
53
|
+
|
|
54
|
+
# ── Derived-metrics metric names ─────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
WORKFLOW_EFFICIENCY = "WorkflowEfficiency"
|
|
57
|
+
APP_GROUNDEDNESS = "GroundednessMetric"
|
|
58
|
+
ANSWER_RELEVANCY = "AnswerRelevancyMetric"
|
|
59
|
+
RESPONSE_COMPLETENESS = "ResponseCompleteness"
|
|
60
|
+
TOOL_UTILIZATION_ACCURACY = "ToolUtilizationAccuracy"
|
|
61
|
+
|
|
62
|
+
# Passive eval SDK metric name
|
|
63
|
+
PASSIVE_EVAL_APP_METRIC = "PassiveEvalApp"
|
|
64
|
+
APP_LLM_COST = "eval.app.llm_cost"
|
|
65
|
+
SESSION_DURATION = "eval.app.duration"
|
|
66
|
+
APP_LLM_CALLS = "eval.app.llm_calls"
|
|
67
|
+
APP_TOOL_CALLS = "eval.app.tool_calls"
|
|
68
|
+
APP_LLM_FAILS = "eval.app.llm_fails"
|
|
69
|
+
APP_TOOL_FAILS = "eval.app.tool_fails"
|
|
70
|
+
APP_GRAPH_DETERMINISM = "eval.app.graph_determinism"
|
|
71
|
+
APP_GRAPH_DYNAMISM = "eval.app.graph_dynamism"
|
|
72
|
+
APP_RETRIEVAL_LATENCY = "eval.app.retrieval_latency"
|
|
73
|
+
APP_AGENT_DURATION = "eval.app.duration"
|
|
74
|
+
APP_LLM_INVOCATION_DURATION = "eval.app.llm_invocation_duration"
|
|
75
|
+
APP_WORKFLOW_EFFICIENCY = "eval.app.workflow_efficiency"
|
|
76
|
+
APP_COMPLETION_RATE = "eval.app.completion_rate"
|
|
77
|
+
|
|
78
|
+
# MCE metric names (additional)
|
|
79
|
+
TOXICITY = "ToxicityMetric"
|
|
80
|
+
TONALITY = "TonalityMetric"
|
|
81
|
+
CONTEXT_PRESERVATION = "ContextPreservation"
|