ambral-evals 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.
- ambral_evals-0.1.0/LICENSE +202 -0
- ambral_evals-0.1.0/PKG-INFO +218 -0
- ambral_evals-0.1.0/README.md +205 -0
- ambral_evals-0.1.0/pyproject.toml +70 -0
- ambral_evals-0.1.0/pyproject.toml.orig +56 -0
- ambral_evals-0.1.0/src/ambral_evals/__init__.py +21 -0
- ambral_evals-0.1.0/src/ambral_evals/_current.py +25 -0
- ambral_evals-0.1.0/src/ambral_evals/client.py +212 -0
- ambral_evals-0.1.0/src/ambral_evals/environment.py +92 -0
- ambral_evals-0.1.0/src/ambral_evals/errors.py +6 -0
- ambral_evals-0.1.0/src/ambral_evals/harbor.py +218 -0
- ambral_evals-0.1.0/src/ambral_evals/httpx.py +63 -0
- ambral_evals-0.1.0/src/ambral_evals/py.typed +0 -0
- ambral_evals-0.1.0/src/ambral_evals/queue.py +315 -0
- ambral_evals-0.1.0/src/ambral_evals/run.py +411 -0
- ambral_evals-0.1.0/src/ambral_evals/verifiers.py +262 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ambral-evals
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reports a suite's scenarios to Ambral: opens an offline run, hands each scenario's agent its headers, reports what the suite scored, and closes the run.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Typing :: Typed
|
|
9
|
+
Requires-Dist: httpx>=0.27,<1
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Project-URL: Repository, https://github.com/AmbralAI/Cerberus
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# ambral-evals
|
|
15
|
+
|
|
16
|
+
Reports an eval suite's scenarios to Ambral. Your harness runs each scenario and scores it; its agent's model calls go
|
|
17
|
+
through Ambral's Gateway, which serves them with the model the run chose and records them. The SDK opens a run, hands
|
|
18
|
+
each scenario's agent its headers, reports what the suite scored, and closes the run, which then reads with
|
|
19
|
+
`ambral runs show <run>`.
|
|
20
|
+
|
|
21
|
+
A run holds two things for each scenario it ran: its **result** (what the suite reported: whether it passed, its
|
|
22
|
+
rewards, the reasons for them) and its **calls** (the agent's model calls the Gateway recorded). A result can have no
|
|
23
|
+
calls (its agent called no model through the Gateway), and a session can have made calls but have no result (its report
|
|
24
|
+
was refused, or never sent): `ambral runs` reads both.
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
pip install ambral-evals
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Python 3.10 or later. Its one dependency is [httpx](https://www.python-httpx.org/).
|
|
31
|
+
|
|
32
|
+
## A verifiers eval
|
|
33
|
+
|
|
34
|
+
Run the eval with `ambral-verifiers`, naming the suite, then `vf-eval`'s own arguments:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
ambral-verifiers support-agent/refunds @ eval.toml
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
It opens the run, sets `AMBRAL_EVAL_HEADER` to its header, runs `vf-eval` in the same process, reports each episode as
|
|
41
|
+
it finishes, and closes the run. The eval's agent seat calls the Gateway, naming the header in its client:
|
|
42
|
+
|
|
43
|
+
```toml
|
|
44
|
+
model = "ambral/auto"
|
|
45
|
+
|
|
46
|
+
[env.agent.client]
|
|
47
|
+
type = "eval"
|
|
48
|
+
base_url = "https://app.ambral.ai/v1"
|
|
49
|
+
api_key_var = "AMBRAL_API_KEY"
|
|
50
|
+
headers_from_env = { x-ambral-eval = "AMBRAL_EVAL_HEADER" }
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- The trace of the seat whose client names the header is one run of its episode's scenario. A trace of another seat (a
|
|
54
|
+
simulated user, a judge) isn't reported. Give only the agent's seat the header, in its own client
|
|
55
|
+
(`[env.agent.client]`): an episode in which more than one seat sends it (as each does when the eval's own client
|
|
56
|
+
names it) isn't reported, and the run's close names it.
|
|
57
|
+
- verifiers sends each rollout's trace id as `X-Session-ID`, which is the session its calls are recorded under.
|
|
58
|
+
- A scenario's id is its task's `id`, or else its `name`, or else its index in the taskset, which holds only while the
|
|
59
|
+
taskset's order does: give each task an `id`.
|
|
60
|
+
- Its rewards, metrics, judge calls and errors are the trace's, and its task the episode's.
|
|
61
|
+
- `ambral-verifiers` reports what this invocation runs: a resumed eval (`--resume`) reports the rollouts it runs again,
|
|
62
|
+
into a run of its own unless `AMBRAL_EVAL_KEY` names the first one's key. With no arguments after the suite, `--help`
|
|
63
|
+
or `--dry-run`, `vf-eval` runs no rollout, and no run is opened.
|
|
64
|
+
- An episode that can't be reported is printed and named when the run closes; the eval goes on. It exits with
|
|
65
|
+
`vf-eval`'s code, or 1 when a scenario has no result, or when `vf-eval` wrote episodes `ambral-verifiers` wasn't
|
|
66
|
+
handed (a verifiers other than the one it was built against).
|
|
67
|
+
|
|
68
|
+
## A Harbor job
|
|
69
|
+
|
|
70
|
+
Run the job with the plugin, naming the suite:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
harbor run --plugin ambral_evals.harbor:Report \
|
|
74
|
+
--plugin-kwarg workload=support-agent --plugin-kwarg taskset=terminal-tasks ...
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Your agent class sends the headers `headers(self.context_id)` gives on each of its model calls:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from ambral_evals.harbor import headers
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class SupportAgent(BaseAgent):
|
|
84
|
+
async def run(self, instruction, environment, context):
|
|
85
|
+
client = AsyncOpenAI(base_url=gateway_url, default_headers=headers(self.context_id))
|
|
86
|
+
...
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- Each trial is one run of its task, whose name is the scenario's id. Its session is the trial's id (the agent's
|
|
90
|
+
`context_id`), which is new for each attempt.
|
|
91
|
+
- Its rewards are the verifier's (`reward.json`), and each reward's reason is what its criteria said of it, from the
|
|
92
|
+
trial's `verifier/reward-details.json` when the verifier wrote one (rewardkit does). An exception the trial recorded
|
|
93
|
+
is one of its errors.
|
|
94
|
+
- The run's key is the job's id, which a resumed job keeps: it reopens its run and reports the trials it runs now.
|
|
95
|
+
`--plugin-kwarg key=…` or `AMBRAL_EVAL_KEY` names another; `model=…` and `source=…` name the run's model and source.
|
|
96
|
+
- The run opens before any trial runs, and a run that can't be opened stops the job. A trial that can't be reported
|
|
97
|
+
is printed and named when the run closes; the job goes on.
|
|
98
|
+
|
|
99
|
+
## Any other harness
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from ambral_evals import open_run
|
|
103
|
+
|
|
104
|
+
with open_run("support-agent", "refunds", model="anthropic/claude-haiku-5-5") as run:
|
|
105
|
+
scenario = run.scenario("refunds/over-the-limit")
|
|
106
|
+
client = OpenAI(base_url=os.environ["AMBRAL_GATEWAY_URL"], default_headers=dict(scenario.headers))
|
|
107
|
+
# ... the agent runs ...
|
|
108
|
+
scenario.report({"passed": False, "rewards": {"solved": {"score": 0}}, "reasons": {"solved": "..."}})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- `run.scenario(id, session=...)` takes the agent's own session id, for an agent that names its sessions.
|
|
112
|
+
- `scenario.report(result)` returns once Ambral stored it; reports are sent together, about once a second.
|
|
113
|
+
`scenario.send(result)` queues it and returns a `concurrent.futures.Future` at once, for a harness that shouldn't
|
|
114
|
+
wait (`await asyncio.wrap_future(scenario.send(result))` in asyncio). A report queued is sent: cancelling the wait
|
|
115
|
+
(a timeout) doesn't take it back.
|
|
116
|
+
- `scenario.drop()` says a run of a scenario has no result to report (it was skipped), so the close doesn't ask for
|
|
117
|
+
one.
|
|
118
|
+
- `run.close()` (or the end of the `with` block) sends what is left, prints the run's id and how to read it, and raises
|
|
119
|
+
`ReportError` naming each scenario this process ran that has no result. A result that doesn't fit (a reward
|
|
120
|
+
outside 0 to 1, a `NaN` in its task) raises at `send` or `report`, before it is queued, so it never sinks another
|
|
121
|
+
scenario's report.
|
|
122
|
+
|
|
123
|
+
## What a result holds, and how it reads back
|
|
124
|
+
|
|
125
|
+
Each result is one run of one scenario, a `dict`. Every key is optional, but a result with neither `passed` nor a reward
|
|
126
|
+
says little.
|
|
127
|
+
|
|
128
|
+
| Key | Shape | What it holds |
|
|
129
|
+
| ------------- | -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
130
|
+
| `passed` | `bool` | The suite's own verdict. Left out, the run is judged by its scores alone. |
|
|
131
|
+
| `rewards` | `{name: {"score", "weight"?} \| None}` | `score` from 0 (fails) to 1 (passes); a score outside that is refused. `weight` from 0 to 1000, 1 when left out. `None` for a reward that didn't run. A suite that scores on another scale divides by it. |
|
|
132
|
+
| `metrics` | `{name: float \| None}` | What else the suite measures (turns, latency, its own cost): no bound. |
|
|
133
|
+
| `reasons` | `{name: str}` | Why a reward or metric got its value, by its name; at most 16,384 UTF-16 code units each. |
|
|
134
|
+
| `task` | verifiers' `TaskData` | The scenario's prompt, what it expects, and any keys of the suite's; at most 256 KiB as JSON. Sent once per scenario, then by its id. |
|
|
135
|
+
| `judge_calls` | verifiers' judge calls | Each judge exchange behind the scores, at most 64. |
|
|
136
|
+
| `errors` | `[{"type", "message"}]` | What failed while the scenario ran. |
|
|
137
|
+
|
|
138
|
+
Neither integration rescales a score: a verifiers or Harbor reward outside 0 to 1 refuses its scenario before it is
|
|
139
|
+
sent, naming the reward. Divide it by its scale in the suite, or record it as a metric.
|
|
140
|
+
|
|
141
|
+
How Ambral reads them back:
|
|
142
|
+
|
|
143
|
+
- **A run of a scenario's score** is the weighted mean of its rewards: `solved` 0.25 (weight 1) and `polite` 1
|
|
144
|
+
(weight 0.5) score 0.50.
|
|
145
|
+
- **`ambral runs show <run>`** gives the mean of those scores over the run, the pass tally from `passed`, and for each
|
|
146
|
+
reward its mean, median, how many runs scored it, how many runs and scenarios scored it below 1, and the reason
|
|
147
|
+
given for its lowest score.
|
|
148
|
+
- **`ambral runs verdicts <run>`** lists each reward of each run of a scenario with its reason; `--failed` keeps the
|
|
149
|
+
runs `passed` says failed, `--below <n>` and `--check <name>` filter by reward.
|
|
150
|
+
- **`ambral runs trace <run> <scenario>`** shows one run whole: its task, each reward with its reason, its metrics and
|
|
151
|
+
errors, and its calls.
|
|
152
|
+
- **`ambral runs export <run>`** writes each run of a scenario as verifiers' `Episode`, which verifiers and prime-rl
|
|
153
|
+
load.
|
|
154
|
+
|
|
155
|
+
Metrics are shown per run, in `runs trace` and `runs export`; `runs show` doesn't add them up.
|
|
156
|
+
|
|
157
|
+
## Handing the agent its headers
|
|
158
|
+
|
|
159
|
+
Every model call of a scenario's agent carries its headers, which the Gateway reads the run and the scenario from. Any
|
|
160
|
+
of three ways:
|
|
161
|
+
|
|
162
|
+
- as its model client's default headers (`default_headers=dict(scenario.headers)`);
|
|
163
|
+
- on each request (`extra_headers=dict(scenario.headers)`);
|
|
164
|
+
- through `ambral_evals.httpx`'s transport, for a client built once, at module scope, which adds the current
|
|
165
|
+
scenario's:
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
import httpx
|
|
169
|
+
from ambral_evals.httpx import Transport # AsyncTransport for an httpx.AsyncClient
|
|
170
|
+
|
|
171
|
+
client = OpenAI(base_url=os.environ["AMBRAL_GATEWAY_URL"], http_client=httpx.Client(transport=Transport()))
|
|
172
|
+
|
|
173
|
+
with scenario.current():
|
|
174
|
+
agent(client, "Refund invoice inv_123")
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The current scenario is the one whose `current()` block the call is made within, in the same thread or asyncio task,
|
|
178
|
+
or one started within it. A call through it outside a scenario is refused, rather than recorded as anything but the
|
|
179
|
+
run's.
|
|
180
|
+
|
|
181
|
+
Only the system under test's clients carry them: never a judge's, or a simulated user's.
|
|
182
|
+
|
|
183
|
+
The agent sends model `ambral/auto`, as it does in production. The headers name the run's workload, so a call that
|
|
184
|
+
names none is served the run's model. One that names another workload (`x-workload`, or `ambral/auto:<workload>`), such
|
|
185
|
+
as a second agent the first calls, is served that workload's primary, and is recorded under the run too.
|
|
186
|
+
|
|
187
|
+
## The environment
|
|
188
|
+
|
|
189
|
+
| Variable | What it says |
|
|
190
|
+
| -------------------- | ---------------------------------------------------------------------------------------------------- |
|
|
191
|
+
| `AMBRAL_API_KEY` | the org's API key, the one its agent calls the Gateway with. Required |
|
|
192
|
+
| `AMBRAL_URL` | where Ambral is served: `https://app.ambral.ai` when unset |
|
|
193
|
+
| `AMBRAL_EVAL_MODEL` | the model the run serves, any of the workload's pool, when the code names none: its primary if unset |
|
|
194
|
+
| `AMBRAL_EVAL_KEY` | the key the suite's processes share one run by (below) |
|
|
195
|
+
| `AMBRAL_EVAL_SOURCE` | `ci` or `local`, where the code names none |
|
|
196
|
+
|
|
197
|
+
A CI matrix over models sets `AMBRAL_EVAL_MODEL` per job, with no change to the code.
|
|
198
|
+
|
|
199
|
+
## One run per invocation, on CI
|
|
200
|
+
|
|
201
|
+
Shards, workers and matrix jobs of one CI run report to one run: each opens it by the same key, taskset and model, and
|
|
202
|
+
it completes once each has closed it. The key is the CI's own id for the workflow run:
|
|
203
|
+
|
|
204
|
+
- GitHub Actions: the run's id and attempt, so re-running failed jobs is a new run, holding only the jobs run again;
|
|
205
|
+
- GitLab CI: the pipeline's id; CircleCI: the workflow's; Buildkite: the build's. A retried job there keeps that id,
|
|
206
|
+
so it reports into the same run, and its scenarios gain repeats. Set `AMBRAL_EVAL_KEY` to tell its attempts apart;
|
|
207
|
+
- Jenkins and Azure Pipelines don't set `CI`: set `AMBRAL_EVAL_SOURCE=ci`, and `AMBRAL_EVAL_KEY` to the pipeline run's
|
|
208
|
+
id.
|
|
209
|
+
|
|
210
|
+
Elsewhere, each invocation opens a run of its own. A fixed `AMBRAL_EVAL_KEY` opens the same run every time, again once
|
|
211
|
+
it completed, so make it unique per invocation. A Harbor job's run is keyed by the job's id instead (above).
|
|
212
|
+
|
|
213
|
+
A run records where it ran: `ci` when `CI` is set (to anything but `0` or `false`), and `local` otherwise. A suite's
|
|
214
|
+
history leaves local runs out unless asked for them.
|
|
215
|
+
|
|
216
|
+
## License
|
|
217
|
+
|
|
218
|
+
Apache-2.0.
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# ambral-evals
|
|
2
|
+
|
|
3
|
+
Reports an eval suite's scenarios to Ambral. Your harness runs each scenario and scores it; its agent's model calls go
|
|
4
|
+
through Ambral's Gateway, which serves them with the model the run chose and records them. The SDK opens a run, hands
|
|
5
|
+
each scenario's agent its headers, reports what the suite scored, and closes the run, which then reads with
|
|
6
|
+
`ambral runs show <run>`.
|
|
7
|
+
|
|
8
|
+
A run holds two things for each scenario it ran: its **result** (what the suite reported: whether it passed, its
|
|
9
|
+
rewards, the reasons for them) and its **calls** (the agent's model calls the Gateway recorded). A result can have no
|
|
10
|
+
calls (its agent called no model through the Gateway), and a session can have made calls but have no result (its report
|
|
11
|
+
was refused, or never sent): `ambral runs` reads both.
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pip install ambral-evals
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Python 3.10 or later. Its one dependency is [httpx](https://www.python-httpx.org/).
|
|
18
|
+
|
|
19
|
+
## A verifiers eval
|
|
20
|
+
|
|
21
|
+
Run the eval with `ambral-verifiers`, naming the suite, then `vf-eval`'s own arguments:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
ambral-verifiers support-agent/refunds @ eval.toml
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
It opens the run, sets `AMBRAL_EVAL_HEADER` to its header, runs `vf-eval` in the same process, reports each episode as
|
|
28
|
+
it finishes, and closes the run. The eval's agent seat calls the Gateway, naming the header in its client:
|
|
29
|
+
|
|
30
|
+
```toml
|
|
31
|
+
model = "ambral/auto"
|
|
32
|
+
|
|
33
|
+
[env.agent.client]
|
|
34
|
+
type = "eval"
|
|
35
|
+
base_url = "https://app.ambral.ai/v1"
|
|
36
|
+
api_key_var = "AMBRAL_API_KEY"
|
|
37
|
+
headers_from_env = { x-ambral-eval = "AMBRAL_EVAL_HEADER" }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- The trace of the seat whose client names the header is one run of its episode's scenario. A trace of another seat (a
|
|
41
|
+
simulated user, a judge) isn't reported. Give only the agent's seat the header, in its own client
|
|
42
|
+
(`[env.agent.client]`): an episode in which more than one seat sends it (as each does when the eval's own client
|
|
43
|
+
names it) isn't reported, and the run's close names it.
|
|
44
|
+
- verifiers sends each rollout's trace id as `X-Session-ID`, which is the session its calls are recorded under.
|
|
45
|
+
- A scenario's id is its task's `id`, or else its `name`, or else its index in the taskset, which holds only while the
|
|
46
|
+
taskset's order does: give each task an `id`.
|
|
47
|
+
- Its rewards, metrics, judge calls and errors are the trace's, and its task the episode's.
|
|
48
|
+
- `ambral-verifiers` reports what this invocation runs: a resumed eval (`--resume`) reports the rollouts it runs again,
|
|
49
|
+
into a run of its own unless `AMBRAL_EVAL_KEY` names the first one's key. With no arguments after the suite, `--help`
|
|
50
|
+
or `--dry-run`, `vf-eval` runs no rollout, and no run is opened.
|
|
51
|
+
- An episode that can't be reported is printed and named when the run closes; the eval goes on. It exits with
|
|
52
|
+
`vf-eval`'s code, or 1 when a scenario has no result, or when `vf-eval` wrote episodes `ambral-verifiers` wasn't
|
|
53
|
+
handed (a verifiers other than the one it was built against).
|
|
54
|
+
|
|
55
|
+
## A Harbor job
|
|
56
|
+
|
|
57
|
+
Run the job with the plugin, naming the suite:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
harbor run --plugin ambral_evals.harbor:Report \
|
|
61
|
+
--plugin-kwarg workload=support-agent --plugin-kwarg taskset=terminal-tasks ...
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Your agent class sends the headers `headers(self.context_id)` gives on each of its model calls:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from ambral_evals.harbor import headers
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class SupportAgent(BaseAgent):
|
|
71
|
+
async def run(self, instruction, environment, context):
|
|
72
|
+
client = AsyncOpenAI(base_url=gateway_url, default_headers=headers(self.context_id))
|
|
73
|
+
...
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- Each trial is one run of its task, whose name is the scenario's id. Its session is the trial's id (the agent's
|
|
77
|
+
`context_id`), which is new for each attempt.
|
|
78
|
+
- Its rewards are the verifier's (`reward.json`), and each reward's reason is what its criteria said of it, from the
|
|
79
|
+
trial's `verifier/reward-details.json` when the verifier wrote one (rewardkit does). An exception the trial recorded
|
|
80
|
+
is one of its errors.
|
|
81
|
+
- The run's key is the job's id, which a resumed job keeps: it reopens its run and reports the trials it runs now.
|
|
82
|
+
`--plugin-kwarg key=…` or `AMBRAL_EVAL_KEY` names another; `model=…` and `source=…` name the run's model and source.
|
|
83
|
+
- The run opens before any trial runs, and a run that can't be opened stops the job. A trial that can't be reported
|
|
84
|
+
is printed and named when the run closes; the job goes on.
|
|
85
|
+
|
|
86
|
+
## Any other harness
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from ambral_evals import open_run
|
|
90
|
+
|
|
91
|
+
with open_run("support-agent", "refunds", model="anthropic/claude-haiku-5-5") as run:
|
|
92
|
+
scenario = run.scenario("refunds/over-the-limit")
|
|
93
|
+
client = OpenAI(base_url=os.environ["AMBRAL_GATEWAY_URL"], default_headers=dict(scenario.headers))
|
|
94
|
+
# ... the agent runs ...
|
|
95
|
+
scenario.report({"passed": False, "rewards": {"solved": {"score": 0}}, "reasons": {"solved": "..."}})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
- `run.scenario(id, session=...)` takes the agent's own session id, for an agent that names its sessions.
|
|
99
|
+
- `scenario.report(result)` returns once Ambral stored it; reports are sent together, about once a second.
|
|
100
|
+
`scenario.send(result)` queues it and returns a `concurrent.futures.Future` at once, for a harness that shouldn't
|
|
101
|
+
wait (`await asyncio.wrap_future(scenario.send(result))` in asyncio). A report queued is sent: cancelling the wait
|
|
102
|
+
(a timeout) doesn't take it back.
|
|
103
|
+
- `scenario.drop()` says a run of a scenario has no result to report (it was skipped), so the close doesn't ask for
|
|
104
|
+
one.
|
|
105
|
+
- `run.close()` (or the end of the `with` block) sends what is left, prints the run's id and how to read it, and raises
|
|
106
|
+
`ReportError` naming each scenario this process ran that has no result. A result that doesn't fit (a reward
|
|
107
|
+
outside 0 to 1, a `NaN` in its task) raises at `send` or `report`, before it is queued, so it never sinks another
|
|
108
|
+
scenario's report.
|
|
109
|
+
|
|
110
|
+
## What a result holds, and how it reads back
|
|
111
|
+
|
|
112
|
+
Each result is one run of one scenario, a `dict`. Every key is optional, but a result with neither `passed` nor a reward
|
|
113
|
+
says little.
|
|
114
|
+
|
|
115
|
+
| Key | Shape | What it holds |
|
|
116
|
+
| ------------- | -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
117
|
+
| `passed` | `bool` | The suite's own verdict. Left out, the run is judged by its scores alone. |
|
|
118
|
+
| `rewards` | `{name: {"score", "weight"?} \| None}` | `score` from 0 (fails) to 1 (passes); a score outside that is refused. `weight` from 0 to 1000, 1 when left out. `None` for a reward that didn't run. A suite that scores on another scale divides by it. |
|
|
119
|
+
| `metrics` | `{name: float \| None}` | What else the suite measures (turns, latency, its own cost): no bound. |
|
|
120
|
+
| `reasons` | `{name: str}` | Why a reward or metric got its value, by its name; at most 16,384 UTF-16 code units each. |
|
|
121
|
+
| `task` | verifiers' `TaskData` | The scenario's prompt, what it expects, and any keys of the suite's; at most 256 KiB as JSON. Sent once per scenario, then by its id. |
|
|
122
|
+
| `judge_calls` | verifiers' judge calls | Each judge exchange behind the scores, at most 64. |
|
|
123
|
+
| `errors` | `[{"type", "message"}]` | What failed while the scenario ran. |
|
|
124
|
+
|
|
125
|
+
Neither integration rescales a score: a verifiers or Harbor reward outside 0 to 1 refuses its scenario before it is
|
|
126
|
+
sent, naming the reward. Divide it by its scale in the suite, or record it as a metric.
|
|
127
|
+
|
|
128
|
+
How Ambral reads them back:
|
|
129
|
+
|
|
130
|
+
- **A run of a scenario's score** is the weighted mean of its rewards: `solved` 0.25 (weight 1) and `polite` 1
|
|
131
|
+
(weight 0.5) score 0.50.
|
|
132
|
+
- **`ambral runs show <run>`** gives the mean of those scores over the run, the pass tally from `passed`, and for each
|
|
133
|
+
reward its mean, median, how many runs scored it, how many runs and scenarios scored it below 1, and the reason
|
|
134
|
+
given for its lowest score.
|
|
135
|
+
- **`ambral runs verdicts <run>`** lists each reward of each run of a scenario with its reason; `--failed` keeps the
|
|
136
|
+
runs `passed` says failed, `--below <n>` and `--check <name>` filter by reward.
|
|
137
|
+
- **`ambral runs trace <run> <scenario>`** shows one run whole: its task, each reward with its reason, its metrics and
|
|
138
|
+
errors, and its calls.
|
|
139
|
+
- **`ambral runs export <run>`** writes each run of a scenario as verifiers' `Episode`, which verifiers and prime-rl
|
|
140
|
+
load.
|
|
141
|
+
|
|
142
|
+
Metrics are shown per run, in `runs trace` and `runs export`; `runs show` doesn't add them up.
|
|
143
|
+
|
|
144
|
+
## Handing the agent its headers
|
|
145
|
+
|
|
146
|
+
Every model call of a scenario's agent carries its headers, which the Gateway reads the run and the scenario from. Any
|
|
147
|
+
of three ways:
|
|
148
|
+
|
|
149
|
+
- as its model client's default headers (`default_headers=dict(scenario.headers)`);
|
|
150
|
+
- on each request (`extra_headers=dict(scenario.headers)`);
|
|
151
|
+
- through `ambral_evals.httpx`'s transport, for a client built once, at module scope, which adds the current
|
|
152
|
+
scenario's:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
import httpx
|
|
156
|
+
from ambral_evals.httpx import Transport # AsyncTransport for an httpx.AsyncClient
|
|
157
|
+
|
|
158
|
+
client = OpenAI(base_url=os.environ["AMBRAL_GATEWAY_URL"], http_client=httpx.Client(transport=Transport()))
|
|
159
|
+
|
|
160
|
+
with scenario.current():
|
|
161
|
+
agent(client, "Refund invoice inv_123")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The current scenario is the one whose `current()` block the call is made within, in the same thread or asyncio task,
|
|
165
|
+
or one started within it. A call through it outside a scenario is refused, rather than recorded as anything but the
|
|
166
|
+
run's.
|
|
167
|
+
|
|
168
|
+
Only the system under test's clients carry them: never a judge's, or a simulated user's.
|
|
169
|
+
|
|
170
|
+
The agent sends model `ambral/auto`, as it does in production. The headers name the run's workload, so a call that
|
|
171
|
+
names none is served the run's model. One that names another workload (`x-workload`, or `ambral/auto:<workload>`), such
|
|
172
|
+
as a second agent the first calls, is served that workload's primary, and is recorded under the run too.
|
|
173
|
+
|
|
174
|
+
## The environment
|
|
175
|
+
|
|
176
|
+
| Variable | What it says |
|
|
177
|
+
| -------------------- | ---------------------------------------------------------------------------------------------------- |
|
|
178
|
+
| `AMBRAL_API_KEY` | the org's API key, the one its agent calls the Gateway with. Required |
|
|
179
|
+
| `AMBRAL_URL` | where Ambral is served: `https://app.ambral.ai` when unset |
|
|
180
|
+
| `AMBRAL_EVAL_MODEL` | the model the run serves, any of the workload's pool, when the code names none: its primary if unset |
|
|
181
|
+
| `AMBRAL_EVAL_KEY` | the key the suite's processes share one run by (below) |
|
|
182
|
+
| `AMBRAL_EVAL_SOURCE` | `ci` or `local`, where the code names none |
|
|
183
|
+
|
|
184
|
+
A CI matrix over models sets `AMBRAL_EVAL_MODEL` per job, with no change to the code.
|
|
185
|
+
|
|
186
|
+
## One run per invocation, on CI
|
|
187
|
+
|
|
188
|
+
Shards, workers and matrix jobs of one CI run report to one run: each opens it by the same key, taskset and model, and
|
|
189
|
+
it completes once each has closed it. The key is the CI's own id for the workflow run:
|
|
190
|
+
|
|
191
|
+
- GitHub Actions: the run's id and attempt, so re-running failed jobs is a new run, holding only the jobs run again;
|
|
192
|
+
- GitLab CI: the pipeline's id; CircleCI: the workflow's; Buildkite: the build's. A retried job there keeps that id,
|
|
193
|
+
so it reports into the same run, and its scenarios gain repeats. Set `AMBRAL_EVAL_KEY` to tell its attempts apart;
|
|
194
|
+
- Jenkins and Azure Pipelines don't set `CI`: set `AMBRAL_EVAL_SOURCE=ci`, and `AMBRAL_EVAL_KEY` to the pipeline run's
|
|
195
|
+
id.
|
|
196
|
+
|
|
197
|
+
Elsewhere, each invocation opens a run of its own. A fixed `AMBRAL_EVAL_KEY` opens the same run every time, again once
|
|
198
|
+
it completed, so make it unique per invocation. A Harbor job's run is keyed by the job's id instead (above).
|
|
199
|
+
|
|
200
|
+
A run records where it ran: `ci` when `CI` is set (to anything but `0` or `false`), and `local` otherwise. A suite's
|
|
201
|
+
history leaves local runs out unless asked for them.
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
Apache-2.0.
|