revefi-agent-test 0.1.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Revefi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,104 @@
1
+ Metadata-Version: 2.4
2
+ Name: revefi-agent-test
3
+ Version: 0.1.0
4
+ Summary: End-to-end agent testing — assert an agent's tools fired, via Revefi LLM observability
5
+ Author-email: Revefi <support@revefi.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/revefi/revefi-agent-test
8
+ Project-URL: Repository, https://github.com/revefi/revefi-agent-test
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Software Development :: Testing
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: requests>=2.31
18
+ Requires-Dist: pyyaml>=6.0
19
+ Dynamic: license-file
20
+
21
+ # revefi-agent-test
22
+
23
+ A small Python harness that **asserts an AI agent actually called the tools it was supposed to** —
24
+ verified against Revefi's LLM observability spans, not the answer text. Works for any agent
25
+ instrumented with `revefi-llm-sdk`.
26
+
27
+ Per case it: generates a per-run `test_prompt_id` → POSTs the case `body` to the agent's `url` with a
28
+ `test-prompt-id` header → polls Revefi's test-span-data API by that id → checks the run's span for the
29
+ `required_tools` → prints the result. Exit code is non-zero if any case fails.
30
+
31
+ ## Layout
32
+
33
+ ```
34
+ revefi_agent_test/__init__.py # all the logic + the CLI (run_test, AgentTestCase, RevefiConfig, main)
35
+ revefi_agent_test/__main__.py # lets you do `python -m revefi_agent_test`
36
+ examples/raden.yaml # a worked example config you copy and edit
37
+ pyproject.toml # package metadata (the `revefi-agent-test` command)
38
+ ```
39
+
40
+ ## Run it
41
+
42
+ ```bash
43
+ pip install -e . # from this repo (editable; no PyPI needed)
44
+ cp examples/raden.yaml my.yaml # copy the example, then edit the config block + cases
45
+ export REVEFI_API_KEY=… # or put api_key in the YAML (env wins over the file)
46
+ revefi-agent-test --config my.yaml
47
+ ```
48
+
49
+ ## The config (one generic format)
50
+
51
+ A single YAML file: a `config` block (how to reach Revefi to read spans back) plus `cases`, each
52
+ POSTing a `body` to a `url`.
53
+
54
+ ```yaml
55
+ config:
56
+ base_url: https://your-revefi-instance.com/v1 # Revefi public API base — used to read spans back
57
+ # api_key: "…" # or set REVEFI_API_KEY (env wins); never commit secrets
58
+
59
+ cases:
60
+ - name: web search
61
+ url: https://your-agent.example.com/run # the agent endpoint to drive
62
+ body: # POSTed to `url` verbatim — shape is up to the agent
63
+ input: "Who won the 2024 IPL final? Use web search."
64
+ required_tools:
65
+ - web_search_tool
66
+ ```
67
+
68
+ `body` is opaque — it's whatever the agent under test expects. `required_tools` is the whole point of
69
+ the test.
70
+
71
+ ## As a library
72
+
73
+ ```python
74
+ from revefi_agent_test import RevefiConfig, AgentTestCase, run_test
75
+
76
+ cfg = RevefiConfig(base_url="https://your-revefi-instance.com/v1", api_key="…")
77
+ cases = [
78
+ AgentTestCase(
79
+ name="web search",
80
+ url="https://your-agent.example.com/run",
81
+ body={"input": "Who won the 2024 IPL final? Use web search."},
82
+ required_tools=["web_search_tool"],
83
+ )
84
+ ]
85
+ assert all(r.passed for r in run_test(cfg, cases))
86
+ ```
87
+
88
+ ## How `test_prompt_id` reaches the agent
89
+
90
+ The harness attaches a per-run `test-prompt-id` **header** to every agent call. The agent reads it
91
+ off its inbound request and forwards it to `revefi_llm_sdk.set_request_test_prompt_id(...)` so the
92
+ run's spans get tagged — in the agent's own request handler, or in whatever gateway fronts it. The
93
+ harness never touches the `body`, so adopting this needs no change to your agent's request schema.
94
+
95
+ ## How tools are detected
96
+
97
+ Verification reads the run's latest `SPAN_KIND_CLIENT` span from Revefi's test-span-data API and collects
98
+ tool names from `extractedData.promptsList[*].toolCallsList[*].name` (and `completionsList[*]`),
99
+ comparing them against `required_tools`.
100
+
101
+ ## CI
102
+
103
+ Run it in CI by pointing `--config` at a YAML committed to your repo and injecting the API token via
104
+ a secret (the `REVEFI_API_KEY` env var) — never commit the token.
@@ -0,0 +1,84 @@
1
+ # revefi-agent-test
2
+
3
+ A small Python harness that **asserts an AI agent actually called the tools it was supposed to** —
4
+ verified against Revefi's LLM observability spans, not the answer text. Works for any agent
5
+ instrumented with `revefi-llm-sdk`.
6
+
7
+ Per case it: generates a per-run `test_prompt_id` → POSTs the case `body` to the agent's `url` with a
8
+ `test-prompt-id` header → polls Revefi's test-span-data API by that id → checks the run's span for the
9
+ `required_tools` → prints the result. Exit code is non-zero if any case fails.
10
+
11
+ ## Layout
12
+
13
+ ```
14
+ revefi_agent_test/__init__.py # all the logic + the CLI (run_test, AgentTestCase, RevefiConfig, main)
15
+ revefi_agent_test/__main__.py # lets you do `python -m revefi_agent_test`
16
+ examples/raden.yaml # a worked example config you copy and edit
17
+ pyproject.toml # package metadata (the `revefi-agent-test` command)
18
+ ```
19
+
20
+ ## Run it
21
+
22
+ ```bash
23
+ pip install -e . # from this repo (editable; no PyPI needed)
24
+ cp examples/raden.yaml my.yaml # copy the example, then edit the config block + cases
25
+ export REVEFI_API_KEY=… # or put api_key in the YAML (env wins over the file)
26
+ revefi-agent-test --config my.yaml
27
+ ```
28
+
29
+ ## The config (one generic format)
30
+
31
+ A single YAML file: a `config` block (how to reach Revefi to read spans back) plus `cases`, each
32
+ POSTing a `body` to a `url`.
33
+
34
+ ```yaml
35
+ config:
36
+ base_url: https://your-revefi-instance.com/v1 # Revefi public API base — used to read spans back
37
+ # api_key: "…" # or set REVEFI_API_KEY (env wins); never commit secrets
38
+
39
+ cases:
40
+ - name: web search
41
+ url: https://your-agent.example.com/run # the agent endpoint to drive
42
+ body: # POSTed to `url` verbatim — shape is up to the agent
43
+ input: "Who won the 2024 IPL final? Use web search."
44
+ required_tools:
45
+ - web_search_tool
46
+ ```
47
+
48
+ `body` is opaque — it's whatever the agent under test expects. `required_tools` is the whole point of
49
+ the test.
50
+
51
+ ## As a library
52
+
53
+ ```python
54
+ from revefi_agent_test import RevefiConfig, AgentTestCase, run_test
55
+
56
+ cfg = RevefiConfig(base_url="https://your-revefi-instance.com/v1", api_key="…")
57
+ cases = [
58
+ AgentTestCase(
59
+ name="web search",
60
+ url="https://your-agent.example.com/run",
61
+ body={"input": "Who won the 2024 IPL final? Use web search."},
62
+ required_tools=["web_search_tool"],
63
+ )
64
+ ]
65
+ assert all(r.passed for r in run_test(cfg, cases))
66
+ ```
67
+
68
+ ## How `test_prompt_id` reaches the agent
69
+
70
+ The harness attaches a per-run `test-prompt-id` **header** to every agent call. The agent reads it
71
+ off its inbound request and forwards it to `revefi_llm_sdk.set_request_test_prompt_id(...)` so the
72
+ run's spans get tagged — in the agent's own request handler, or in whatever gateway fronts it. The
73
+ harness never touches the `body`, so adopting this needs no change to your agent's request schema.
74
+
75
+ ## How tools are detected
76
+
77
+ Verification reads the run's latest `SPAN_KIND_CLIENT` span from Revefi's test-span-data API and collects
78
+ tool names from `extractedData.promptsList[*].toolCallsList[*].name` (and `completionsList[*]`),
79
+ comparing them against `required_tools`.
80
+
81
+ ## CI
82
+
83
+ Run it in CI by pointing `--config` at a YAML committed to your repo and injecting the API token via
84
+ a secret (the `REVEFI_API_KEY` env var) — never commit the token.
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "revefi-agent-test"
7
+ version = "0.1.0"
8
+ description = "End-to-end agent testing — assert an agent's tools fired, via Revefi LLM observability"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ authors = [{name = "Revefi", email = "support@revefi.com"}]
12
+ requires-python = ">=3.9"
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3",
18
+ "Topic :: Software Development :: Testing",
19
+ ]
20
+ dependencies = [
21
+ "requests>=2.31",
22
+ "pyyaml>=6.0",
23
+ ]
24
+
25
+ [project.urls]
26
+ Homepage = "https://github.com/revefi/revefi-agent-test"
27
+ Repository = "https://github.com/revefi/revefi-agent-test"
28
+
29
+ [project.scripts]
30
+ revefi-agent-test = "revefi_agent_test:main"
31
+
32
+ [tool.setuptools.packages.find]
33
+ where = ["."]
34
+ include = ["revefi_agent_test*"]
@@ -0,0 +1,273 @@
1
+ """revefi-agent-test — assert an AI agent's tools fired, verified via Revefi LLM observability.
2
+
3
+ A single YAML file holds a `config` block (base_url + api_key) and the `cases`. For each
4
+ case the harness generates a per-run test_prompt_id, POSTs the case body to its url with the
5
+ test-prompt-id header, polls Revefi's test-span-data API by that id, checks the run's span for the
6
+ required tools, and prints the result. The agent reads the header off its inbound request and
7
+ forwards it to revefi-llm-sdk. The api_key may be set in the YAML or via the REVEFI_API_KEY env
8
+ var.
9
+
10
+ revefi-agent-test --config my.yaml
11
+ """
12
+ from __future__ import annotations
13
+
14
+ import argparse
15
+ import json
16
+ import os
17
+ import time
18
+ import uuid
19
+ from dataclasses import dataclass, field
20
+ from typing import Optional
21
+
22
+ import requests
23
+
24
+ # The one header the test_prompt_id travels under, for every agent. The agent reads it off the
25
+ # inbound request and forwards it to revefi-llm-sdk's set_request_test_prompt_id so its spans get
26
+ # tagged — in the agent's own request handler, or in whatever gateway fronts it. Same name as the
27
+ # SDK's ingest header, so the id travels under one header (test-prompt-id) end to end.
28
+ TEST_ID_HEADER = "test-prompt-id"
29
+ SOURCE_APP_HEADER = {"X-Source-Application": "revefi-agent-test"}
30
+
31
+
32
+ # ──────────────────────────────── config + case models ────────────────────────────────
33
+ @dataclass
34
+ class AgentTestCase:
35
+ """One agent call to make plus the tools it must exercise.
36
+
37
+ `body` is the request payload sent to `url` verbatim — the harness is agnostic to its shape;
38
+ it's whatever the agent under test expects.
39
+ """
40
+
41
+ name: str
42
+ url: str # the agent endpoint to POST to, e.g. https://your-agent.example.com/run
43
+ body: dict = field(default_factory=dict) # request payload, sent as-is
44
+ required_tools: list[str] = field(default_factory=list)
45
+ max_latency_s: Optional[float] = None
46
+
47
+
48
+ @dataclass
49
+ class RevefiConfig:
50
+ """Connection to Revefi (to read spans back) + polling behavior, shared across cases."""
51
+
52
+ base_url: str # Revefi public API base, e.g. https://your-revefi-instance.com/v1
53
+ api_key: str # Revefi API token (Bearer); used for the span read and the agent call
54
+ answer_timeout_s: float = 120.0
55
+ poll_attempts: int = 12
56
+ poll_interval_s: float = 5.0
57
+
58
+
59
+ @dataclass
60
+ class AgentTestResult:
61
+ name: str
62
+ passed: bool
63
+ test_prompt_id: str
64
+ answer: Optional[str] = None
65
+ latency_s: Optional[float] = None
66
+ tools_fired: list[str] = field(default_factory=list)
67
+ missing_tools: list[str] = field(default_factory=list)
68
+ error: Optional[str] = None
69
+
70
+
71
+ # ──────────────────────────────── HTTP: call agent, read spans ────────────────────────────────
72
+ def _auth_headers(api_key: str) -> dict:
73
+ return {"Authorization": f"Bearer {api_key}", **SOURCE_APP_HEADER}
74
+
75
+
76
+ def _call_agent(
77
+ cfg: RevefiConfig, case: AgentTestCase, test_prompt_id: str
78
+ ) -> tuple[Optional[str], float]:
79
+ """POST the case body to the agent's url. Returns (answer, latency_s); raises on a non-200.
80
+
81
+ test_prompt_id always travels in the test-prompt-id header, for every agent; the agent reads
82
+ it off its inbound request and forwards it to revefi-llm-sdk's set_request_test_prompt_id.
83
+ The body is sent verbatim; the harness is agnostic to its shape.
84
+ """
85
+ headers = {**_auth_headers(cfg.api_key), TEST_ID_HEADER: test_prompt_id}
86
+ started = time.monotonic()
87
+ resp = requests.post(case.url, json=case.body, headers=headers, timeout=cfg.answer_timeout_s)
88
+ latency = time.monotonic() - started
89
+ if resp.status_code != 200:
90
+ raise RuntimeError(f"agent returned status {resp.status_code}: {resp.text}")
91
+ # Log the full response body verbatim; verification is via spans, not the answer text.
92
+ return resp.text or None, latency
93
+
94
+
95
+ def _poll_span(cfg: RevefiConfig, test_prompt_id: str) -> Optional[dict]:
96
+ """Poll Revefi test-span-data by test_prompt_id. Returns the span dict, or None if never ingested."""
97
+ url = f"{cfg.base_url.rstrip('/')}/observability/test-span-data"
98
+ headers = _auth_headers(cfg.api_key)
99
+ for attempt in range(1, cfg.poll_attempts + 1):
100
+ resp = requests.get(
101
+ url, params={"testPromptId": test_prompt_id}, headers=headers, timeout=30
102
+ )
103
+ if resp.status_code == 200:
104
+ span = (resp.json() or {}).get("span")
105
+ if span:
106
+ return span
107
+ elif resp.status_code != 404:
108
+ # 404 = not ingested yet (fine while polling); anything else is a real error.
109
+ raise RuntimeError(f"test-span-data returned {resp.status_code}: {resp.text}")
110
+ if attempt < cfg.poll_attempts:
111
+ time.sleep(cfg.poll_interval_s)
112
+ return None
113
+
114
+
115
+ def extract_tool_names(span: dict) -> list[str]:
116
+ """Executed tool names on a SPAN_KIND_CLIENT (LLM-call) span.
117
+
118
+ Tool calls live in extractedData.promptsList[*].toolCallsList[*].name and
119
+ completionsList[*].toolCallsList[*].name. Each LLM call carries the full prior
120
+ conversation in promptsList, so a tool requested in an earlier step is still present on the
121
+ latest client span.
122
+ """
123
+ data = (span or {}).get("extractedData") or {}
124
+ names: list[str] = []
125
+ seen: set[str] = set()
126
+ for bucket in (data.get("promptsList") or []) + (data.get("completionsList") or []):
127
+ for tool_call in bucket.get("toolCallsList") or []:
128
+ name = tool_call.get("name")
129
+ if name and name not in seen:
130
+ seen.add(name)
131
+ names.append(name)
132
+ return names
133
+
134
+
135
+ # ──────────────────────────────── run ────────────────────────────────
136
+ def run_case(cfg: RevefiConfig, case: AgentTestCase) -> AgentTestResult:
137
+ """Run one case end-to-end: drive the agent, then (if tools listed) verify them via spans."""
138
+ test_prompt_id = uuid.uuid4().hex
139
+ print(f"[{case.name}] test_prompt_id: {test_prompt_id}")
140
+ result = AgentTestResult(name=case.name, passed=False, test_prompt_id=test_prompt_id)
141
+
142
+ try:
143
+ answer, latency = _call_agent(cfg, case, test_prompt_id)
144
+ except requests.exceptions.ReadTimeout:
145
+ # Distinct from a failure: the agent WAS reached but didn't answer within the timeout.
146
+ result.error = (
147
+ f"agent timed out fetching the answer (no response within {cfg.answer_timeout_s:.0f}s; "
148
+ f"the agent may still finish and ingest spans afterward)"
149
+ )
150
+ print(f"Error: [{case.name}] {result.error}")
151
+ return result
152
+ except Exception as exc: # noqa: BLE001 — connection error, non-200, etc.
153
+ result.error = f"agent call failed: {exc}"
154
+ print(f"Error: [{case.name}] {result.error}")
155
+ return result
156
+ result.answer = answer
157
+ result.latency_s = latency
158
+ print(f"[{case.name}] answer: {answer}")
159
+ if case.max_latency_s is not None and latency > case.max_latency_s:
160
+ result.error = f"latency {latency:.1f}s exceeded max_latency_s {case.max_latency_s}"
161
+ print(f"Error: [{case.name}] {result.error}")
162
+ return result
163
+
164
+ if not case.required_tools:
165
+ result.passed = True
166
+ return result
167
+
168
+ span = _poll_span(cfg, test_prompt_id)
169
+ if span is None:
170
+ result.error = (
171
+ f"span not ingested within {cfg.poll_attempts * cfg.poll_interval_s:.0f}s "
172
+ f"for test_prompt_id={test_prompt_id}"
173
+ )
174
+ print(f"Error: [{case.name}] {result.error}")
175
+ return result
176
+
177
+ tool_names = extract_tool_names(span)
178
+ if not tool_names:
179
+ # No tool calls on the span — dump it so an unexpected shape is debuggable.
180
+ print(f"[{case.name}] no tool calls found on span. span={json.dumps(span)}")
181
+ missing = [t for t in case.required_tools if t not in tool_names]
182
+ result.tools_fired = tool_names
183
+ result.missing_tools = missing
184
+ for tool in case.required_tools:
185
+ if tool in missing:
186
+ print(f"Error: [{case.name}] required tool {tool} not fired; saw {tool_names}")
187
+ else:
188
+ print(f"[{case.name}] required tool {tool} fired")
189
+ result.passed = not missing
190
+ if missing:
191
+ result.error = f"required tools not fired: {missing}; saw {tool_names}"
192
+ return result
193
+
194
+
195
+ _SEPARATOR = "-" * 70
196
+
197
+
198
+ def run_test(cfg: RevefiConfig, cases: list[AgentTestCase]) -> list[AgentTestResult]:
199
+ """Run all cases sequentially. Prints per-case progress + a final tally. Returns results."""
200
+ results = []
201
+ for index, case in enumerate(cases, start=1):
202
+ print(f"\n{_SEPARATOR}\nCase {index}/{len(cases)}: {case.name}\n{_SEPARATOR}")
203
+ results.append(run_case(cfg, case))
204
+ passed = sum(1 for r in results if r.passed)
205
+ print(f"\n{_SEPARATOR}\n{passed}/{len(cases)} cases passed\n{_SEPARATOR}")
206
+ return results
207
+
208
+
209
+ # ──────────────────────────────── CLI ────────────────────────────────
210
+ def _load_yaml_config(path: str) -> tuple[RevefiConfig, list[AgentTestCase]]:
211
+ """Read the `config` block + `cases` from one YAML file.
212
+
213
+ base_url comes from the YAML (it's not a secret). api_key comes from the REVEFI_API_KEY env var
214
+ if set (CI injects the secret there, never committing it), else from the YAML config block (the
215
+ local-convenience path).
216
+ """
217
+ import yaml
218
+
219
+ with open(path, encoding="utf-8") as handle:
220
+ data = yaml.safe_load(handle) or {}
221
+ config = data.get("config") or {}
222
+ cfg = RevefiConfig(
223
+ base_url=config.get("base_url", ""),
224
+ api_key=os.environ.get("REVEFI_API_KEY") or config.get("api_key", ""),
225
+ answer_timeout_s=config.get("answer_timeout_s", 120.0),
226
+ poll_attempts=config.get("poll_attempts", 12),
227
+ poll_interval_s=config.get("poll_interval_s", 5.0),
228
+ )
229
+ cases = [
230
+ AgentTestCase(
231
+ name=c["name"],
232
+ url=c["url"],
233
+ body=c.get("body") or {},
234
+ required_tools=c.get("required_tools", []),
235
+ max_latency_s=c.get("max_latency_s"),
236
+ )
237
+ for c in data.get("cases", [])
238
+ ]
239
+ return cfg, cases
240
+
241
+
242
+ def main(argv: Optional[list[str]] = None) -> int:
243
+ parser = argparse.ArgumentParser(
244
+ description="Run tests against an agent; results are validated via Revefi observability."
245
+ )
246
+ parser.add_argument(
247
+ "--config", required=True, help="Path to a YAML config file (config block + cases)."
248
+ )
249
+ args = parser.parse_args(argv)
250
+
251
+ cfg, cases = _load_yaml_config(args.config)
252
+ if not cfg.base_url or not cfg.api_key:
253
+ parser.error(
254
+ "config.base_url is required in the YAML; api_key must be in the YAML config "
255
+ "or the REVEFI_API_KEY env var."
256
+ )
257
+ if not cases:
258
+ print("No cases defined.")
259
+ return 0
260
+
261
+ results = run_test(cfg, cases)
262
+ return 1 if any(not r.passed for r in results) else 0
263
+
264
+
265
+ __all__ = [
266
+ "AgentTestCase",
267
+ "AgentTestResult",
268
+ "RevefiConfig",
269
+ "extract_tool_names",
270
+ "run_case",
271
+ "run_test",
272
+ "main",
273
+ ]
@@ -0,0 +1,6 @@
1
+ """Allow ``python -m revefi_agent_test --config cases.yaml``."""
2
+ import sys
3
+
4
+ from revefi_agent_test import main
5
+
6
+ sys.exit(main())
@@ -0,0 +1,104 @@
1
+ Metadata-Version: 2.4
2
+ Name: revefi-agent-test
3
+ Version: 0.1.0
4
+ Summary: End-to-end agent testing — assert an agent's tools fired, via Revefi LLM observability
5
+ Author-email: Revefi <support@revefi.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/revefi/revefi-agent-test
8
+ Project-URL: Repository, https://github.com/revefi/revefi-agent-test
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Software Development :: Testing
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: requests>=2.31
18
+ Requires-Dist: pyyaml>=6.0
19
+ Dynamic: license-file
20
+
21
+ # revefi-agent-test
22
+
23
+ A small Python harness that **asserts an AI agent actually called the tools it was supposed to** —
24
+ verified against Revefi's LLM observability spans, not the answer text. Works for any agent
25
+ instrumented with `revefi-llm-sdk`.
26
+
27
+ Per case it: generates a per-run `test_prompt_id` → POSTs the case `body` to the agent's `url` with a
28
+ `test-prompt-id` header → polls Revefi's test-span-data API by that id → checks the run's span for the
29
+ `required_tools` → prints the result. Exit code is non-zero if any case fails.
30
+
31
+ ## Layout
32
+
33
+ ```
34
+ revefi_agent_test/__init__.py # all the logic + the CLI (run_test, AgentTestCase, RevefiConfig, main)
35
+ revefi_agent_test/__main__.py # lets you do `python -m revefi_agent_test`
36
+ examples/raden.yaml # a worked example config you copy and edit
37
+ pyproject.toml # package metadata (the `revefi-agent-test` command)
38
+ ```
39
+
40
+ ## Run it
41
+
42
+ ```bash
43
+ pip install -e . # from this repo (editable; no PyPI needed)
44
+ cp examples/raden.yaml my.yaml # copy the example, then edit the config block + cases
45
+ export REVEFI_API_KEY=… # or put api_key in the YAML (env wins over the file)
46
+ revefi-agent-test --config my.yaml
47
+ ```
48
+
49
+ ## The config (one generic format)
50
+
51
+ A single YAML file: a `config` block (how to reach Revefi to read spans back) plus `cases`, each
52
+ POSTing a `body` to a `url`.
53
+
54
+ ```yaml
55
+ config:
56
+ base_url: https://your-revefi-instance.com/v1 # Revefi public API base — used to read spans back
57
+ # api_key: "…" # or set REVEFI_API_KEY (env wins); never commit secrets
58
+
59
+ cases:
60
+ - name: web search
61
+ url: https://your-agent.example.com/run # the agent endpoint to drive
62
+ body: # POSTed to `url` verbatim — shape is up to the agent
63
+ input: "Who won the 2024 IPL final? Use web search."
64
+ required_tools:
65
+ - web_search_tool
66
+ ```
67
+
68
+ `body` is opaque — it's whatever the agent under test expects. `required_tools` is the whole point of
69
+ the test.
70
+
71
+ ## As a library
72
+
73
+ ```python
74
+ from revefi_agent_test import RevefiConfig, AgentTestCase, run_test
75
+
76
+ cfg = RevefiConfig(base_url="https://your-revefi-instance.com/v1", api_key="…")
77
+ cases = [
78
+ AgentTestCase(
79
+ name="web search",
80
+ url="https://your-agent.example.com/run",
81
+ body={"input": "Who won the 2024 IPL final? Use web search."},
82
+ required_tools=["web_search_tool"],
83
+ )
84
+ ]
85
+ assert all(r.passed for r in run_test(cfg, cases))
86
+ ```
87
+
88
+ ## How `test_prompt_id` reaches the agent
89
+
90
+ The harness attaches a per-run `test-prompt-id` **header** to every agent call. The agent reads it
91
+ off its inbound request and forwards it to `revefi_llm_sdk.set_request_test_prompt_id(...)` so the
92
+ run's spans get tagged — in the agent's own request handler, or in whatever gateway fronts it. The
93
+ harness never touches the `body`, so adopting this needs no change to your agent's request schema.
94
+
95
+ ## How tools are detected
96
+
97
+ Verification reads the run's latest `SPAN_KIND_CLIENT` span from Revefi's test-span-data API and collects
98
+ tool names from `extractedData.promptsList[*].toolCallsList[*].name` (and `completionsList[*]`),
99
+ comparing them against `required_tools`.
100
+
101
+ ## CI
102
+
103
+ Run it in CI by pointing `--config` at a YAML committed to your repo and injecting the API token via
104
+ a secret (the `REVEFI_API_KEY` env var) — never commit the token.
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ revefi_agent_test/__init__.py
5
+ revefi_agent_test/__main__.py
6
+ revefi_agent_test.egg-info/PKG-INFO
7
+ revefi_agent_test.egg-info/SOURCES.txt
8
+ revefi_agent_test.egg-info/dependency_links.txt
9
+ revefi_agent_test.egg-info/entry_points.txt
10
+ revefi_agent_test.egg-info/requires.txt
11
+ revefi_agent_test.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ revefi-agent-test = revefi_agent_test:main
@@ -0,0 +1,2 @@
1
+ requests>=2.31
2
+ pyyaml>=6.0
@@ -0,0 +1 @@
1
+ revefi_agent_test
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+