agent-referee 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.
- agent_referee-0.1.0/.github/workflows/ci.yml +20 -0
- agent_referee-0.1.0/.gitignore +17 -0
- agent_referee-0.1.0/CONTRIBUTING.md +45 -0
- agent_referee-0.1.0/LICENSE +21 -0
- agent_referee-0.1.0/PKG-INFO +365 -0
- agent_referee-0.1.0/README.md +322 -0
- agent_referee-0.1.0/docs/assets/dashboard-screenshot.png +0 -0
- agent_referee-0.1.0/docs/assets/demo.gif +0 -0
- agent_referee-0.1.0/docs/assets/demo.tape +22 -0
- agent_referee-0.1.0/docs/assets/generate_demo_gif.py +114 -0
- agent_referee-0.1.0/docs/how-it-works.md +104 -0
- agent_referee-0.1.0/docs/your-first-dataset.md +96 -0
- agent_referee-0.1.0/examples/adk_example.py +71 -0
- agent_referee-0.1.0/examples/crewai_example.py +59 -0
- agent_referee-0.1.0/examples/langgraph_example.py +71 -0
- agent_referee-0.1.0/examples/plain_python_gemini_example.py +46 -0
- agent_referee-0.1.0/examples/plain_python_openai_example.py +44 -0
- agent_referee-0.1.0/pyproject.toml +82 -0
- agent_referee-0.1.0/referee/__init__.py +5 -0
- agent_referee-0.1.0/referee/cli.py +776 -0
- agent_referee-0.1.0/referee/config.py +44 -0
- agent_referee-0.1.0/referee/dashboard/__init__.py +0 -0
- agent_referee-0.1.0/referee/dashboard/app.py +174 -0
- agent_referee-0.1.0/referee/entry_point.py +43 -0
- agent_referee-0.1.0/referee/eval/__init__.py +0 -0
- agent_referee-0.1.0/referee/eval/deterministic.py +43 -0
- agent_referee-0.1.0/referee/eval/embedding_similarity.py +53 -0
- agent_referee-0.1.0/referee/eval/example_dataset.json +62 -0
- agent_referee-0.1.0/referee/eval/llm_judge.py +73 -0
- agent_referee-0.1.0/referee/eval/runner.py +81 -0
- agent_referee-0.1.0/referee/eval/text_similarity.py +34 -0
- agent_referee-0.1.0/referee/guardrails/__init__.py +0 -0
- agent_referee-0.1.0/referee/guardrails/execution_layer.py +91 -0
- agent_referee-0.1.0/referee/guardrails/input_validation.py +118 -0
- agent_referee-0.1.0/referee/guardrails/output_validation.py +127 -0
- agent_referee-0.1.0/referee/guardrails/scope_check.py +55 -0
- agent_referee-0.1.0/referee/guardrails/test_suite.py +58 -0
- agent_referee-0.1.0/referee/init_project.py +190 -0
- agent_referee-0.1.0/referee/observe/__init__.py +0 -0
- agent_referee-0.1.0/referee/observe/console_summary.py +36 -0
- agent_referee-0.1.0/referee/observe/tracing.py +69 -0
- agent_referee-0.1.0/referee/protect.py +125 -0
- agent_referee-0.1.0/referee/providers.py +92 -0
- agent_referee-0.1.0/referee/ui.py +208 -0
- agent_referee-0.1.0/tests/__init__.py +0 -0
- agent_referee-0.1.0/tests/test_config.py +35 -0
- agent_referee-0.1.0/tests/test_console_summary.py +31 -0
- agent_referee-0.1.0/tests/test_deterministic.py +32 -0
- agent_referee-0.1.0/tests/test_entry_point.py +31 -0
- agent_referee-0.1.0/tests/test_execution_layer.py +36 -0
- agent_referee-0.1.0/tests/test_input_validation.py +50 -0
- agent_referee-0.1.0/tests/test_protect.py +65 -0
- agent_referee-0.1.0/tests/test_text_similarity.py +29 -0
- agent_referee-0.1.0/tests/test_tracing.py +30 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.9", "3.11", "3.12"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- run: pip install -e ".[dev]"
|
|
20
|
+
- run: pytest tests/ -v
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for considering it. This project is meant to be readable and approachable, so
|
|
4
|
+
contributions of any size are welcome: a typo fix, a new example integration, a new guardrail
|
|
5
|
+
check, a doc improvement.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
git clone https://github.com/mehrotra0307/agent-referee.git
|
|
11
|
+
cd agent-referee
|
|
12
|
+
python3 -m venv .venv
|
|
13
|
+
source .venv/bin/activate
|
|
14
|
+
pip install -e ".[dev]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
That installs the package in editable mode, plus pytest.
|
|
18
|
+
|
|
19
|
+
## Running the tests
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pytest tests/ -v
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
All tests should pass with the base install alone. Tests that need an optional extra
|
|
26
|
+
(embedding, a specific provider SDK, streamlit) should skip cleanly if that extra isn't
|
|
27
|
+
installed, not fail.
|
|
28
|
+
|
|
29
|
+
## Before opening a pull request
|
|
30
|
+
|
|
31
|
+
- Run the test suite and make sure it passes.
|
|
32
|
+
- If you're changing behavior in `referee/`, add or update a test for it.
|
|
33
|
+
- If you're adding a new public function, give it a short docstring explaining what it does,
|
|
34
|
+
what it needs, and what it returns. The project favors clear docstrings and clear naming over
|
|
35
|
+
inline comments explaining what code does; a comment is worth adding only when it explains a
|
|
36
|
+
non-obvious *why*, like a workaround for a specific bug or a deliberate tradeoff.
|
|
37
|
+
- Keep the core install light. If your change needs a new dependency, check whether it belongs
|
|
38
|
+
in `pyproject.toml`'s core `dependencies` or in `optional-dependencies` as a new or existing
|
|
39
|
+
extra, and default to the extra unless it's genuinely tiny and always needed.
|
|
40
|
+
|
|
41
|
+
## Reporting a bug or proposing an idea
|
|
42
|
+
|
|
43
|
+
Open a GitHub issue. For a bug, include what you ran, what you expected, and what actually
|
|
44
|
+
happened. For an idea, a sentence or two on the problem it solves is more useful than a full
|
|
45
|
+
design up front.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ashish Mehrotra
|
|
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,365 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-referee
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Plug any AI agent into real evaluation scoring, guardrails, and observability tracing in minutes — framework-agnostic, 100% free, no signup, never touches your API key.
|
|
5
|
+
Project-URL: Homepage, https://github.com/mehrotra0307/agent-referee
|
|
6
|
+
Project-URL: Repository, https://github.com/mehrotra0307/agent-referee
|
|
7
|
+
Project-URL: Issues, https://github.com/mehrotra0307/agent-referee/issues
|
|
8
|
+
Author: Ashish Mehrotra
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai-agents,guardrails,llm,llm-evaluation,observability,opentelemetry
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Topic :: Software Development :: Testing
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Requires-Dist: anthropic>=0.30
|
|
24
|
+
Requires-Dist: click>=8.1
|
|
25
|
+
Requires-Dist: google-genai>=0.1
|
|
26
|
+
Requires-Dist: openai>=1.0
|
|
27
|
+
Requires-Dist: opentelemetry-api>=1.20
|
|
28
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.20
|
|
29
|
+
Requires-Dist: opentelemetry-sdk>=1.20
|
|
30
|
+
Requires-Dist: python-dotenv>=1.0
|
|
31
|
+
Requires-Dist: pyyaml>=6.0
|
|
32
|
+
Requires-Dist: rouge-score>=0.1.2
|
|
33
|
+
Provides-Extra: all
|
|
34
|
+
Requires-Dist: sentence-transformers>=2.2; extra == 'all'
|
|
35
|
+
Requires-Dist: streamlit>=1.30; extra == 'all'
|
|
36
|
+
Provides-Extra: dashboard
|
|
37
|
+
Requires-Dist: streamlit>=1.30; extra == 'dashboard'
|
|
38
|
+
Provides-Extra: dev
|
|
39
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
40
|
+
Provides-Extra: embedding
|
|
41
|
+
Requires-Dist: sentence-transformers>=2.2; extra == 'embedding'
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
# Agent Referee
|
|
45
|
+
|
|
46
|
+
[](https://github.com/mehrotra0307/agent-referee/actions/workflows/ci.yml)
|
|
47
|
+
[](LICENSE)
|
|
48
|
+
[](pyproject.toml)
|
|
49
|
+
|
|
50
|
+
You built an agent. Cool. Does it lie? Does it leak your users' phone numbers? Does it fall
|
|
51
|
+
over the first time someone types "ignore your instructions"? You don't know, because nobody
|
|
52
|
+
tells you this stuff by default. That's the whole reason this exists.
|
|
53
|
+
|
|
54
|
+
Agent Referee plugs into any agent, however you built it, wherever it lives, and gives it three
|
|
55
|
+
things almost nobody sets up on their own: a report card (**evaluation**), a bouncer
|
|
56
|
+
(**guardrails**), and a flight recorder (**observability**). One `pip install`, one decorator,
|
|
57
|
+
zero API keys typed into anything, and it teaches you what it's doing while it does it.
|
|
58
|
+
|
|
59
|
+

|
|
60
|
+
|
|
61
|
+
**Who this is for, honestly:**
|
|
62
|
+
- Never built an agent before and don't know what "guardrails" even means → good, start here.
|
|
63
|
+
- Built a few agents, shipped them, and quietly hoped nothing bad would happen → also you.
|
|
64
|
+
- Already know evaluation/guardrails/observability cold and just want the fastest possible
|
|
65
|
+
plug-in → skip to [the flow](#the-full-flow-teach-first-then-do), it's still faster than
|
|
66
|
+
writing your own.
|
|
67
|
+
|
|
68
|
+
Nobody gets talked down to and nobody gets left behind. That's the actual design goal, not a
|
|
69
|
+
marketing line.
|
|
70
|
+
|
|
71
|
+
## The one rule we will never break
|
|
72
|
+
|
|
73
|
+
Agent Referee will never ask you to paste an API key into a prompt, a wizard, or a config file.
|
|
74
|
+
Ever. Not now, not in version 47, not if you beg.
|
|
75
|
+
|
|
76
|
+
Your key lives in one `.env` file, on your machine, that you create yourself. We read it with
|
|
77
|
+
`os.getenv()`, the exact same boring, standard way the official Google/OpenAI/Anthropic SDKs
|
|
78
|
+
already do. There is no server on our end receiving it, because there is no server, period. A
|
|
79
|
+
CLI tool asking you to type in a secret is a phishing pattern with a friendly logo slapped on
|
|
80
|
+
it. We just don't do that.
|
|
81
|
+
|
|
82
|
+
## Try it before you install anything you'll actually use
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install agent-referee
|
|
86
|
+
referee demo
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Quick, important clarification because people get confused here: **this does not touch your
|
|
90
|
+
real agent.** `referee demo` runs a tiny, fake, built-in agent that ships inside the package
|
|
91
|
+
itself, basically an if/else pizza-shop bot. It's not calling any real AI. The whole point is
|
|
92
|
+
to show you what this tool does before you trust it with something real, no key, no setup, no
|
|
93
|
+
risk, kind of like sitting in a display car at the dealership before you buy one, except the
|
|
94
|
+
car is `pip install`-able.
|
|
95
|
+
|
|
96
|
+
In about 30 seconds you'll watch: a normal question pass straight through with a live trace
|
|
97
|
+
underneath it, a message with a fake phone number get blocked before the fake agent even sees
|
|
98
|
+
it, and a tiny grading check pass. That's the entire pitch, compressed.
|
|
99
|
+
|
|
100
|
+
## The big picture
|
|
101
|
+
|
|
102
|
+
```mermaid
|
|
103
|
+
graph LR
|
|
104
|
+
A["Your agent function<br/>(unchanged, any framework)"]
|
|
105
|
+
P["@referee.protect()"]
|
|
106
|
+
IN["Input guardrails<br/>PII · injection · rate limit · scope"]
|
|
107
|
+
OUT["Output guardrails<br/>PII leak · toxicity · groundedness"]
|
|
108
|
+
TR["Trace, printed to your terminal"]
|
|
109
|
+
EV["referee eval run<br/>(separate command, offline grading)"]
|
|
110
|
+
|
|
111
|
+
P --> IN
|
|
112
|
+
IN -- safe --> A
|
|
113
|
+
A --> OUT
|
|
114
|
+
OUT -- safe --> DONE["Answer goes back to your user"]
|
|
115
|
+
P -.records.-> TR
|
|
116
|
+
EV -.grades.-> A
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Guardrails and tracing wrap every live call, automatically. Evaluation is a separate, deliberate
|
|
120
|
+
command you run when you want a report card, not something that runs on every message.
|
|
121
|
+
|
|
122
|
+
## The full flow, teach-first, then do
|
|
123
|
+
|
|
124
|
+
Every step below follows the same shape: **what this is, in plain English, first. Then the
|
|
125
|
+
command.** That's on purpose. If you skip the explanations you'll still get it working, but
|
|
126
|
+
you'll have learned nothing, and learning is half of what this project is for.
|
|
127
|
+
|
|
128
|
+
### Step 1: Install it
|
|
129
|
+
|
|
130
|
+
**What's happening:** `pip` is Python's package manager, the thing that downloads and installs
|
|
131
|
+
libraries. This one command gets you the whole tool.
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
pip install agent-referee
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
It's fast on purpose. No PyTorch, no gigabyte downloads. (There are two genuinely heavy optional
|
|
138
|
+
features later, explained honestly near the bottom, not hidden.)
|
|
139
|
+
|
|
140
|
+
### Step 2: Meet the setup wizard
|
|
141
|
+
|
|
142
|
+
**What's happening:** before Agent Referee can watch your agent, it needs three facts about it:
|
|
143
|
+
where the code lives, what it's supposed to talk about, and which AI company you use. That's it.
|
|
144
|
+
No key, ever, at any point in this step.
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
referee init
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
It asks:
|
|
151
|
+
1. Where your agent function lives, e.g. `agent/my_agent.py:ask_my_agent`.
|
|
152
|
+
2. One sentence describing what your agent is allowed to talk about (used later to catch
|
|
153
|
+
completely off-topic questions, like someone asking your pizza-shop bot for tax advice).
|
|
154
|
+
3. Which provider you use: Gemini, OpenAI, or Anthropic.
|
|
155
|
+
|
|
156
|
+
This writes one file, `referee.yaml`, plain text, safe to commit to git. It also makes sure your
|
|
157
|
+
`.env` file is in `.gitignore`, so you can never accidentally commit a key even if you tried.
|
|
158
|
+
|
|
159
|
+
### Step 3: Get an API key (skip this if you already have one)
|
|
160
|
+
|
|
161
|
+
**What's happening:** an API key is just a password that proves to an AI company's servers that
|
|
162
|
+
it's really you making the request, so they know who to bill (or not bill, on a free tier).
|
|
163
|
+
Never made one? Here's the fastest, free option:
|
|
164
|
+
|
|
165
|
+
- **Gemini (recommended if you're starting from zero):** go to
|
|
166
|
+
[aistudio.google.com](https://aistudio.google.com), sign in with any Google account, click
|
|
167
|
+
"Get API key." No credit card. This is separate from a full Google Cloud project, and if you've
|
|
168
|
+
built with ADK and have GCP's $300 trial credit, you don't need to touch any of that just to
|
|
169
|
+
get this key.
|
|
170
|
+
- **OpenAI:** [platform.openai.com/api-keys](https://platform.openai.com/api-keys). Needs
|
|
171
|
+
billing set up first, no free tier.
|
|
172
|
+
- **Anthropic:** [console.anthropic.com](https://console.anthropic.com). Same deal, billing
|
|
173
|
+
required.
|
|
174
|
+
|
|
175
|
+
Whichever you picked in Step 2, save it in a `.env` file, in the same folder as your agent:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
echo "GEMINI_API_KEY=your_key_here" > .env
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
(Swap the variable name if you picked OpenAI or Anthropic.)
|
|
182
|
+
|
|
183
|
+
### Step 4: Add one decorator
|
|
184
|
+
|
|
185
|
+
**What's happening:** this is the only line you add to your actual code. Find the function that
|
|
186
|
+
takes a question in and returns an answer, and put this directly above it.
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
import referee
|
|
190
|
+
|
|
191
|
+
@referee.protect(config="referee.yaml")
|
|
192
|
+
def my_agent(user_input: str) -> str:
|
|
193
|
+
... # your existing code, completely untouched
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
From now on, every call to `my_agent` quietly does five things, in order: starts a trace, runs
|
|
197
|
+
your input guardrails (a block here means your real function never even runs), calls your
|
|
198
|
+
actual code, runs your output guardrails on the answer, ends the trace. You never write any of
|
|
199
|
+
that plumbing. One line did it.
|
|
200
|
+
|
|
201
|
+
**If you built with Google's ADK:** your agent doesn't look like a plain function, it's a
|
|
202
|
+
`Runner` that speaks in async events. That's fine, you just need a one-function adapter that
|
|
203
|
+
awaits your ADK agent and hands back the plain text of its final answer. The complete, verified
|
|
204
|
+
pattern is in [`examples/adk_example.py`](examples/adk_example.py), same one-decorator promise,
|
|
205
|
+
just with ADK's own shape underneath it instead of a bare function.
|
|
206
|
+
|
|
207
|
+
### Step 5: Check it actually worked
|
|
208
|
+
|
|
209
|
+
**What's happening:** don't skip this. Call your real agent once, by hand, right in this same
|
|
210
|
+
terminal, and actually look at the output.
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
referee try "any question for your agent"
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
This loads your agent from `referee.yaml` and calls it exactly once. You should see guardrail
|
|
217
|
+
and trace lines printed above a clearly boxed final answer. If you see that, the wiring is
|
|
218
|
+
correct and you've earned the right to move on. If you don't, something's off in `referee.yaml`
|
|
219
|
+
before you go build a whole test list on top of it.
|
|
220
|
+
|
|
221
|
+
### Step 6: Build a test list, with zero API calls
|
|
222
|
+
|
|
223
|
+
**What's happening:** a golden dataset is just a list of questions and what a correct answer
|
|
224
|
+
should mention, so you can check your agent's real answers automatically instead of reading
|
|
225
|
+
every single one yourself forever.
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
referee dataset new
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
A back-and-forth wizard, right in your terminal. Fully offline, no key needed, on purpose, so
|
|
232
|
+
your very first test list costs nothing. There's also a small example dataset shipped with the
|
|
233
|
+
tool for inspiration, the wizard tells you exactly where to find it. Full walkthrough:
|
|
234
|
+
[docs/your-first-dataset.md](docs/your-first-dataset.md).
|
|
235
|
+
|
|
236
|
+
### Step 7: Grade your agent against that list
|
|
237
|
+
|
|
238
|
+
**What's happening:** this is the "report card" moment. Your agent gets asked every question you
|
|
239
|
+
just wrote, and each answer gets checked and explained in one plain sentence.
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
referee eval run
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Saves a full report to a `reports/` folder, and exits with an error code if anything marked
|
|
246
|
+
"critical" failed, on purpose, so the exact same command can block a bad deploy in a CI pipeline.
|
|
247
|
+
|
|
248
|
+
### Step 8: Attack your own guardrails, on purpose
|
|
249
|
+
|
|
250
|
+
**What's happening:** a guardrail you've never actually tested is a guardrail you're just
|
|
251
|
+
hoping works. This does **not** call your real agent at all. It has 8 fixed attack strings
|
|
252
|
+
built into the library itself (`referee/guardrails/test_suite.py`), and sends each one straight
|
|
253
|
+
to the library's own checking functions: `check_pii()` and `check_injection()` (plain regex,
|
|
254
|
+
zero API calls) or `check_scope()` (one real API call, only if you've turned scope-check on).
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
referee guardrails test
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Never even heard the word "guardrail" before today?** Good news: this command assumes exactly
|
|
261
|
+
that. It doesn't require you to have set anything up first: the PII and injection checks are
|
|
262
|
+
always on and run instantly, for free, with zero setup. Add `--local-only` if you've also turned
|
|
263
|
+
on the topic-scope check and want to skip the one attack that spends a real API call. Once
|
|
264
|
+
everything's blocked, it also prints a real, colored, bordered status table right in your
|
|
265
|
+
terminal, no install needed, showing everything set up so far in one glance.
|
|
266
|
+
|
|
267
|
+
### Step 9: Look at everything in one place (optional, but nice)
|
|
268
|
+
|
|
269
|
+
**What's happening:** a small local webpage showing your last report card and your last
|
|
270
|
+
guardrail attack results side by side, including your agent's actual answer text, not just
|
|
271
|
+
pass/fail counts like the free terminal table above.
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
pip install "agent-referee[dashboard]"
|
|
275
|
+
referee dashboard
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+

|
|
279
|
+
|
|
280
|
+
Yes, this is a real screenshot, taken against a real run, not a mockup drawn by someone who's
|
|
281
|
+
never opened Figma. Red means something's wrong, green means it isn't, and if you can't tell
|
|
282
|
+
those apart from three feet away, that's a you problem, not a design problem.
|
|
283
|
+
|
|
284
|
+
This is the one step that needs a second install command, and here's why, honestly: the
|
|
285
|
+
dashboard is built on Streamlit, which drags in about 180MB of its own dependencies (mostly
|
|
286
|
+
`pyarrow`, for a data table you'll look at maybe twice a day). That download lands inside your
|
|
287
|
+
project's own virtual environment (`.venv/`), not scattered anywhere else — delete that folder
|
|
288
|
+
and it's gone. That's real weight for something optional, so it's opt-in instead of forced on
|
|
289
|
+
everyone. Nothing here is hosted by anyone but you, it's a page rendered on your own machine,
|
|
290
|
+
and it opens your browser automatically once it starts.
|
|
291
|
+
|
|
292
|
+
That's the whole flow. Steps 1 through 8 need exactly one install command, ever. Step 9 is a
|
|
293
|
+
nice-to-have that costs one more, explained instead of hidden.
|
|
294
|
+
|
|
295
|
+
## The one place you still write code by hand
|
|
296
|
+
|
|
297
|
+
Everything above is automatic once the decorator's in place, except one thing, for an honest
|
|
298
|
+
technical reason, not laziness: if your agent calls a *tool* (placing a real order, sending a
|
|
299
|
+
real email), the decorator can't see inside that decision. It only wraps the outer function.
|
|
300
|
+
So blocking a specific tool call needs one manual line, right before the tool actually runs:
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
from referee.guardrails.execution_layer import check_tool_call
|
|
304
|
+
|
|
305
|
+
result = check_tool_call(tool_name, tool_args, session_id, config)
|
|
306
|
+
if not result["allowed"]:
|
|
307
|
+
return result["reason"]
|
|
308
|
+
# only now does your tool actually run
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
That's the only hand-written wiring anywhere in this project.
|
|
312
|
+
|
|
313
|
+
## What's actually in the box
|
|
314
|
+
|
|
315
|
+
- **Evaluation**: 5 scoring methods, exact phrase match, refusal detection, ROUGE word-overlap,
|
|
316
|
+
meaning-based embedding similarity, and a second LLM grading the first one against a rubric
|
|
317
|
+
you write.
|
|
318
|
+
- **Guardrails**: PII detection, prompt-injection detection, rate limiting, topic-scope
|
|
319
|
+
enforcement, toxicity and groundedness checks. Free checks always run before the ones that
|
|
320
|
+
cost an API call.
|
|
321
|
+
- **Observability**: real OpenTelemetry, the same open standard Google Cloud and AWS use, not a
|
|
322
|
+
reinvented wheel. Prints clean, readable traces to your terminal by default; point it at any
|
|
323
|
+
OTLP-compatible backend (Langfuse Cloud's free tier, for instance) if you want permanent,
|
|
324
|
+
searchable history instead.
|
|
325
|
+
|
|
326
|
+
Works with plain Python + Gemini/OpenAI/Anthropic, LangGraph, CrewAI, and Google's ADK, all four
|
|
327
|
+
as complete working files in [examples/](examples/), not snippets. Agent Referee itself never
|
|
328
|
+
imports any of those frameworks, so it keeps working with whatever shows up next year too.
|
|
329
|
+
|
|
330
|
+
## Optional extras, and why they're optional
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
pip install "agent-referee[embedding]" # semantic-similarity scoring, needs PyTorch, ~395MB
|
|
334
|
+
pip install "agent-referee[dashboard]" # the local web UI, needs Streamlit, ~180MB
|
|
335
|
+
pip install "agent-referee[all]" # both, if you want everything
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Everything else, including all three provider SDKs (Gemini, OpenAI, Anthropic), ships in core.
|
|
339
|
+
We checked actual install sizes before deciding, not vibes: those three together add well under
|
|
340
|
+
100MB, and picking one is a question `referee init` asks you on your very first run, not an edge
|
|
341
|
+
case worth a second command. `sentence-transformers` and `streamlit` are each 3-4x heavier than
|
|
342
|
+
that combined, for features the guided flow above doesn't even touch by default. Weight only
|
|
343
|
+
where weight is earned.
|
|
344
|
+
|
|
345
|
+
## Want the deeper explanation
|
|
346
|
+
|
|
347
|
+
- [docs/how-it-works.md](docs/how-it-works.md): the three pillars again, slower, for someone
|
|
348
|
+
who's never heard these words before today.
|
|
349
|
+
- [docs/your-first-dataset.md](docs/your-first-dataset.md): a full worked example of building a
|
|
350
|
+
golden dataset by hand.
|
|
351
|
+
|
|
352
|
+
## Contributing
|
|
353
|
+
|
|
354
|
+
Typos, new examples, new guardrail checks, doc fixes, all welcome. See
|
|
355
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) for setup and the project's docstring conventions.
|
|
356
|
+
|
|
357
|
+
## License
|
|
358
|
+
|
|
359
|
+
MIT. See [LICENSE](LICENSE).
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
Go forth and plug this into whatever you built. If your agent was already flawless and
|
|
364
|
+
guardrail-proof before reading this, congratulations, you didn't need us and this was a fun
|
|
365
|
+
five minutes. Everyone else: you're welcome.
|