aid-runtime-python 0.1.153__tar.gz → 0.1.154__tar.gz

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.
Files changed (122) hide show
  1. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/PKG-INFO +1 -1
  2. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/pyproject.toml +1 -1
  3. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/__init__.py +1 -1
  4. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/gateway.py +19 -1
  5. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/tracing.py +52 -0
  6. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
  7. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_local_trace.py +32 -1
  8. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_tracing.py +73 -0
  9. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/README.md +0 -0
  10. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/setup.cfg +0 -0
  11. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/agents/__init__.py +0 -0
  12. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/agents/chat_model.py +0 -0
  13. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/agents/deep_agents.py +0 -0
  14. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/agents/engine.py +0 -0
  15. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/agents/guardrails.py +0 -0
  16. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/agents/ir.py +0 -0
  17. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/agents/loop.py +0 -0
  18. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/agents/managed.py +0 -0
  19. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/agents/memory.py +0 -0
  20. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/agents/policy.py +0 -0
  21. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/agents/state.py +0 -0
  22. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/cache.py +0 -0
  23. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/concurrency.py +0 -0
  24. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/control.py +0 -0
  25. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/cost.py +0 -0
  26. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/decisions.py +0 -0
  27. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/errors.py +0 -0
  28. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/evals/__init__.py +0 -0
  29. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/evals/dataset.py +0 -0
  30. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/evals/gate.py +0 -0
  31. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/evals/metrics.py +0 -0
  32. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/evals/predicate.py +0 -0
  33. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/evals/runner.py +0 -0
  34. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/evals/trajectory.py +0 -0
  35. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/local_trace.py +0 -0
  36. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/metrics.py +0 -0
  37. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/pipeline.py +0 -0
  38. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/prompts.py +0 -0
  39. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/providers/__init__.py +0 -0
  40. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/providers/anthropic.py +0 -0
  41. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/providers/base.py +0 -0
  42. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/providers/bedrock.py +0 -0
  43. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/providers/fake.py +0 -0
  44. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/providers/gemini.py +0 -0
  45. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/providers/gemini_wire.py +0 -0
  46. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/providers/http.py +0 -0
  47. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/providers/vertex.py +0 -0
  48. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/py.typed +0 -0
  49. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/__init__.py +0 -0
  50. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/chunking.py +0 -0
  51. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/citations.py +0 -0
  52. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/connectors.py +0 -0
  53. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/embedding.py +0 -0
  54. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/filters.py +0 -0
  55. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/gate.py +0 -0
  56. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/hybrid.py +0 -0
  57. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/knowledge_base.py +0 -0
  58. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/metrics.py +0 -0
  59. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/pgvector.py +0 -0
  60. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/rerank.py +0 -0
  61. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/retriever.py +0 -0
  62. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/stores.py +0 -0
  63. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/retrieval/types.py +0 -0
  64. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/steps.py +0 -0
  65. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/structured.py +0 -0
  66. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/telemetry.py +0 -0
  67. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/tools.py +0 -0
  68. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime/types.py +0 -0
  69. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime_python.egg-info/SOURCES.txt +0 -0
  70. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
  71. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime_python.egg-info/requires.txt +0 -0
  72. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
  73. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_agents_budget.py +0 -0
  74. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_agents_deep_agents.py +0 -0
  75. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_agents_hitl.py +0 -0
  76. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_agents_loop.py +0 -0
  77. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_agents_memory.py +0 -0
  78. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_anthropic_provider.py +0 -0
  79. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_bedrock_provider.py +0 -0
  80. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_cache.py +0 -0
  81. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_concurrency.py +0 -0
  82. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_control.py +0 -0
  83. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_cost.py +0 -0
  84. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_dataset.py +0 -0
  85. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_decisions.py +0 -0
  86. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_evals.py +0 -0
  87. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_evals_assert_gate.py +0 -0
  88. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_evals_budgets.py +0 -0
  89. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_evals_decision.py +0 -0
  90. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_evals_gate.py +0 -0
  91. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_evals_predicate.py +0 -0
  92. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_evals_trajectory.py +0 -0
  93. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_gateway.py +0 -0
  94. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_gemini_provider.py +0 -0
  95. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_guardrails.py +0 -0
  96. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_guardrails_managed.py +0 -0
  97. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_guardrails_model_armor.py +0 -0
  98. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_http_provider.py +0 -0
  99. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_metrics.py +0 -0
  100. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_package.py +0 -0
  101. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_pipeline.py +0 -0
  102. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_prompts.py +0 -0
  103. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_chunking.py +0 -0
  104. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_citations.py +0 -0
  105. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_connectors.py +0 -0
  106. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_embedding.py +0 -0
  107. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_filters.py +0 -0
  108. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_gate.py +0 -0
  109. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_hybrid.py +0 -0
  110. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_knowledge_base.py +0 -0
  111. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_metrics.py +0 -0
  112. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_rerank.py +0 -0
  113. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_stores.py +0 -0
  114. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_retrieval_types.py +0 -0
  115. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_steps.py +0 -0
  116. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_streaming.py +0 -0
  117. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_structured.py +0 -0
  118. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_telemetry.py +0 -0
  119. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_tool_permissions.py +0 -0
  120. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_tools.py +0 -0
  121. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_types.py +0 -0
  122. {aid_runtime_python-0.1.153 → aid_runtime_python-0.1.154}/tests/test_vertex_provider.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aid-runtime-python
3
- Version: 0.1.153
3
+ Version: 0.1.154
4
4
  Summary: The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline.
5
5
  Author: The AID Framework authors
6
6
  License-Expression: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aid-runtime-python"
7
- version = "0.1.153"
7
+ version = "0.1.154"
8
8
  description = "The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -337,7 +337,7 @@ from aid_runtime.types import (
337
337
  )
338
338
 
339
339
  #: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
340
- __version__ = "0.1.153"
340
+ __version__ = "0.1.154"
341
341
 
342
342
  __all__ = [
343
343
  "AGENT_LABEL",
@@ -32,7 +32,14 @@ from aid_runtime.errors import (
32
32
  UnknownModelAliasError,
33
33
  )
34
34
  from aid_runtime.providers.base import Provider
35
- from aid_runtime.tracing import ATTRIBUTES, get_tracer, llm_span, record_cost, record_usage
35
+ from aid_runtime.tracing import (
36
+ ATTRIBUTES,
37
+ get_tracer,
38
+ llm_span,
39
+ record_content,
40
+ record_cost,
41
+ record_usage,
42
+ )
36
43
  from aid_runtime.types import (
37
44
  Capability,
38
45
  CompletionRequest,
@@ -55,6 +62,15 @@ _CACHE_CHUNK = 16
55
62
  CallHook = Callable[[LedgerEntry], None]
56
63
 
57
64
 
65
+ def _prompt_text(request: CompletionRequest) -> str:
66
+ """The prompt as one string, for a span that was asked to record payloads.
67
+
68
+ Role-prefixed rather than concatenated, so a captured prompt still shows which
69
+ turn a line came from once it is a row of JSONL rather than a live message list.
70
+ """
71
+ return "\n\n".join(f"{message.role}: {message.content}" for message in request.messages)
72
+
73
+
58
74
  def _sse(payload: dict[str, Any]) -> bytes:
59
75
  """Encode one Server-Sent Event ``data`` frame as UTF-8 bytes."""
60
76
  return f"data: {json.dumps(payload, separators=(',', ':'))}\n\n".encode()
@@ -270,6 +286,7 @@ class ModelGateway:
270
286
  cost = spec.cost.cost_usd(usage)
271
287
  record_usage(span, usage)
272
288
  record_cost(span, cost, alias=pinned.alias)
289
+ record_content(span, input_text=_prompt_text(request), output_text=text)
273
290
 
274
291
  entry = LedgerEntry(
275
292
  alias=pinned.alias,
@@ -341,6 +358,7 @@ class ModelGateway:
341
358
  cost = spec.cost.cost_usd(response.usage)
342
359
  record_usage(span, response.usage)
343
360
  record_cost(span, cost, alias=pinned.alias)
361
+ record_content(span, input_text=_prompt_text(request), output_text=response.text)
344
362
  if len(attempted) > 1:
345
363
  span.set_attribute(ATTRIBUTES["attempts"], list(attempted))
346
364
 
@@ -16,6 +16,7 @@ spans written here leave the process.
16
16
  from __future__ import annotations
17
17
 
18
18
  import contextlib
19
+ import os
19
20
  from collections.abc import Iterator, Sequence
20
21
  from typing import Any, Protocol
21
22
 
@@ -27,13 +28,17 @@ from aid_runtime.types import TokenUsage
27
28
 
28
29
  __all__ = [
29
30
  "ATTRIBUTES",
31
+ "CONTENT_ENV",
30
32
  "GEN_AI_OPERATION_CHAT",
33
+ "MAX_CONTENT_CHARS",
31
34
  "GuardrailEvent",
32
35
  "agent_span",
33
36
  "aid_attributes",
37
+ "content_capture_enabled",
34
38
  "get_tracer",
35
39
  "llm_span",
36
40
  "record_attributes",
41
+ "record_content",
37
42
  "record_cost",
38
43
  "record_exception",
39
44
  "record_guardrail",
@@ -87,8 +92,20 @@ ATTRIBUTES: dict[str, str] = {
87
92
  "guardrail_stage": "aid.guardrail.stage",
88
93
  "guardrail_action": "aid.guardrail.action",
89
94
  "guardrail_policies": "aid.guardrail.policies",
95
+ # Payload text. Written only when ``AID_TRACE_CONTENT`` asks for it; see
96
+ # :func:`record_content` for why the default is off.
97
+ "input_text": "aid.input.text",
98
+ "output_text": "aid.output.text",
90
99
  }
91
100
 
101
+ #: The environment variable that opts in to recording prompt and completion text.
102
+ CONTENT_ENV = "AID_TRACE_CONTENT"
103
+
104
+ #: Longest payload fragment a span records. A dataset needs enough of the input to
105
+ #: name the case, not a full transcript, and an unbounded attribute would put a
106
+ #: megabyte into one JSONL line.
107
+ MAX_CONTENT_CHARS = 4000
108
+
92
109
  _TRACER_NAME = "aid_runtime"
93
110
 
94
111
 
@@ -162,6 +179,41 @@ def record_attributes(span: Span, **values: Any) -> None:
162
179
  span.set_attribute(key, value)
163
180
 
164
181
 
182
+ def content_capture_enabled() -> bool:
183
+ """Whether ``AID_TRACE_CONTENT`` asks for prompt and completion text on spans."""
184
+ return os.environ.get(CONTENT_ENV, "").strip().lower() in {"1", "true", "yes", "on"}
185
+
186
+
187
+ def record_content(span: Span, *, input_text: str | None, output_text: str | None) -> None:
188
+ """Attach the prompt and the completion to a span **only** when asked to.
189
+
190
+ Everything else this runtime records is a fact about a call -- a model, a token
191
+ count, a price. Payloads are what a user said and what a model answered, so they
192
+ stay out of the trace unless the operator names :data:`CONTENT_ENV`. Three
193
+ reasons the default matters:
194
+
195
+ - The sink writes to a local directory that a repository may commit and a CI log
196
+ may echo, so text that is off by default cannot leak by accident.
197
+ - Nothing here redacts. A captured prompt is captured as it was sent, and the
198
+ operator who set the variable owns that decision; the spec's ``pii.redact``
199
+ governs the deployed feedback path, not this local switch.
200
+ - ``aid trace export --dataset`` is the one reader that wants the text, and it
201
+ can only build a case from a run that recorded one.
202
+
203
+ Empty and whitespace-only text is skipped, so a span that carried nothing does
204
+ not look like a decided empty answer.
205
+ """
206
+ if not content_capture_enabled():
207
+ return
208
+ for key, value in (
209
+ ("input_text", input_text),
210
+ ("output_text", output_text),
211
+ ):
212
+ if value is None or value.strip() == "":
213
+ continue
214
+ span.set_attribute(ATTRIBUTES[key], value[:MAX_CONTENT_CHARS])
215
+
216
+
165
217
  @contextlib.contextmanager
166
218
  def agent_span(
167
219
  *,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aid-runtime-python
3
- Version: 0.1.153
3
+ Version: 0.1.154
4
4
  Summary: The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline.
5
5
  Author: The AID Framework authors
6
6
  License-Expression: Apache-2.0
@@ -22,10 +22,12 @@ from aid_runtime import (
22
22
  ATTRIBUTES,
23
23
  GEN_AI_OPERATION_CHAT,
24
24
  TRACE_DIR_ENV,
25
+ CompletionRequest,
26
+ ModelGateway,
25
27
  local_trace_enabled,
26
28
  )
27
29
  from aid_runtime.local_trace import finish_span, wrap_span
28
- from aid_runtime.tracing import agent_span, get_tracer, llm_span, record_cost
30
+ from aid_runtime.tracing import CONTENT_ENV, agent_span, get_tracer, llm_span, record_cost
29
31
 
30
32
 
31
33
  class BoomError(Exception):
@@ -41,6 +43,11 @@ def _lines(directory: Path) -> list[dict[str, Any]]:
41
43
  return [json.loads(line) for line in path.read_text(encoding="utf-8").splitlines()]
42
44
 
43
45
 
46
+ def _clear(directory: Path) -> None:
47
+ for leftover in directory.glob("trace-*.jsonl"):
48
+ leftover.unlink()
49
+
50
+
44
51
  def test_the_sink_is_off_unless_a_directory_is_configured(monkeypatch: pytest.MonkeyPatch) -> None:
45
52
  monkeypatch.delenv(TRACE_DIR_ENV, raising=False)
46
53
 
@@ -153,3 +160,27 @@ def test_the_opentelemetry_path_still_records(
153
160
  assert recorded.name == f"{GEN_AI_OPERATION_CHAT} m"
154
161
  (line,) = _lines(tmp_path)
155
162
  assert line["name"] == recorded.name
163
+
164
+
165
+ async def test_the_gateway_captures_payloads_only_when_asked(
166
+ gateway: ModelGateway, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
167
+ ) -> None:
168
+ """A real gateway call is the only thing that proves the wiring, not the helper."""
169
+ monkeypatch.delenv(CONTENT_ENV, raising=False)
170
+ monkeypatch.setenv(TRACE_DIR_ENV, str(tmp_path))
171
+ await gateway.generate("small", CompletionRequest.prompt("what is it"))
172
+
173
+ calls = [record for record in _lines(tmp_path) if record["kind"] == "CLIENT"]
174
+ assert calls
175
+ assert all(ATTRIBUTES["input_text"] not in call["attributes"] for call in calls)
176
+ assert all(ATTRIBUTES["output_text"] not in call["attributes"] for call in calls)
177
+
178
+ # A second run in a clean directory, so the assertion isolates the captured call.
179
+ _clear(tmp_path)
180
+
181
+ monkeypatch.setenv(CONTENT_ENV, "1")
182
+ await gateway.generate("small", CompletionRequest.prompt("what is it"))
183
+
184
+ (captured,) = [record for record in _lines(tmp_path) if record["kind"] == "CLIENT"]
185
+ assert captured["attributes"][ATTRIBUTES["input_text"]] == "user: what is it"
186
+ assert str(captured["attributes"][ATTRIBUTES["output_text"]]).strip()
@@ -17,8 +17,12 @@ from opentelemetry.trace import SpanKind, StatusCode, Tracer
17
17
 
18
18
  from aid_runtime import ATTRIBUTES, GEN_AI_OPERATION_CHAT, TokenUsage, aid_attributes
19
19
  from aid_runtime.tracing import (
20
+ CONTENT_ENV,
21
+ MAX_CONTENT_CHARS,
22
+ content_capture_enabled,
20
23
  get_tracer,
21
24
  llm_span,
25
+ record_content,
22
26
  record_cost,
23
27
  record_exception,
24
28
  record_usage,
@@ -83,6 +87,8 @@ def test_framework_specific_attributes_stay_out_of_the_genai_namespace() -> None
83
87
  "aid.guardrail.stage",
84
88
  "aid.guardrail.action",
85
89
  "aid.guardrail.policies",
90
+ "aid.input.text",
91
+ "aid.output.text",
86
92
  }
87
93
 
88
94
 
@@ -221,3 +227,70 @@ def test_aid_attributes_renames_known_keys_and_passes_others_through() -> None:
221
227
  "aid.gateway.attempts": 2,
222
228
  "tenant_id": "acme",
223
229
  }
230
+
231
+
232
+ def test_content_capture_is_off_unless_the_variable_says_otherwise(
233
+ monkeypatch: pytest.MonkeyPatch,
234
+ ) -> None:
235
+ monkeypatch.delenv(CONTENT_ENV, raising=False)
236
+ assert content_capture_enabled() is False
237
+
238
+ for off in ("", "0", "false", "no", "off", " "):
239
+ monkeypatch.setenv(CONTENT_ENV, off)
240
+ assert content_capture_enabled() is False, off
241
+
242
+ for on in ("1", "true", "TRUE", " Yes ", "on"):
243
+ monkeypatch.setenv(CONTENT_ENV, on)
244
+ assert content_capture_enabled() is True, on
245
+
246
+
247
+ def test_payloads_are_not_recorded_when_capture_is_off(monkeypatch: pytest.MonkeyPatch) -> None:
248
+ monkeypatch.delenv(CONTENT_ENV, raising=False)
249
+ tracer, exporter = _recording_tracer()
250
+
251
+ with llm_span(model="m", provider="p", tracer=tracer) as span:
252
+ record_content(span, input_text="hello", output_text="hi")
253
+
254
+ attributes = _attributes_of(exporter)
255
+ assert "aid.input.text" not in attributes
256
+ assert "aid.output.text" not in attributes
257
+
258
+
259
+ def test_a_captured_prompt_and_completion_land_on_the_span(
260
+ monkeypatch: pytest.MonkeyPatch,
261
+ ) -> None:
262
+ monkeypatch.setenv(CONTENT_ENV, "1")
263
+ tracer, exporter = _recording_tracer()
264
+
265
+ with llm_span(model="m", provider="p", tracer=tracer) as span:
266
+ record_content(span, input_text="hello", output_text="hi")
267
+
268
+ attributes = _attributes_of(exporter)
269
+ assert attributes["aid.input.text"] == "hello"
270
+ assert attributes["aid.output.text"] == "hi"
271
+
272
+
273
+ def test_captured_text_is_truncated_to_the_cap(monkeypatch: pytest.MonkeyPatch) -> None:
274
+ monkeypatch.setenv(CONTENT_ENV, "1")
275
+ tracer, exporter = _recording_tracer()
276
+
277
+ with llm_span(model="m", provider="p", tracer=tracer) as span:
278
+ record_content(span, input_text="x" * (MAX_CONTENT_CHARS + 500), output_text=None)
279
+
280
+ attributes = _attributes_of(exporter)
281
+ assert attributes["aid.input.text"] == "x" * MAX_CONTENT_CHARS
282
+ assert "aid.output.text" not in attributes
283
+
284
+
285
+ def test_blank_payloads_are_omitted_rather_than_recorded_empty(
286
+ monkeypatch: pytest.MonkeyPatch,
287
+ ) -> None:
288
+ monkeypatch.setenv(CONTENT_ENV, "1")
289
+ tracer, exporter = _recording_tracer()
290
+
291
+ with llm_span(model="m", provider="p", tracer=tracer) as span:
292
+ record_content(span, input_text=" ", output_text="")
293
+
294
+ attributes = _attributes_of(exporter)
295
+ assert "aid.input.text" not in attributes
296
+ assert "aid.output.text" not in attributes