diting-agent 0.1.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.
- diting_agent-0.1.0.dist-info/METADATA +770 -0
- diting_agent-0.1.0.dist-info/RECORD +303 -0
- diting_agent-0.1.0.dist-info/WHEEL +4 -0
- diting_agent-0.1.0.dist-info/entry_points.txt +3 -0
- trace_agent/__init__.py +3 -0
- trace_agent/__main__.py +4 -0
- trace_agent/agent/__init__.py +63 -0
- trace_agent/agent/adapters/claude/__init__.py +48 -0
- trace_agent/agent/adapters/claude/client.py +83 -0
- trace_agent/agent/adapters/claude/session.py +72 -0
- trace_agent/agent/adapters/claude/skills.py +68 -0
- trace_agent/agent/adapters/claude/tools.py +290 -0
- trace_agent/agent/adapters/codex/__init__.py +534 -0
- trace_agent/agent/adapters/codex/client.py +315 -0
- trace_agent/agent/adapters/codex/events.py +342 -0
- trace_agent/agent/adapters/codex/prompt.py +164 -0
- trace_agent/agent/adapters/codex/session.py +283 -0
- trace_agent/agent/adapters/openai/__init__.py +481 -0
- trace_agent/agent/adapters/openai/client.py +539 -0
- trace_agent/agent/adapters/openai/prompt.py +127 -0
- trace_agent/agent/adapters/openai/session.py +357 -0
- trace_agent/agent/adapters/qoder/__init__.py +44 -0
- trace_agent/agent/adapters/qoder/client.py +68 -0
- trace_agent/agent/adapters/qoder/session.py +72 -0
- trace_agent/agent/adapters/qoder/tools.py +301 -0
- trace_agent/agent/base.py +33 -0
- trace_agent/agent/claude.py +697 -0
- trace_agent/agent/core/__init__.py +55 -0
- trace_agent/agent/core/audit.py +166 -0
- trace_agent/agent/core/diagnostics.py +101 -0
- trace_agent/agent/core/helpers.py +75 -0
- trace_agent/agent/core/parsing.py +104 -0
- trace_agent/agent/core/payload.py +186 -0
- trace_agent/agent/core/prompts.py +265 -0
- trace_agent/agent/factory.py +118 -0
- trace_agent/agent/local.py +48 -0
- trace_agent/agent/protocols.py +90 -0
- trace_agent/agent/providers.py +116 -0
- trace_agent/agent/qoder.py +722 -0
- trace_agent/agent/qoder_transport.py +118 -0
- trace_agent/agent/registry.py +93 -0
- trace_agent/agent/runtime.py +390 -0
- trace_agent/agent/sdk_guard.py +50 -0
- trace_agent/agent/transport.py +169 -0
- trace_agent/application/__init__.py +31 -0
- trace_agent/application/analyze.py +1634 -0
- trace_agent/application/boundary_normalization.py +310 -0
- trace_agent/application/checkpoint.py +101 -0
- trace_agent/application/completion_phase_evidence.py +160 -0
- trace_agent/application/composition.py +237 -0
- trace_agent/application/evidence_normalization.py +453 -0
- trace_agent/application/normalization.py +381 -0
- trace_agent/application/preflight.py +148 -0
- trace_agent/cli.py +642 -0
- trace_agent/cli_progress.py +271 -0
- trace_agent/cli_run.py +213 -0
- trace_agent/cli_text.py +29 -0
- trace_agent/compat.py +382 -0
- trace_agent/config.py +154 -0
- trace_agent/contract/__init__.py +13 -0
- trace_agent/contract/result.py +86 -0
- trace_agent/contract/task.py +76 -0
- trace_agent/database/__init__.py +49 -0
- trace_agent/database/cold_start.py +1291 -0
- trace_agent/database/completion_latency.py +972 -0
- trace_agent/database/completion_phases.py +749 -0
- trace_agent/database/frame_jank.py +1789 -0
- trace_agent/database/perf.py +595 -0
- trace_agent/database/perf_analysis.py +1342 -0
- trace_agent/database/problem_window.py +464 -0
- trace_agent/database/repository.py +286 -0
- trace_agent/database/startup_modules.py +231 -0
- trace_agent/database/thread_dependencies.py +334 -0
- trace_agent/database/thread_execution.py +643 -0
- trace_agent/database/trace_indexes.py +73 -0
- trace_agent/demo/__init__.py +105 -0
- trace_agent/demo/agent.py +2114 -0
- trace_agent/demo/capture.py +130 -0
- trace_agent/demo/cli.py +463 -0
- trace_agent/demo/runner.py +327 -0
- trace_agent/demo/scenarios.py +207 -0
- trace_agent/demo/synth.py +1160 -0
- trace_agent/demo/trace_adapter.py +234 -0
- trace_agent/doctor/__init__.py +38 -0
- trace_agent/doctor/checks.py +828 -0
- trace_agent/doctor/cli.py +87 -0
- trace_agent/doctor/context.py +149 -0
- trace_agent/doctor/healthcheck.py +215 -0
- trace_agent/doctor/model.py +120 -0
- trace_agent/doctor/render.py +85 -0
- trace_agent/errors.py +300 -0
- trace_agent/eval/__init__.py +121 -0
- trace_agent/eval/cli.py +429 -0
- trace_agent/eval/grader.py +398 -0
- trace_agent/eval/harness.py +466 -0
- trace_agent/eval/loader.py +201 -0
- trace_agent/eval/memory_audit.py +666 -0
- trace_agent/eval/models.py +773 -0
- trace_agent/eval/multi_trial.py +227 -0
- trace_agent/eval/report.py +402 -0
- trace_agent/eval/runner.py +244 -0
- trace_agent/eval/service.py +638 -0
- trace_agent/eval/trajectory.py +267 -0
- trace_agent/evidence/__init__.py +4 -0
- trace_agent/evidence/index.py +191 -0
- trace_agent/evidence/store.py +58 -0
- trace_agent/llm/__init__.py +21 -0
- trace_agent/llm/deepseek.py +38 -0
- trace_agent/llm/ports.py +47 -0
- trace_agent/mcp_server/__init__.py +243 -0
- trace_agent/mcp_server/__main__.py +11 -0
- trace_agent/mcp_server/analyze.py +1450 -0
- trace_agent/mcp_server/binding.py +649 -0
- trace_agent/mcp_server/cli.py +1465 -0
- trace_agent/mcp_server/config.py +1017 -0
- trace_agent/mcp_server/conversion.py +743 -0
- trace_agent/mcp_server/eval_tools.py +1894 -0
- trace_agent/mcp_server/guard.py +1158 -0
- trace_agent/mcp_server/jobs.py +1288 -0
- trace_agent/mcp_server/memory_tools.py +1841 -0
- trace_agent/mcp_server/namespaces.py +316 -0
- trace_agent/mcp_server/ops.py +357 -0
- trace_agent/mcp_server/progress.py +351 -0
- trace_agent/mcp_server/prompts.py +818 -0
- trace_agent/mcp_server/resources.py +1264 -0
- trace_agent/mcp_server/schema.py +351 -0
- trace_agent/mcp_server/server.py +3520 -0
- trace_agent/mcp_server/session.py +423 -0
- trace_agent/mcp_server/submission.py +69 -0
- trace_agent/mcp_server/transport.py +1102 -0
- trace_agent/memory/__init__.py +311 -0
- trace_agent/memory/backend.py +287 -0
- trace_agent/memory/backup.py +416 -0
- trace_agent/memory/base.py +64 -0
- trace_agent/memory/cache.py +426 -0
- trace_agent/memory/calibrate.py +1501 -0
- trace_agent/memory/cli.py +2493 -0
- trace_agent/memory/consolidation.py +408 -0
- trace_agent/memory/context/__init__.py +29 -0
- trace_agent/memory/context/composer.py +345 -0
- trace_agent/memory/deep_recall.py +166 -0
- trace_agent/memory/dreaming.py +496 -0
- trace_agent/memory/embedding/__init__.py +43 -0
- trace_agent/memory/embedding/cache.py +88 -0
- trace_agent/memory/embedding/factory.py +192 -0
- trace_agent/memory/embedding/index.py +311 -0
- trace_agent/memory/embedding/lexicon.py +158 -0
- trace_agent/memory/embedding/local.py +142 -0
- trace_agent/memory/embedding/ollama.py +288 -0
- trace_agent/memory/embedding/ports.py +218 -0
- trace_agent/memory/embedding/remote.py +151 -0
- trace_agent/memory/episode.py +183 -0
- trace_agent/memory/eval_probe.py +148 -0
- trace_agent/memory/execution.py +49 -0
- trace_agent/memory/feedback.py +795 -0
- trace_agent/memory/flags.py +1527 -0
- trace_agent/memory/intent.py +52 -0
- trace_agent/memory/lifecycle/__init__.py +114 -0
- trace_agent/memory/lifecycle/conflicts.py +889 -0
- trace_agent/memory/lifecycle/contamination.py +239 -0
- trace_agent/memory/lifecycle/promoter.py +666 -0
- trace_agent/memory/lifecycle/quality_gate.py +371 -0
- trace_agent/memory/lifecycle/retention.py +238 -0
- trace_agent/memory/migrate.py +863 -0
- trace_agent/memory/models.py +595 -0
- trace_agent/memory/paths.py +40 -0
- trace_agent/memory/ports.py +637 -0
- trace_agent/memory/project.py +417 -0
- trace_agent/memory/quality_gate.py +33 -0
- trace_agent/memory/query_rewrite.py +1074 -0
- trace_agent/memory/recall.py +1124 -0
- trace_agent/memory/redaction.py +1372 -0
- trace_agent/memory/registry.py +162 -0
- trace_agent/memory/rerank.py +503 -0
- trace_agent/memory/retrieval_eval.py +2272 -0
- trace_agent/memory/runtime.py +507 -0
- trace_agent/memory/scope.py +407 -0
- trace_agent/memory/search_text.py +74 -0
- trace_agent/memory/seed.py +504 -0
- trace_agent/memory/semantic_profiles.py +462 -0
- trace_agent/memory/session.py +137 -0
- trace_agent/memory/store/__init__.py +170 -0
- trace_agent/memory/store/fts.py +44 -0
- trace_agent/memory/store/json_store.py +1302 -0
- trace_agent/memory/store/pg_schema.py +618 -0
- trace_agent/memory/store/postgres_store.py +986 -0
- trace_agent/memory/store/rows.py +277 -0
- trace_agent/memory/store/schema.py +381 -0
- trace_agent/memory/store/sql_core.py +2914 -0
- trace_agent/memory/store/sqlite_store.py +354 -0
- trace_agent/memory/store/version_race.py +124 -0
- trace_agent/memory/summarize.py +323 -0
- trace_agent/memory/text.py +192 -0
- trace_agent/memory/thresholds.py +809 -0
- trace_agent/models.py +624 -0
- trace_agent/observability/__init__.py +157 -0
- trace_agent/observability/cli.py +316 -0
- trace_agent/observability/collect.py +675 -0
- trace_agent/observability/export.py +588 -0
- trace_agent/observability/registry.py +583 -0
- trace_agent/observability/vocabulary.py +448 -0
- trace_agent/policies/__init__.py +6 -0
- trace_agent/policies/submission.py +328 -0
- trace_agent/progress.py +160 -0
- trace_agent/py.typed +0 -0
- trace_agent/qoder_config.py +69 -0
- trace_agent/report/__init__.py +4 -0
- trace_agent/report/projection.py +3993 -0
- trace_agent/report/renderer.py +83 -0
- trace_agent/report/templates/report.html.j2 +4293 -0
- trace_agent/runtime/__init__.py +68 -0
- trace_agent/runtime/cancellation.py +66 -0
- trace_agent/runtime/commands.py +80 -0
- trace_agent/runtime/context.py +61 -0
- trace_agent/runtime/event_bus.py +192 -0
- trace_agent/runtime/events.py +92 -0
- trace_agent/runtime/latency.py +199 -0
- trace_agent/runtime/persistence.py +122 -0
- trace_agent/runtime/sessions.py +216 -0
- trace_agent/runtime/sink.py +38 -0
- trace_agent/runtime/state.py +82 -0
- trace_agent/runtime_project/.qoder/skills/cold-start-analysis/SKILL.md +159 -0
- trace_agent/runtime_project/.qoder/skills/cold-start-analysis/SKILLCN.md +71 -0
- trace_agent/runtime_project/.qoder/skills/cold-start-analysis/agents/openai.yaml +4 -0
- trace_agent/runtime_project/.qoder/skills/cold-start-analysis/references/app-startup-phase-semantics.md +54 -0
- trace_agent/runtime_project/.qoder/skills/cold-start-analysis/references/app-startup-phase-semanticsCN.md +38 -0
- trace_agent/runtime_project/.qoder/skills/completion-latency-analysis/SKILL.md +135 -0
- trace_agent/runtime_project/.qoder/skills/completion-latency-analysis/SKILLCN.md +74 -0
- trace_agent/runtime_project/.qoder/skills/completion-latency-analysis/agents/openai.yaml +4 -0
- trace_agent/runtime_project/.qoder/skills/frame-jank-analysis/SKILL.md +105 -0
- trace_agent/runtime_project/.qoder/skills/frame-jank-analysis/SKILLCN.md +61 -0
- trace_agent/runtime_project/.qoder/skills/frame-jank-analysis/agents/openai.yaml +4 -0
- trace_agent/runtime_project/.qoder/skills/perf-sample-analysis/SKILL.md +189 -0
- trace_agent/runtime_project/.qoder/skills/perf-sample-analysis/SKILLCN.md +98 -0
- trace_agent/runtime_project/.qoder/skills/perf-sample-analysis/agents/openai.yaml +4 -0
- trace_agent/runtime_project/.qoder/skills/perf-sample-analysis/references/perf-trace-streamer-schema.md +182 -0
- trace_agent/runtime_project/.qoder/skills/perf-sample-analysis/references/perf-trace-streamer-schemaCN.md +160 -0
- trace_agent/runtime_project/.qoder/skills/response-latency-analysis/SKILL.md +195 -0
- trace_agent/runtime_project/.qoder/skills/response-latency-analysis/SKILLCN.md +104 -0
- trace_agent/runtime_project/.qoder/skills/response-latency-analysis/agents/openai.yaml +4 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/SKILL.md +127 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/SKILLCN.md +76 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/agents/openai.yaml +4 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/references/io-analysis.md +15 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/references/io-analysisCN.md +13 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/references/rendering-analysis.md +9 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/references/rendering-analysisCN.md +5 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/references/report-standard.md +23 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/references/report-standardCN.md +22 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/references/thread-execution-critical-path.md +150 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/references/thread-execution-critical-pathCN.md +125 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/references/trace-streamer-schema.md +257 -0
- trace_agent/runtime_project/.qoder/skills/trace-analysis/references/trace-streamer-schemaCN.md +216 -0
- trace_agent/runtime_tools/trace_streamer/CHECKSUMS.sha256 +15 -0
- trace_agent/runtime_tools/trace_streamer/LICENSE +201 -0
- trace_agent/runtime_tools/trace_streamer/README.md +69 -0
- trace_agent/runtime_tools/trace_streamer/VERSION +11 -0
- trace_agent/runtime_tools/trace_streamer/darwin-aarch64/trace_streamer +0 -0
- trace_agent/runtime_tools/trace_streamer/linux-x86_64/trace_streamer +0 -0
- trace_agent/runtime_tools/trace_streamer/windows-x86_64/trace_streamer.exe +0 -0
- trace_agent/scenarios/__init__.py +11 -0
- trace_agent/scenarios/catalog.py +156 -0
- trace_agent/secret_files.py +172 -0
- trace_agent/service/__init__.py +20 -0
- trace_agent/service/audit.py +230 -0
- trace_agent/service/ratelimit.py +320 -0
- trace_agent/service/tenancy.py +253 -0
- trace_agent/settings.py +1759 -0
- trace_agent/skills/__init__.py +22 -0
- trace_agent/skills/catalog.py +174 -0
- trace_agent/skills/inlining.py +198 -0
- trace_agent/skills/router.py +31 -0
- trace_agent/time_range.py +55 -0
- trace_agent/tools/__init__.py +29 -0
- trace_agent/tools/factory.py +26 -0
- trace_agent/tools/parameters.py +322 -0
- trace_agent/tools/registry.py +347 -0
- trace_agent/tools/trace_tools.py +1772 -0
- trace_agent/trace/__init__.py +17 -0
- trace_agent/trace/asset_root.py +120 -0
- trace_agent/trace/base.py +15 -0
- trace_agent/trace/cache.py +260 -0
- trace_agent/trace/cancellation.py +183 -0
- trace_agent/trace/htrace.py +204 -0
- trace_agent/trace/provision.py +626 -0
- trace_agent/trace/trace_streamer.py +602 -0
- trace_agent/trace/vendor_integrity.py +330 -0
- trace_agent/validation/__init__.py +15 -0
- trace_agent/validation/analysis.py +1964 -0
- trace_agent/verification/__init__.py +13 -0
- trace_agent/verification/result_verifier.py +197 -0
- trace_agent/web/__init__.py +4 -0
- trace_agent/web/app.py +584 -0
- trace_agent/web/asgi.py +321 -0
- trace_agent/web/routes_memory.py +399 -0
- trace_agent/web/routes_runs.py +788 -0
- trace_agent/web/routes_sse.py +109 -0
- trace_agent/web/server.py +530 -0
- trace_agent/web/state.py +303 -0
- trace_agent/web/static/app.js +1717 -0
- trace_agent/web/static/index.html +225 -0
- trace_agent/web/static/styles.css +830 -0
- trace_agent/web/static.py +51 -0
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
"""The fixed metric catalogue (P1-1).
|
|
2
|
+
|
|
3
|
+
One table, in one place, listing every metric this process can ever emit with
|
|
4
|
+
its kind, its help line and its exact label set. Two reasons it is a table
|
|
5
|
+
rather than a pile of ``Counter("...")`` calls scattered across the codebase:
|
|
6
|
+
|
|
7
|
+
1. A team wiring DitingAgent into their own platform needs the contract up
|
|
8
|
+
front. ``metric_names()`` and ``label_sets()`` are that contract, and
|
|
9
|
+
``tests/test_observability.py`` pins them literally, so a renamed metric or
|
|
10
|
+
a new label fails a test instead of silently breaking somebody's dashboard.
|
|
11
|
+
2. Label sets are the cardinality budget. Declaring them here makes "this
|
|
12
|
+
label is unbounded" a reviewable decision rather than an accident in a
|
|
13
|
+
format string three modules away.
|
|
14
|
+
|
|
15
|
+
Nothing in this module measures anything. It is data; :mod:`.registry` holds
|
|
16
|
+
the numbers and :mod:`.collect` decides which already-computed domain value
|
|
17
|
+
feeds which series.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
from dataclasses import dataclass
|
|
23
|
+
|
|
24
|
+
COUNTER = "counter"
|
|
25
|
+
GAUGE = "gauge"
|
|
26
|
+
HISTOGRAM = "histogram"
|
|
27
|
+
|
|
28
|
+
# Prometheus requires these three and nothing else; an unknown kind would
|
|
29
|
+
# render an invalid ``# TYPE`` line rather than fail loudly at scrape time.
|
|
30
|
+
KINDS: tuple[str, ...] = (COUNTER, GAUGE, HISTOGRAM)
|
|
31
|
+
|
|
32
|
+
# Every series is prefixed so that a shared scrape target can tell our numbers
|
|
33
|
+
# apart from the exporter's own ``process_*`` / ``python_*`` families.
|
|
34
|
+
PREFIX = "diting"
|
|
35
|
+
|
|
36
|
+
# Wall-clock budgets, in milliseconds. The steps are the ones the latency policy
|
|
37
|
+
# and the four scenario budgets actually reason about: sub-second for a single
|
|
38
|
+
# tool call, seconds for recall and a stage, minutes for a whole run.
|
|
39
|
+
LATENCY_BUCKETS: tuple[float, ...] = (
|
|
40
|
+
50.0,
|
|
41
|
+
100.0,
|
|
42
|
+
250.0,
|
|
43
|
+
500.0,
|
|
44
|
+
1_000.0,
|
|
45
|
+
2_500.0,
|
|
46
|
+
5_000.0,
|
|
47
|
+
10_000.0,
|
|
48
|
+
30_000.0,
|
|
49
|
+
60_000.0,
|
|
50
|
+
120_000.0,
|
|
51
|
+
300_000.0,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# Recall is a local query against SQLite or Postgres; a 30s bucket would only
|
|
55
|
+
# ever tell us "it was slow", which the run histogram already says.
|
|
56
|
+
RECALL_BUCKETS: tuple[float, ...] = (
|
|
57
|
+
1.0,
|
|
58
|
+
5.0,
|
|
59
|
+
10.0,
|
|
60
|
+
25.0,
|
|
61
|
+
50.0,
|
|
62
|
+
100.0,
|
|
63
|
+
250.0,
|
|
64
|
+
500.0,
|
|
65
|
+
1_000.0,
|
|
66
|
+
2_500.0,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# Small integer counts: hits per recall, repair rounds per run.
|
|
70
|
+
COUNT_BUCKETS: tuple[float, ...] = (0.0, 1.0, 2.0, 3.0, 5.0, 8.0, 13.0, 21.0)
|
|
71
|
+
|
|
72
|
+
# Anything that is a share of something else.
|
|
73
|
+
RATIO_BUCKETS: tuple[float, ...] = (
|
|
74
|
+
0.0,
|
|
75
|
+
0.05,
|
|
76
|
+
0.1,
|
|
77
|
+
0.25,
|
|
78
|
+
0.5,
|
|
79
|
+
0.75,
|
|
80
|
+
0.9,
|
|
81
|
+
0.99,
|
|
82
|
+
1.0,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@dataclass(frozen=True, slots=True)
|
|
87
|
+
class MetricSpec:
|
|
88
|
+
"""One exported metric: its full Prometheus name and its label contract."""
|
|
89
|
+
|
|
90
|
+
#: Full base name, prefix included. Counters carry the ``_total`` suffix
|
|
91
|
+
#: themselves so that the rendered text is exactly what a scraper sees and
|
|
92
|
+
#: no suffix rule has to be inferred at render time.
|
|
93
|
+
name: str
|
|
94
|
+
kind: str
|
|
95
|
+
#: Single line. Prometheus ``# HELP`` is one line by definition; a newline
|
|
96
|
+
#: here would corrupt every series that follows it.
|
|
97
|
+
help: str
|
|
98
|
+
labels: tuple[str, ...] = ()
|
|
99
|
+
buckets: tuple[float, ...] = ()
|
|
100
|
+
|
|
101
|
+
def __post_init__(self) -> None:
|
|
102
|
+
if self.kind not in KINDS:
|
|
103
|
+
raise ValueError(f"未知指标类型:{self.kind}")
|
|
104
|
+
if not self.name.startswith(f"{PREFIX}_"):
|
|
105
|
+
raise ValueError(f"指标名必须带 {PREFIX}_ 前缀:{self.name}")
|
|
106
|
+
if self.kind == COUNTER and not self.name.endswith("_total"):
|
|
107
|
+
raise ValueError(f"counter 必须以 _total 结尾:{self.name}")
|
|
108
|
+
if self.kind != COUNTER and self.name.endswith("_total"):
|
|
109
|
+
raise ValueError(f"只有 counter 能以 _total 结尾:{self.name}")
|
|
110
|
+
if "\n" in self.help or not self.help.strip():
|
|
111
|
+
raise ValueError(f"HELP 必须是单行非空文本:{self.name}")
|
|
112
|
+
if len(set(self.labels)) != len(self.labels):
|
|
113
|
+
raise ValueError(f"标签重复:{self.name}")
|
|
114
|
+
if self.kind == HISTOGRAM and not self.buckets:
|
|
115
|
+
raise ValueError(f"histogram 必须声明 buckets:{self.name}")
|
|
116
|
+
if self.kind != HISTOGRAM and self.buckets:
|
|
117
|
+
raise ValueError(f"只有 histogram 能声明 buckets:{self.name}")
|
|
118
|
+
if self.buckets and list(self.buckets) != sorted(self.buckets):
|
|
119
|
+
raise ValueError(f"buckets 必须升序:{self.name}")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# --------------------------------------------------------------------- runs
|
|
123
|
+
|
|
124
|
+
_RUN_LABELS = ("scenario_type", "agent", "status")
|
|
125
|
+
|
|
126
|
+
RUNS = MetricSpec(
|
|
127
|
+
name=f"{PREFIX}_runs_total",
|
|
128
|
+
kind=COUNTER,
|
|
129
|
+
help="已完成的分析运行数,按场景、Agent 后端与最终状态区分。",
|
|
130
|
+
labels=_RUN_LABELS,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
RUN_DURATION = MetricSpec(
|
|
134
|
+
name=f"{PREFIX}_run_duration_milliseconds",
|
|
135
|
+
kind=HISTOGRAM,
|
|
136
|
+
help="单次分析运行的端到端墙钟耗时(毫秒),取自 performance.json。",
|
|
137
|
+
labels=_RUN_LABELS,
|
|
138
|
+
buckets=LATENCY_BUCKETS,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
STAGE_DURATION = MetricSpec(
|
|
142
|
+
name=f"{PREFIX}_stage_duration_milliseconds",
|
|
143
|
+
kind=HISTOGRAM,
|
|
144
|
+
help="运行内各阶段耗时(毫秒),阶段名来自 StageRecorder 快照。",
|
|
145
|
+
labels=("scenario_type", "stage"),
|
|
146
|
+
buckets=LATENCY_BUCKETS,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# -------------------------------------------------------------------- tools
|
|
150
|
+
|
|
151
|
+
TOOL_INVOCATIONS = MetricSpec(
|
|
152
|
+
name=f"{PREFIX}_tool_invocations_total",
|
|
153
|
+
kind=COUNTER,
|
|
154
|
+
help="只读 Trace 工具调用次数,outcome 为 ok / error / budget。",
|
|
155
|
+
labels=("tool", "outcome"),
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
TOOL_BUDGET_EXCEEDED = MetricSpec(
|
|
159
|
+
name=f"{PREFIX}_tool_budget_exceeded_total",
|
|
160
|
+
kind=COUNTER,
|
|
161
|
+
help=(
|
|
162
|
+
"工具预算拒绝次数。reason 为 sealed / tool_limit / "
|
|
163
|
+
"reserved_budget / total_budget,与 tools/registry.py 的四个拒绝点一一对应。"
|
|
164
|
+
),
|
|
165
|
+
labels=("reason",),
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
DRAFT_REPAIR_ROUNDS = MetricSpec(
|
|
169
|
+
name=f"{PREFIX}_draft_repair_rounds",
|
|
170
|
+
kind=HISTOGRAM,
|
|
171
|
+
help="一次运行里结构化 Draft 走了几轮有界修正(repair)。",
|
|
172
|
+
labels=("agent",),
|
|
173
|
+
buckets=COUNT_BUCKETS,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
# ------------------------------------------------------------------- memory
|
|
177
|
+
|
|
178
|
+
MEMORY_RECALL_LATENCY = MetricSpec(
|
|
179
|
+
name=f"{PREFIX}_memory_recall_latency_milliseconds",
|
|
180
|
+
kind=HISTOGRAM,
|
|
181
|
+
help="记忆召回耗时(毫秒),取自 MemoryTrace.latency_ms。",
|
|
182
|
+
labels=("namespace", "store"),
|
|
183
|
+
buckets=RECALL_BUCKETS,
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
MEMORY_RECALL_HITS = MetricSpec(
|
|
187
|
+
name=f"{PREFIX}_memory_recall_hits",
|
|
188
|
+
kind=HISTOGRAM,
|
|
189
|
+
help="单次召回命中的记忆条数。",
|
|
190
|
+
labels=("namespace",),
|
|
191
|
+
buckets=COUNT_BUCKETS,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
MEMORY_INJECTION_RATIO = MetricSpec(
|
|
195
|
+
name=f"{PREFIX}_memory_injection_ratio",
|
|
196
|
+
kind=HISTOGRAM,
|
|
197
|
+
help=(
|
|
198
|
+
"注入率:真正进入 prompt 的命中数 / 召回命中数。"
|
|
199
|
+
"0 命中记为 0,与「预算把命中挤掉了」是同一根轴上的两端。"
|
|
200
|
+
),
|
|
201
|
+
labels=("namespace",),
|
|
202
|
+
buckets=RATIO_BUCKETS,
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
MEMORY_RECALL_TRUNCATED = MetricSpec(
|
|
206
|
+
name=f"{PREFIX}_memory_recall_truncated_total",
|
|
207
|
+
kind=COUNTER,
|
|
208
|
+
help="召回结果被 prompt 预算截断的次数。",
|
|
209
|
+
labels=("namespace",),
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
MEMORY_CORPUS_RECORDS = MetricSpec(
|
|
213
|
+
name=f"{PREFIX}_memory_corpus_records",
|
|
214
|
+
kind=GAUGE,
|
|
215
|
+
help="语料规模,kind 为 memories / episodes / sessions,取自 MemoryStats。",
|
|
216
|
+
labels=("namespace", "store", "kind"),
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
MEMORY_TRUST_RECORDS = MetricSpec(
|
|
220
|
+
name=f"{PREFIX}_memory_trust_records",
|
|
221
|
+
kind=GAUGE,
|
|
222
|
+
help="按信任档(candidate / active / verified / archived)分布的记录数。",
|
|
223
|
+
labels=("namespace", "trust"),
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
MEMORY_TYPE_RECORDS = MetricSpec(
|
|
227
|
+
name=f"{PREFIX}_memory_type_records",
|
|
228
|
+
kind=GAUGE,
|
|
229
|
+
help="按业务类型分布的 curated 记忆数。",
|
|
230
|
+
labels=("namespace", "type"),
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
MEMORY_HEALTH_RECORDS = MetricSpec(
|
|
234
|
+
name=f"{PREFIX}_memory_health_records",
|
|
235
|
+
kind=GAUGE,
|
|
236
|
+
help=(
|
|
237
|
+
"语料健康计数,state 为 contradictions / expired / duplicates / "
|
|
238
|
+
"superseded / versions / links。"
|
|
239
|
+
),
|
|
240
|
+
labels=("namespace", "state"),
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
MEMORY_GOVERNANCE_QUEUE = MetricSpec(
|
|
244
|
+
name=f"{PREFIX}_memory_governance_queue_available",
|
|
245
|
+
kind=GAUGE,
|
|
246
|
+
help=(
|
|
247
|
+
"该语料是否有治理队列可读(1/0)。为 0 时 backlog 系列不会出现,"
|
|
248
|
+
"因为「没有队列」和「队列是空的」不是一件事。"
|
|
249
|
+
),
|
|
250
|
+
labels=("namespace",),
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
MEMORY_GOVERNANCE_BACKLOG = MetricSpec(
|
|
254
|
+
name=f"{PREFIX}_memory_governance_backlog",
|
|
255
|
+
kind=GAUGE,
|
|
256
|
+
help=(
|
|
257
|
+
"待治理队列作业数。mode 是命名空间当前的 inline 治理模式;"
|
|
258
|
+
"saturated=true 表示探测到上限,真实值更大。"
|
|
259
|
+
),
|
|
260
|
+
labels=("namespace", "mode", "saturated"),
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
MEMORY_EMBEDDING_AVAILABLE = MetricSpec(
|
|
264
|
+
name=f"{PREFIX}_memory_embedding_available",
|
|
265
|
+
kind=GAUGE,
|
|
266
|
+
help="向量通道是否可用(1/0),kind 是 embedding 适配器名,off 表示未启用。",
|
|
267
|
+
labels=("namespace", "kind"),
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
MEMORY_EMBEDDING_RECORDS = MetricSpec(
|
|
271
|
+
name=f"{PREFIX}_memory_embedding_records",
|
|
272
|
+
kind=GAUGE,
|
|
273
|
+
help=(
|
|
274
|
+
"嵌入覆盖情况,state 为 embedded / pending / stale。"
|
|
275
|
+
"stale 是用旧配方嵌入、与当前 model 不一致的记录数。"
|
|
276
|
+
),
|
|
277
|
+
labels=("namespace", "state"),
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
MEMORY_FEEDBACK_RECORDS = MetricSpec(
|
|
281
|
+
name=f"{PREFIX}_memory_feedback_records",
|
|
282
|
+
kind=GAUGE,
|
|
283
|
+
help=(
|
|
284
|
+
"在线归因计数,state 为 attributions(去重后的注入归因)/ "
|
|
285
|
+
"memories(有归因的记忆数)/ review(复审队列长度)。"
|
|
286
|
+
),
|
|
287
|
+
labels=("namespace", "state"),
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
MEMORY_FEEDBACK_CONFIG = MetricSpec(
|
|
291
|
+
name=f"{PREFIX}_memory_feedback_config",
|
|
292
|
+
kind=GAUGE,
|
|
293
|
+
help=(
|
|
294
|
+
"归因策略当前取值,state 为 enabled / supported / threshold / "
|
|
295
|
+
"min_injections。配置以 gauge 导出,是为了让「指标为什么变了」"
|
|
296
|
+
"和「配置什么时候变的」能在同一张图上对齐。"
|
|
297
|
+
),
|
|
298
|
+
labels=("namespace", "state"),
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
MEMORY_SELF_CONTAMINATION = MetricSpec(
|
|
302
|
+
name=f"{PREFIX}_memory_self_contamination_rate",
|
|
303
|
+
kind=GAUGE,
|
|
304
|
+
help="最近一次 eval 对比组的自污染率;没有 eval 数据时不出现该系列。",
|
|
305
|
+
labels=("namespace",),
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
# --------------------------------------------------------------- bookkeeping
|
|
309
|
+
|
|
310
|
+
# A cardinality ceiling that silently dropped samples would be worse than no
|
|
311
|
+
# ceiling: the operator sees a flat line and reads it as "nothing happened".
|
|
312
|
+
# Counting the drops keeps the ceiling itself observable.
|
|
313
|
+
SERIES_DROPPED = MetricSpec(
|
|
314
|
+
name=f"{PREFIX}_metric_series_dropped_total",
|
|
315
|
+
kind=COUNTER,
|
|
316
|
+
help="因单指标时间序列数超过上限而被丢弃的样本数,metric 是被丢弃的指标名。",
|
|
317
|
+
labels=("metric",),
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
# The whole catalogue, in render order. Grouped runs -> tools -> memory ->
|
|
322
|
+
# bookkeeping so that a scraped page reads like the run does.
|
|
323
|
+
METRICS: tuple[MetricSpec, ...] = (
|
|
324
|
+
RUNS,
|
|
325
|
+
RUN_DURATION,
|
|
326
|
+
STAGE_DURATION,
|
|
327
|
+
TOOL_INVOCATIONS,
|
|
328
|
+
TOOL_BUDGET_EXCEEDED,
|
|
329
|
+
DRAFT_REPAIR_ROUNDS,
|
|
330
|
+
MEMORY_RECALL_LATENCY,
|
|
331
|
+
MEMORY_RECALL_HITS,
|
|
332
|
+
MEMORY_INJECTION_RATIO,
|
|
333
|
+
MEMORY_RECALL_TRUNCATED,
|
|
334
|
+
MEMORY_CORPUS_RECORDS,
|
|
335
|
+
MEMORY_TRUST_RECORDS,
|
|
336
|
+
MEMORY_TYPE_RECORDS,
|
|
337
|
+
MEMORY_HEALTH_RECORDS,
|
|
338
|
+
MEMORY_GOVERNANCE_QUEUE,
|
|
339
|
+
MEMORY_GOVERNANCE_BACKLOG,
|
|
340
|
+
MEMORY_EMBEDDING_AVAILABLE,
|
|
341
|
+
MEMORY_EMBEDDING_RECORDS,
|
|
342
|
+
MEMORY_FEEDBACK_RECORDS,
|
|
343
|
+
MEMORY_FEEDBACK_CONFIG,
|
|
344
|
+
MEMORY_SELF_CONTAMINATION,
|
|
345
|
+
SERIES_DROPPED,
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
SPEC_BY_NAME: dict[str, MetricSpec] = {spec.name: spec for spec in METRICS}
|
|
349
|
+
|
|
350
|
+
# Enumerated label values. Anything a caller passes outside these sets is
|
|
351
|
+
# accepted (the vocabulary cannot know every store kind or stage name), but the
|
|
352
|
+
# sets are what the tests pin and what documents the intended cardinality.
|
|
353
|
+
LABEL_VALUES: dict[str, frozenset[str]] = {
|
|
354
|
+
"status": frozenset({"completed", "failed", "cancelled", "unknown"}),
|
|
355
|
+
"outcome": frozenset({"ok", "error", "budget"}),
|
|
356
|
+
"reason": frozenset(
|
|
357
|
+
{"sealed", "tool_limit", "reserved_budget", "total_budget"}
|
|
358
|
+
),
|
|
359
|
+
"kind": frozenset(
|
|
360
|
+
{"memories", "episodes", "sessions", "embedded", "pending", "stale"}
|
|
361
|
+
),
|
|
362
|
+
"trust": frozenset({"candidate", "active", "verified", "archived"}),
|
|
363
|
+
"state": frozenset(
|
|
364
|
+
{
|
|
365
|
+
"contradictions",
|
|
366
|
+
"expired",
|
|
367
|
+
"duplicates",
|
|
368
|
+
"superseded",
|
|
369
|
+
"versions",
|
|
370
|
+
"links",
|
|
371
|
+
"embedded",
|
|
372
|
+
"pending",
|
|
373
|
+
"stale",
|
|
374
|
+
"attributions",
|
|
375
|
+
"memories",
|
|
376
|
+
"review",
|
|
377
|
+
"enabled",
|
|
378
|
+
"supported",
|
|
379
|
+
"threshold",
|
|
380
|
+
"min_injections",
|
|
381
|
+
}
|
|
382
|
+
),
|
|
383
|
+
"saturated": frozenset({"true", "false"}),
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def metric_names() -> tuple[str, ...]:
|
|
388
|
+
"""Every metric name this process may emit, in render order."""
|
|
389
|
+
return tuple(spec.name for spec in METRICS)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def label_sets() -> dict[str, tuple[str, ...]]:
|
|
393
|
+
"""Metric name -> its exact label tuple. The cardinality contract."""
|
|
394
|
+
return {spec.name: spec.labels for spec in METRICS}
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
#: The series names a histogram renders under, as documented on
|
|
398
|
+
#: :class:`~trace_agent.observability.registry.Sample`. Kept here rather than in
|
|
399
|
+
#: the renderer or in a test: "which catalogue entry does this series belong to"
|
|
400
|
+
#: is a vocabulary question, and a second copy of these three suffixes would
|
|
401
|
+
#: silently stop matching the day the renderer changes.
|
|
402
|
+
HISTOGRAM_SERIES_SUFFIXES: tuple[str, ...] = ("_bucket", "_sum", "_count")
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def series_metric_name(series: str) -> str | None:
|
|
406
|
+
"""Map a rendered Prometheus series name back to its catalogued metric.
|
|
407
|
+
|
|
408
|
+
Counters and gauges render under their own name, so they map to themselves.
|
|
409
|
+
A histogram renders under ``<base>_bucket`` / ``<base>_sum`` /
|
|
410
|
+
``<base>_count``, so those three map back to ``<base>``. Anything else
|
|
411
|
+
returns ``None``, which is the answer a caller needs in order to tell
|
|
412
|
+
"this series is not in the catalogue" apart from "this series is one
|
|
413
|
+
sample of a catalogued histogram".
|
|
414
|
+
|
|
415
|
+
Exact matches are tried first, so a metric whose own name happened to end
|
|
416
|
+
in one of the suffixes still resolves to itself rather than to a shorter
|
|
417
|
+
name that does not exist.
|
|
418
|
+
"""
|
|
419
|
+
if series in SPEC_BY_NAME:
|
|
420
|
+
return series
|
|
421
|
+
for suffix in HISTOGRAM_SERIES_SUFFIXES:
|
|
422
|
+
if series.endswith(suffix):
|
|
423
|
+
base = series[: -len(suffix)]
|
|
424
|
+
if base in SPEC_BY_NAME:
|
|
425
|
+
return base
|
|
426
|
+
return None
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
__all__ = [
|
|
430
|
+
"COUNT_BUCKETS",
|
|
431
|
+
"COUNTER",
|
|
432
|
+
"GAUGE",
|
|
433
|
+
"HISTOGRAM",
|
|
434
|
+
"HISTOGRAM_SERIES_SUFFIXES",
|
|
435
|
+
"KINDS",
|
|
436
|
+
"LABEL_VALUES",
|
|
437
|
+
"LATENCY_BUCKETS",
|
|
438
|
+
"METRICS",
|
|
439
|
+
"PREFIX",
|
|
440
|
+
"RATIO_BUCKETS",
|
|
441
|
+
"RECALL_BUCKETS",
|
|
442
|
+
"SERIES_DROPPED",
|
|
443
|
+
"SPEC_BY_NAME",
|
|
444
|
+
"MetricSpec",
|
|
445
|
+
"label_sets",
|
|
446
|
+
"metric_names",
|
|
447
|
+
"series_metric_name",
|
|
448
|
+
]
|