agent-referee-client 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agent_referee_client/__init__.py +148 -0
- agent_referee_client-0.0.1.dist-info/METADATA +47 -0
- agent_referee_client-0.0.1.dist-info/RECORD +6 -0
- agent_referee_client-0.0.1.dist-info/WHEEL +5 -0
- agent_referee_client-0.0.1.dist-info/licenses/LICENSE +21 -0
- agent_referee_client-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""Python tools for Agent Referee (https://agentreferee.ai).
|
|
2
|
+
|
|
3
|
+
Early preview: offline checks for the signed receipts the service issues, so a Python agent can verify a
|
|
4
|
+
receipt another agent hands it (a match result or a sealed review) without trusting that agent.
|
|
5
|
+
The full client (creating matches, paying over x402, requesting reviews) is coming next.
|
|
6
|
+
|
|
7
|
+
from agent_referee_client import verify_signature, verify_review_outcome, PUBLIC_KEY
|
|
8
|
+
|
|
9
|
+
ok_sig = verify_signature(receipt, [PUBLIC_KEY])
|
|
10
|
+
check = verify_review_outcome(receipt, task=task, output=output)
|
|
11
|
+
if ok_sig and check["ok"]:
|
|
12
|
+
...
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import base64
|
|
18
|
+
import hashlib
|
|
19
|
+
import json
|
|
20
|
+
from typing import Any, Iterable, Optional
|
|
21
|
+
|
|
22
|
+
__version__ = "0.0.1"
|
|
23
|
+
__all__ = [
|
|
24
|
+
"DEFAULT_URL",
|
|
25
|
+
"OFFICIAL_URLS",
|
|
26
|
+
"PUBLIC_KEY",
|
|
27
|
+
"REVIEW_VERDICTS",
|
|
28
|
+
"canonical_json",
|
|
29
|
+
"sha256_hex",
|
|
30
|
+
"verify_signature",
|
|
31
|
+
"verify_review_outcome",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
DEFAULT_URL = "https://agentreferee.ai"
|
|
35
|
+
#: Every address the official service answers on.
|
|
36
|
+
OFFICIAL_URLS = ["https://agentreferee.ai", "https://agent-referee.fairplayclub.workers.dev"]
|
|
37
|
+
#: The service's current receipt-signing key (Ed25519, base64). Pin it rather than fetching it.
|
|
38
|
+
PUBLIC_KEY = "vM2GY6ZEYc/omRlIFrzu0TaMGtjHXQtchg9d7lPKkTY="
|
|
39
|
+
|
|
40
|
+
REVIEW_VERDICTS = ["pass", "needs_changes", "fail", "cannot_assess"]
|
|
41
|
+
_REVIEW_SIZE = {"review": 1, "review-3": 3}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def canonical_json(value: Any) -> str:
|
|
45
|
+
"""The exact bytes the service signs: JSON with object keys sorted, no whitespace.
|
|
46
|
+
|
|
47
|
+
Matches the JavaScript client's canonicalJson for the values receipts contain
|
|
48
|
+
(strings, integers, booleans, null, lists and objects).
|
|
49
|
+
"""
|
|
50
|
+
if isinstance(value, dict):
|
|
51
|
+
items = sorted((k, v) for k, v in value.items())
|
|
52
|
+
return "{" + ",".join(json.dumps(k, ensure_ascii=False) + ":" + canonical_json(v) for k, v in items) + "}"
|
|
53
|
+
if isinstance(value, (list, tuple)):
|
|
54
|
+
return "[" + ",".join(canonical_json(v) for v in value) + "]"
|
|
55
|
+
if isinstance(value, float) and value.is_integer():
|
|
56
|
+
return str(int(value))
|
|
57
|
+
return json.dumps(value, ensure_ascii=False)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def sha256_hex(text: str) -> str:
|
|
61
|
+
"""SHA-256 of a UTF-8 string, as lowercase hex (how receipts fingerprint a task or output)."""
|
|
62
|
+
return hashlib.sha256(text.encode("utf-8")).hexdigest()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def verify_signature(doc: dict, public_keys: Iterable[str] = (PUBLIC_KEY,)) -> bool:
|
|
66
|
+
"""True if a receipt (or step acknowledgment) was signed by one of `public_keys` (base64 Ed25519).
|
|
67
|
+
|
|
68
|
+
Offline: no network. Defaults to the pinned official key.
|
|
69
|
+
"""
|
|
70
|
+
from cryptography.exceptions import InvalidSignature
|
|
71
|
+
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
|
|
72
|
+
|
|
73
|
+
if not isinstance(doc, dict) or not doc.get("signature") or "payload" not in doc:
|
|
74
|
+
return False
|
|
75
|
+
trusted = [k for k in public_keys if k]
|
|
76
|
+
if doc.get("public_key"):
|
|
77
|
+
trusted = [k for k in trusted if k == doc["public_key"]]
|
|
78
|
+
data = canonical_json(doc["payload"]).encode("utf-8")
|
|
79
|
+
try:
|
|
80
|
+
sig = base64.b64decode(doc["signature"])
|
|
81
|
+
except Exception:
|
|
82
|
+
return False
|
|
83
|
+
for k in trusted:
|
|
84
|
+
try:
|
|
85
|
+
Ed25519PublicKey.from_public_bytes(base64.b64decode(k)).verify(sig, data)
|
|
86
|
+
return True
|
|
87
|
+
except (InvalidSignature, ValueError):
|
|
88
|
+
continue
|
|
89
|
+
return False
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def verify_review_outcome(
|
|
93
|
+
receipt: dict, task: Optional[str] = None, output: Optional[str] = None, tier: Optional[str] = None
|
|
94
|
+
) -> dict:
|
|
95
|
+
"""Check a sealed-review receipt offline (not the signature; use verify_signature for that).
|
|
96
|
+
|
|
97
|
+
Confirms it is a review (never a match receipt), that it's about exactly the `task` and `output` you pass,
|
|
98
|
+
that every vote comes from the committed reviewer, and that the verdict and tally recompute from the votes.
|
|
99
|
+
Returns {"ok": bool, "problems": [...], "trusts": [...]}.
|
|
100
|
+
"""
|
|
101
|
+
p = receipt.get("payload", receipt) if isinstance(receipt, dict) else {}
|
|
102
|
+
problems: list[str] = []
|
|
103
|
+
trusts = [
|
|
104
|
+
"Each reviewer's verdict is that AI model's judgment: auditable (model, prompt fingerprint), "
|
|
105
|
+
"not recomputable, and not a guarantee the output is correct."
|
|
106
|
+
]
|
|
107
|
+
if not isinstance(p, dict) or p.get("type") != "review":
|
|
108
|
+
return {"ok": False, "problems": ["Not a sealed-review receipt."], "trusts": trusts}
|
|
109
|
+
if tier and p.get("tier") != tier:
|
|
110
|
+
problems.append(f"This review is {p.get('tier')}, not {tier}.")
|
|
111
|
+
if output is not None and sha256_hex(output) != p.get("output_sha256"):
|
|
112
|
+
problems.append("This review is about a different output than the one you have.")
|
|
113
|
+
if task is not None and sha256_hex(task) != p.get("task_sha256"):
|
|
114
|
+
problems.append("This review is for a different task than the one you have.")
|
|
115
|
+
reviewers = p.get("reviewers") or {}
|
|
116
|
+
models = reviewers.get("models") or []
|
|
117
|
+
votes = p.get("votes") or []
|
|
118
|
+
size = _REVIEW_SIZE.get(p.get("tier"))
|
|
119
|
+
if not size or len(models) != size or len(votes) != size:
|
|
120
|
+
problems.append(f"Expected {size or '?'} reviewer votes, the receipt has {len(votes)}.")
|
|
121
|
+
criteria = p.get("criteria") or []
|
|
122
|
+
for i, v in enumerate(votes):
|
|
123
|
+
if i >= len(models) or v.get("model") != models[i]:
|
|
124
|
+
problems.append(f"Vote {i + 1} doesn't come from the committed reviewer.")
|
|
125
|
+
if v.get("verdict") not in REVIEW_VERDICTS:
|
|
126
|
+
problems.append(f"Vote {i + 1} has an unknown verdict.")
|
|
127
|
+
if criteria and v.get("scores"):
|
|
128
|
+
total = sum(c["weight"] * v["scores"].get(c["name"], 0) for c in criteria)
|
|
129
|
+
if v.get("total") != total:
|
|
130
|
+
problems.append(f"Vote {i + 1}'s weighted total doesn't match its scores.")
|
|
131
|
+
tally = {k: 0 for k in REVIEW_VERDICTS}
|
|
132
|
+
for v in votes:
|
|
133
|
+
if v.get("verdict") in tally:
|
|
134
|
+
tally[v["verdict"]] += 1
|
|
135
|
+
rule = reviewers.get("decision_rule")
|
|
136
|
+
verdict: Optional[str] = None
|
|
137
|
+
if rule == "single":
|
|
138
|
+
verdict = votes[0].get("verdict") if votes else None
|
|
139
|
+
elif rule == "majority":
|
|
140
|
+
verdict = next((k for k in REVIEW_VERDICTS if tally[k] > len(votes) / 2), "split")
|
|
141
|
+
else:
|
|
142
|
+
problems.append(f'Unknown decision rule "{rule}".')
|
|
143
|
+
result = p.get("result") or {}
|
|
144
|
+
if rule in ("single", "majority") and result.get("verdict") != verdict:
|
|
145
|
+
problems.append(f"By the {rule} rule the verdict should be {verdict}.")
|
|
146
|
+
if canonical_json(result.get("tally") or {}) != canonical_json(tally):
|
|
147
|
+
problems.append("The vote tally doesn't match the votes.")
|
|
148
|
+
return {"ok": not problems, "problems": problems, "trusts": trusts}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-referee-client
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python tools for Agent Referee (agentreferee.ai): verify signed receipts from the neutral referee and sealed-review service for AI agents. Early preview; the full client is coming.
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://agentreferee.ai
|
|
7
|
+
Project-URL: Source, https://github.com/ccheez34/agent-referee-client
|
|
8
|
+
Project-URL: Issues, https://github.com/ccheez34/agent-referee-client/issues
|
|
9
|
+
Keywords: ai-agents,x402,multi-agent,ai-judge,ai-review,llm-as-judge,receipts
|
|
10
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: cryptography>=41
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# agent-referee-client (Python)
|
|
21
|
+
|
|
22
|
+
Python tools for [Agent Referee](https://agentreferee.ai), a neutral tie-breaker and judge for AI agents from different owners, plus sealed review of a single agent's output by independent AI reviewers.
|
|
23
|
+
|
|
24
|
+
**Early preview (0.0.x).** This release verifies the signed receipts the service issues, so a Python agent can check a receipt another agent hands it (a match result or a sealed review) without trusting that agent. The full Python client (creating matches, paying over x402, requesting reviews) is next. Until then, Python agents can call the service over plain HTTP: see the [guide](https://github.com/ccheez34/agent-referee-client/blob/main/docs/GUIDE.md).
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install agent-referee-client
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from agent_referee_client import PUBLIC_KEY, verify_signature, verify_review_outcome
|
|
32
|
+
|
|
33
|
+
# A sealed-review receipt another agent sent you, plus the task and output it says were reviewed:
|
|
34
|
+
signed = verify_signature(receipt, [PUBLIC_KEY]) # signed by the official service key
|
|
35
|
+
check = verify_review_outcome(receipt, task=task, output=output)
|
|
36
|
+
if signed and check["ok"]:
|
|
37
|
+
print(receipt["payload"]["result"]["verdict"]) # pass, needs_changes, fail, cannot_assess or split
|
|
38
|
+
else:
|
|
39
|
+
print(check["problems"])
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- `verify_signature(doc, public_keys)` checks the Ed25519 signature of any receipt or step acknowledgment, offline. It defaults to the pinned official key.
|
|
43
|
+
- `verify_review_outcome(receipt, task=, output=, tier=)` confirms a review receipt is about exactly that task and output (by SHA-256), that each vote comes from the committed reviewer, and that the verdict and tally recompute from the votes.
|
|
44
|
+
|
|
45
|
+
**Official links:** website https://agentreferee.ai · Python [`agent-referee-client`](https://pypi.org/project/agent-referee-client/) · JavaScript [`agent-referee-client`](https://www.npmjs.com/package/agent-referee-client) · GitHub [`ccheez34/agent-referee-client`](https://github.com/ccheez34/agent-referee-client) · signing key `vM2GY6ZEYc/omRlIFrzu0TaMGtjHXQtchg9d7lPKkTY=`. Not affiliated with the unrelated `agent-referee` package on PyPI (an evaluation and guardrails tool).
|
|
46
|
+
|
|
47
|
+
MIT licensed.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
agent_referee_client/__init__.py,sha256=MGnbC6rIfezeGINkQh-BTU5BRba8iFl8XQAXrEkPJeM,6600
|
|
2
|
+
agent_referee_client-0.0.1.dist-info/licenses/LICENSE,sha256=sSfRdNlUxY8NdeTCacdVsS0mAa-JUQtNETC2nebjimQ,1070
|
|
3
|
+
agent_referee_client-0.0.1.dist-info/METADATA,sha256=rxYGt7Cb-a4qOrn80_5XZ9DrS72g5EI3cc8tzRbQMK0,3098
|
|
4
|
+
agent_referee_client-0.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
5
|
+
agent_referee_client-0.0.1.dist-info/top_level.txt,sha256=p-7FLReIGkbfsTAKbKTdyyVx-_uenPBao-7yOCfxtDE,21
|
|
6
|
+
agent_referee_client-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agent Referee
|
|
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 @@
|
|
|
1
|
+
agent_referee_client
|