agnost-evals
Run the rows of an Agnost AI experiment's dataset through your own agent, on your machine or in CI. Agnost sends the rows, your agent answers each one, and Agnost scores the answers with the experiment's evaluators. Your agent runs only on your infrastructure and sees each row's input and metadata, never its expected output.
pip install agnost-evals
Requires Python 3.10 or newer. It has no dependencies.
Write an adapter
The adapter is the one function you write. It receives a row's input, sets up
your agent from it, runs the agent, and returns the agent's final text. It can be
a plain or an async function.
# experiment.py
from agnost_evals import run_experiment
from booking import booking_agent
async def adapter(input, context):
reply = await booking_agent.run(input)
return reply.text
run_experiment(adapter)
When a row times out or the run is cancelled, an async adapter is cancelled
with asyncio.CancelledError. A plain function runs on its own thread and is not
stopped; check context.cancelled, a threading.Event, to stop it early.
context also carries the row's row_id and its metadata, the row's metadata
dict from the dataset ({} when it has none). Use it for per-row setup that isn't
part of the user's message, such as a customer tier or locale:
async def adapter(input, context):
agent = booking_agent.with_tier(context.metadata.get("tier"))
reply = await agent.run(input)
return reply.text
All async adapters run on one event loop for the whole run, so clients your
agent creates once, such as AsyncOpenAI, keep working from row to row. Call
run_experiment from synchronous code, such as the top level of your script,
not from inside asyncio.run.
Run an experiment
export AGNOST_API_KEY=agnost_... # your project's API key
python experiment.py --experiment-id 7f3e2a10-5c4b-4d8e-9a61-2b0c8d4e6f19
agnost-evals: started run 0b7c5d1e-2f3a-4b6c-8d9e-1a2b3c4d5e6f of experiment 7f3e2a10-5c4b-4d8e-9a61-2b0c8d4e6f19: 2 rows
✓ [1/2] 3c2b1a09-8f7e-4d6c-b5a4-0e9d8c7b6a51 2.4s Booked BK123: 3 nights in Mumbai for ₹7,500.
✗ [2/2] 4d3c2b1a-9e8f-4a7b-8c6d-1f0e9d8c7b62 120.0s Timed out after 120s
2 rows: 1 answered, 1 failed.
Failed rows:
4d3c2b1a-9e8f-4a7b-8c6d-1f0e9d8c7b62: Timed out after 120s
Reported 2 of 2 responses to Agnost (run 0b7c5d1e-2f3a-4b6c-8d9e-1a2b3c4d5e6f).
Agnost scores them with the experiment's evaluators.
Each command starts a new run. Each row's response is sent to Agnost as soon as the row finishes, so if the run stops partway, the rows already reported stay saved in that run. Scores appear in Agnost; the SDK doesn't wait for them.
If Agnost can't be reached, times out, or answers with a 5xx, 409, or 429, the request is retried, up to 4 attempts. A 409 that persists means the row already has a different response; start a new run instead. Any other error stops the run with Agnost's reason, such as "Agnost at https://api.agnost.ai rejected the API key (401: Invalid API key); check AGNOST_API_KEY and AGNOST_ENDPOINT". A rejected API key or a missing experiment names the endpoint, because a key or experiment from another Agnost environment fails the same way. The API key is never printed. If starting a run times out and is retried, Agnost can keep an extra run with no responses.
Try an adapter on rows from a file
A rows file runs your adapter without Agnost, so you can build and check it first. Nothing is sent anywhere.
[
{ "id": "mumbai-budget", "input": { "destination": "Mumbai", "budget": 8000 } },
{ "id": "bk91-upgrade", "input": "Upgrade booking BK91 to business class." }
]
python experiment.py --rows-file rows.json
agnost-evals: running 2 rows from rows.json
✓ [1/2] mumbai-budget 2.4s Booked BK123: 3 nights in Mumbai for ₹7,500.
✗ [2/2] bk91-upgrade 120.0s Timed out after 120s
2 rows: 1 answered, 1 failed.
Failed rows:
bk91-upgrade: Timed out after 120s
Local run: nothing was sent to Agnost.
Each row needs a unique id and an input, which can be any JSON value, and may
have a metadata object. Rows have the same shape as Agnost's dataset rows, so a
saved start-run response, an object with a rows list, works as a rows file too;
other fields are ignored.
Rows run one at a time, in file order.
What is recorded for each row
| What the adapter does | Answer | Error |
|---|---|---|
| Returns a string | The string, even if empty | none |
| Returns any other value | The value as JSON | none |
Returns None |
none | The adapter returned no answer |
| Raises | none | The exception's type and message, such as KeyError: 'customer_id' |
| Returns more than 100,000 characters | none | The answer's length |
Runs past timeout |
none | Timed out after 120s |
| Is running when you press Ctrl+C | none | Cancelled |
Pydantic models and dataclasses are sent as JSON too. Rows not reached after
Ctrl+C are recorded as Not run: cancelled, and in an experiment run they are
still reported, so every row in the run gets a response. A second Ctrl+C exits
immediately with code 130, without reporting the rest. Errors longer than 4,000
characters are truncated.
An async adapter that makes a blocking call, such as a request with a
synchronous HTTP client, holds up the event loop, so the timeout can't stop it.
When its answer arrives late it is recorded as Timed out, and a second Ctrl+C
still exits. Make blocking calls from a plain function, which runs on its own
thread.
Exit codes
run_experiment exits the process when the run ends.
| Code | Meaning |
|---|---|
0 |
Every row answered |
1 |
At least one row failed |
2 |
The run couldn't start, a response couldn't be reported to Agnost, or the run was cancelled |
Exit code 0 means every row produced an answer, not that the answers are good.
Pass exit=False to get a RunResult with the exit code, each row's result, and
the run_id of an experiment run instead.
Options
| Option | Default | |
|---|---|---|
adapter |
required | Your function, called once per row as adapter(input, context) |
experiment_id |
--experiment-id argument |
The Agnost experiment to run |
api_key |
AGNOST_API_KEY |
Your project's API key |
endpoint |
AGNOST_ENDPOINT, then https://api.agnost.ai |
The Agnost API |
rows_file |
--rows-file argument |
JSON file of rows to run locally instead |
timeout |
120 |
Seconds one row may run |
cancel |
none | A threading.Event that cancels the run when set, like Ctrl+C |
argv |
sys.argv[1:] |
Arguments to read --experiment-id and --rows-file from; flags it doesn't know are ignored |
exit |
True |
Exit the process with the exit code; False returns the result |
Pass either an experiment ID or a rows file, not both.
Example
examples/ has a hotel booking agent, its adapter, and a rows
file. The agent follows fixed rules instead of calling a model, so it runs
without an API key. The tests run it on every change, and every release runs it
against the built wheel:
pip install agnost-evals
python examples/experiment.py --rows-file examples/rows.json
Metadata
Release files for agnost-evals 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agnost_evals-0.1.0.tar.gz | 28.2 kB | Without provenance | Details for agnost_evals-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agnost_evals-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for agnost_evals-0.1.0-py3-none-any.whl |
Total release size: 44.8 kB
Release files / agnost_evals-0.1.0.tar.gz
| Download URL | agnost_evals-0.1.0.tar.gz |
|---|---|
| Size | 28.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b2d8d282e409e74c56ca8dddbae7b74760ef4f1e5de6cd5e14b90f87888794d
|
|
BLAKE2b-256 checksum How to use checksums |
8ba088b3479b0654266f3980f5d9395d95d30af127ee1820657cf914a6f9e9e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / agnost_evals-0.1.0-py3-none-any.whl
| Download URL | agnost_evals-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f95b8ac248d313954f96712f07026c373019c3e6278573532f7581a2fecae97
|
|
BLAKE2b-256 checksum How to use checksums |
4d160abb5cf2d0a0750cc1bc9ef6a36b4dbffe22c334c6db3fbfe9feb418466a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for agnost-evals 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.