kitaru-typesafe-evaluator 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.
- kitaru_typesafe_evaluator-0.1.0/.gitignore +316 -0
- kitaru_typesafe_evaluator-0.1.0/CHANGELOG.md +5 -0
- kitaru_typesafe_evaluator-0.1.0/PKG-INFO +146 -0
- kitaru_typesafe_evaluator-0.1.0/README.md +118 -0
- kitaru_typesafe_evaluator-0.1.0/pyproject.toml +42 -0
- kitaru_typesafe_evaluator-0.1.0/src/kitaru_typesafe_evaluator/__init__.py +19 -0
- kitaru_typesafe_evaluator-0.1.0/src/kitaru_typesafe_evaluator/connection-schema.json +16 -0
- kitaru_typesafe_evaluator-0.1.0/src/kitaru_typesafe_evaluator/connection.py +22 -0
- kitaru_typesafe_evaluator-0.1.0/src/kitaru_typesafe_evaluator/judge.py +95 -0
- kitaru_typesafe_evaluator-0.1.0/src/kitaru_typesafe_evaluator/params.py +84 -0
- kitaru_typesafe_evaluator-0.1.0/src/kitaru_typesafe_evaluator/results.py +131 -0
- kitaru_typesafe_evaluator-0.1.0/src/kitaru_typesafe_evaluator/state.py +162 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# iCloud conflict duplicates (pattern: "filename 2.ext" or "filename 2")
|
|
2
|
+
*[[:space:]]2.[!.]*
|
|
3
|
+
*[[:space:]]2
|
|
4
|
+
|
|
5
|
+
# Helm dependency artifacts (rebuilt via helm dep update)
|
|
6
|
+
helm/charts/
|
|
7
|
+
helm/Chart.lock
|
|
8
|
+
|
|
9
|
+
# Root TypeScript workspace
|
|
10
|
+
/node_modules/
|
|
11
|
+
/packages/*/node_modules/
|
|
12
|
+
/examples/typescript/mastra_support_triage/node_modules/
|
|
13
|
+
/examples/typescript/mastra_adaptive_conversation/node_modules/
|
|
14
|
+
/examples/typescript/vercel_ai_support_triage/node_modules/
|
|
15
|
+
/packages/*/dist/
|
|
16
|
+
/typescript-dist/
|
|
17
|
+
|
|
18
|
+
# pnpm
|
|
19
|
+
**/.pnpm-store
|
|
20
|
+
|
|
21
|
+
# macOS
|
|
22
|
+
.DS_Store
|
|
23
|
+
|
|
24
|
+
# Byte-compiled / optimized / DLL files
|
|
25
|
+
__pycache__/
|
|
26
|
+
*.py[codz]
|
|
27
|
+
*$py.class
|
|
28
|
+
|
|
29
|
+
# C extensions
|
|
30
|
+
*.so
|
|
31
|
+
|
|
32
|
+
# Distribution / packaging
|
|
33
|
+
.Python
|
|
34
|
+
build/
|
|
35
|
+
develop-eggs/
|
|
36
|
+
dist/
|
|
37
|
+
plugins/candidate-wheels/*
|
|
38
|
+
!plugins/candidate-wheels/.gitkeep
|
|
39
|
+
downloads/
|
|
40
|
+
eggs/
|
|
41
|
+
.eggs/
|
|
42
|
+
lib/
|
|
43
|
+
!docs/lib/
|
|
44
|
+
lib64/
|
|
45
|
+
parts/
|
|
46
|
+
sdist/
|
|
47
|
+
var/
|
|
48
|
+
wheels/
|
|
49
|
+
share/python-wheels/
|
|
50
|
+
*.egg-info/
|
|
51
|
+
.installed.cfg
|
|
52
|
+
*.egg
|
|
53
|
+
MANIFEST
|
|
54
|
+
|
|
55
|
+
# PyInstaller
|
|
56
|
+
# Usually these files are written by a python script from a template
|
|
57
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
58
|
+
*.manifest
|
|
59
|
+
*.spec
|
|
60
|
+
|
|
61
|
+
# Installer logs
|
|
62
|
+
pip-log.txt
|
|
63
|
+
pip-delete-this-directory.txt
|
|
64
|
+
|
|
65
|
+
# Unit test / coverage reports
|
|
66
|
+
htmlcov/
|
|
67
|
+
.tox/
|
|
68
|
+
.nox/
|
|
69
|
+
.coverage
|
|
70
|
+
.coverage.*
|
|
71
|
+
.cache
|
|
72
|
+
nosetests.xml
|
|
73
|
+
coverage.xml
|
|
74
|
+
*.cover
|
|
75
|
+
*.py.cover
|
|
76
|
+
.hypothesis/
|
|
77
|
+
.pytest_cache/
|
|
78
|
+
cover/
|
|
79
|
+
|
|
80
|
+
# Translations
|
|
81
|
+
*.mo
|
|
82
|
+
*.pot
|
|
83
|
+
|
|
84
|
+
# Django stuff:
|
|
85
|
+
*.log
|
|
86
|
+
local_settings.py
|
|
87
|
+
db.sqlite3
|
|
88
|
+
db.sqlite3-journal
|
|
89
|
+
|
|
90
|
+
# Flask stuff:
|
|
91
|
+
instance/
|
|
92
|
+
.webassets-cache
|
|
93
|
+
|
|
94
|
+
# Scrapy stuff:
|
|
95
|
+
.scrapy
|
|
96
|
+
|
|
97
|
+
# Sphinx documentation
|
|
98
|
+
docs/_build/
|
|
99
|
+
|
|
100
|
+
# PyBuilder
|
|
101
|
+
.pybuilder/
|
|
102
|
+
target/
|
|
103
|
+
|
|
104
|
+
# Jupyter Notebook
|
|
105
|
+
.ipynb_checkpoints
|
|
106
|
+
|
|
107
|
+
# IPython
|
|
108
|
+
profile_default/
|
|
109
|
+
ipython_config.py
|
|
110
|
+
|
|
111
|
+
# pyenv
|
|
112
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
113
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
114
|
+
# .python-version
|
|
115
|
+
|
|
116
|
+
# pipenv
|
|
117
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
118
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
119
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
120
|
+
# install all needed dependencies.
|
|
121
|
+
#Pipfile.lock
|
|
122
|
+
|
|
123
|
+
# UV
|
|
124
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
125
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
126
|
+
# commonly ignored for libraries.
|
|
127
|
+
#uv.lock
|
|
128
|
+
|
|
129
|
+
# poetry
|
|
130
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
131
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
132
|
+
# commonly ignored for libraries.
|
|
133
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
134
|
+
#poetry.lock
|
|
135
|
+
#poetry.toml
|
|
136
|
+
|
|
137
|
+
# pdm
|
|
138
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
139
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
140
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
141
|
+
#pdm.lock
|
|
142
|
+
#pdm.toml
|
|
143
|
+
.pdm-python
|
|
144
|
+
.pdm-build/
|
|
145
|
+
|
|
146
|
+
# pixi
|
|
147
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
148
|
+
#pixi.lock
|
|
149
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
150
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
151
|
+
.pixi
|
|
152
|
+
|
|
153
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
154
|
+
__pypackages__/
|
|
155
|
+
|
|
156
|
+
# Celery stuff
|
|
157
|
+
celerybeat-schedule
|
|
158
|
+
celerybeat.pid
|
|
159
|
+
|
|
160
|
+
# SageMath parsed files
|
|
161
|
+
*.sage.py
|
|
162
|
+
|
|
163
|
+
# Environments
|
|
164
|
+
.env
|
|
165
|
+
.envrc
|
|
166
|
+
.venv
|
|
167
|
+
env/
|
|
168
|
+
venv/
|
|
169
|
+
ENV/
|
|
170
|
+
env.bak/
|
|
171
|
+
venv.bak/
|
|
172
|
+
|
|
173
|
+
# Spyder project settings
|
|
174
|
+
.spyderproject
|
|
175
|
+
.spyproject
|
|
176
|
+
|
|
177
|
+
# Rope project settings
|
|
178
|
+
.ropeproject
|
|
179
|
+
|
|
180
|
+
# mypy
|
|
181
|
+
.mypy_cache/
|
|
182
|
+
.dmypy.json
|
|
183
|
+
dmypy.json
|
|
184
|
+
|
|
185
|
+
# Pyre type checker
|
|
186
|
+
.pyre/
|
|
187
|
+
|
|
188
|
+
# pytype static type analyzer
|
|
189
|
+
.pytype/
|
|
190
|
+
|
|
191
|
+
# Cython debug symbols
|
|
192
|
+
cython_debug/
|
|
193
|
+
|
|
194
|
+
# PyCharm
|
|
195
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
196
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
197
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
198
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
199
|
+
#.idea/
|
|
200
|
+
|
|
201
|
+
# Abstra
|
|
202
|
+
# Abstra is an AI-powered process automation framework.
|
|
203
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
204
|
+
# Learn more at https://abstra.io/docs
|
|
205
|
+
.abstra/
|
|
206
|
+
|
|
207
|
+
# Visual Studio Code
|
|
208
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
209
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
210
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
211
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
212
|
+
# .vscode/
|
|
213
|
+
|
|
214
|
+
# Ruff stuff:
|
|
215
|
+
.ruff_cache/
|
|
216
|
+
|
|
217
|
+
# PyPI configuration file
|
|
218
|
+
.pypirc
|
|
219
|
+
|
|
220
|
+
# Cursor
|
|
221
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
222
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
223
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
224
|
+
.cursorignore
|
|
225
|
+
.cursorindexingignore
|
|
226
|
+
|
|
227
|
+
# Marimo
|
|
228
|
+
marimo/_static/
|
|
229
|
+
marimo/_lsp/
|
|
230
|
+
__marimo__/
|
|
231
|
+
|
|
232
|
+
# Cloudflare local state
|
|
233
|
+
.wrangler/
|
|
234
|
+
|
|
235
|
+
# Local project markers
|
|
236
|
+
.kitaru/
|
|
237
|
+
.zen/
|
|
238
|
+
|
|
239
|
+
# Git worktrees (isolated workspaces created via git worktree add)
|
|
240
|
+
.worktrees/
|
|
241
|
+
|
|
242
|
+
# Design docs + Repoprompt
|
|
243
|
+
design/
|
|
244
|
+
dogfood-output/
|
|
245
|
+
prompt-exports/
|
|
246
|
+
|
|
247
|
+
# Local Kitaru UI build artifacts (used by docker/Dockerfile.server-dev)
|
|
248
|
+
docker/kitaru-ui-dist/
|
|
249
|
+
|
|
250
|
+
# MCP
|
|
251
|
+
.mcp.json
|
|
252
|
+
|
|
253
|
+
# Claude
|
|
254
|
+
**/.claude/settings.local.json
|
|
255
|
+
.claude/*
|
|
256
|
+
!.claude/settings.json
|
|
257
|
+
!.claude/skills/
|
|
258
|
+
|
|
259
|
+
# Playwright MCP
|
|
260
|
+
.playwright-mcp/
|
|
261
|
+
|
|
262
|
+
# Bundled Kitaru UI (generated at build time by scripts/download-ui.sh)
|
|
263
|
+
src/kitaru/_ui/dist/
|
|
264
|
+
src/kitaru/_ui/bundle_manifest.json
|
|
265
|
+
.kitaru-ui-bundles/
|
|
266
|
+
|
|
267
|
+
# Codex
|
|
268
|
+
.codex/*
|
|
269
|
+
!.codex/skills/
|
|
270
|
+
AGENTS.override.md
|
|
271
|
+
.agents/skills/*
|
|
272
|
+
!.agents/skills/kitaru-dev/
|
|
273
|
+
!.agents/skills/kitaru-dev/**
|
|
274
|
+
!.agents/skills/kitaru-adapter-development/
|
|
275
|
+
!.agents/skills/kitaru-adapter-development/**
|
|
276
|
+
!.agents/skills/kitaru-docs/
|
|
277
|
+
!.agents/skills/kitaru-docs/**
|
|
278
|
+
!.agents/skills/kitaru-importer-development/
|
|
279
|
+
!.agents/skills/kitaru-importer-development/**
|
|
280
|
+
!.agents/skills/kitaru-release/
|
|
281
|
+
!.agents/skills/kitaru-release/**
|
|
282
|
+
!.agents/skills/kitaru-evaluator-authoring/
|
|
283
|
+
!.agents/skills/kitaru-evaluator-authoring/**
|
|
284
|
+
!.agents/skills/kitaru-session-improvement/
|
|
285
|
+
!.agents/skills/kitaru-session-improvement/**
|
|
286
|
+
!.agents/skills/kitaru-tests-release/
|
|
287
|
+
!.agents/skills/kitaru-tests-release/**
|
|
288
|
+
!.agents/skills/kitaru-ui-api-development/
|
|
289
|
+
!.agents/skills/kitaru-ui-api-development/**
|
|
290
|
+
|
|
291
|
+
# Agent Skills
|
|
292
|
+
.pi/
|
|
293
|
+
.claude/skills/building-pydantic-ai-agents
|
|
294
|
+
.claude/skills/instrumentation
|
|
295
|
+
skills-lock.json
|
|
296
|
+
|
|
297
|
+
# Local PR review screenshots
|
|
298
|
+
.pr-screenshots/
|
|
299
|
+
|
|
300
|
+
# Local scratch — single-developer scratch flow files at repo root
|
|
301
|
+
/my_flow.py
|
|
302
|
+
.claude/skills/logfire-instrumentation
|
|
303
|
+
.clawpatch/
|
|
304
|
+
docs/investigations/
|
|
305
|
+
docs/plans/
|
|
306
|
+
docs/reviews/
|
|
307
|
+
plans/
|
|
308
|
+
replay-verify-reports-live/
|
|
309
|
+
replay-verify-reports/
|
|
310
|
+
|
|
311
|
+
# OpenAPI baseline build output
|
|
312
|
+
openapi/.build/
|
|
313
|
+
src/kitaru/server/application/services/sample_data.json.gz
|
|
314
|
+
|
|
315
|
+
# Per-user publish settings, see devtools/publish.env.example
|
|
316
|
+
devtools/publish.env
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: kitaru-typesafe-evaluator
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Judge Kitaru sessions with TypeSafe's jev model and your own questions.
|
|
5
|
+
Project-URL: Homepage, https://kitaru.ai
|
|
6
|
+
Project-URL: Documentation, https://docs.zenml.io/kitaru/guides/judge-evaluations
|
|
7
|
+
Project-URL: Repository, https://github.com/zenml-io/kitaru
|
|
8
|
+
Project-URL: Issues, https://github.com/zenml-io/kitaru/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/zenml-io/kitaru/blob/develop/plugins/packages/typesafe-evaluator/CHANGELOG.md
|
|
10
|
+
Author-email: ZenML GmbH <info@zenml.io>
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
Keywords: ai-agents,evaluation,jev,kitaru,llm,typesafe
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Requires-Dist: kitaru>=0.22.0
|
|
26
|
+
Requires-Dist: typesafe-sdk==0.6.0
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# Kitaru TypeSafe evaluator
|
|
30
|
+
|
|
31
|
+
Judge recorded and imported Kitaru sessions with jev, TypeSafe's hosted model that answers typed questions about a piece of state. You write the questions as evaluator params, the evaluator sends one request per session, and Kitaru stores one evaluation result per question.
|
|
32
|
+
|
|
33
|
+
## This package sends session content to TypeSafe
|
|
34
|
+
|
|
35
|
+
Every run of this evaluator sends part of a recorded session to TypeSafe's hosted API: what the user asked, the tool calls with their arguments and results, the final answer, and, on the `full` view, the system prompt and the model messages. Nothing is redacted for you.
|
|
36
|
+
|
|
37
|
+
That is why this is a separate package. Kitaru does not install it with the server, the server does not register it at startup, and no Kitaru deployment starts talking to TypeSafe until you submit an evaluation task and a worker executes it. The built-in `kitaru-evaluator` package stays offline and free; this one does not.
|
|
38
|
+
|
|
39
|
+
## Register the evaluator
|
|
40
|
+
|
|
41
|
+
You need a configured Kitaru CLI connected to your workspace, a TypeSafe API key, and a completed recorded or imported session. The [quickstart](https://docs.zenml.io/kitaru/getting-started/quickstart) provides returns-agent sessions matching the example below. Choose a session with `kitaru session list` and set `SESSION_ID` to its ID. Adapt the questions when evaluating another agent.
|
|
42
|
+
|
|
43
|
+
Save the connection schema that ships in the wheel at `kitaru_typesafe_evaluator/connection-schema.json` as `connection-schema.json` in your working directory:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"description": "TypeSafe connection.",
|
|
48
|
+
"properties": {
|
|
49
|
+
"TYPESAFE_API_KEY": {
|
|
50
|
+
"format": "password",
|
|
51
|
+
"title": "Typesafe Api Key",
|
|
52
|
+
"type": "string",
|
|
53
|
+
"writeOnly": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"required": ["TYPESAFE_API_KEY"],
|
|
57
|
+
"title": "TypeSafeConnection",
|
|
58
|
+
"type": "object"
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This file holds no secret. It declares a shape, and the shape is "this plugin needs one secret string called `TYPESAFE_API_KEY`". Registering the evaluator with it tells Kitaru what to ask you for later, nothing more. Never put your key in this file.
|
|
63
|
+
|
|
64
|
+
You type the key itself at a hidden prompt when you run `kitaru connection create`, and the server keeps it as an encrypted secret, the same way Kitaru's importers and analyzers hold their provider credentials.
|
|
65
|
+
|
|
66
|
+
Then register the evaluator under a name you choose:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
kitaru evaluator register typesafe-judge \
|
|
70
|
+
--package "kitaru-typesafe-evaluator==0.1.0" \
|
|
71
|
+
--entrypoint kitaru_typesafe_evaluator.judge:judge \
|
|
72
|
+
--provider typesafe \
|
|
73
|
+
--connection-schema connection-schema.json
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The worker installs the package itself when it claims the first evaluation task.
|
|
77
|
+
|
|
78
|
+
## Give the evaluator an API key
|
|
79
|
+
|
|
80
|
+
The evaluator creates a TypeSafe client, which reads `TYPESAFE_API_KEY` from the task's environment. Because you registered the evaluator with a provider and a connection schema, the key has to arrive one of two ways. If you set up neither, the evaluation job stays `pending` and no worker ever claims it.
|
|
81
|
+
|
|
82
|
+
Store the key on the server, and an evaluator worker can run the task:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
kitaru connection create typesafe-prod --evaluator typesafe-judge --default
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Ensure an evaluator worker is running. If needed, run `kitaru worker start --claim evaluator` in another terminal.
|
|
89
|
+
|
|
90
|
+
Or keep the key on one worker, and tell that worker to claim tasks that need it:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
export TYPESAFE_API_KEY=...
|
|
94
|
+
kitaru worker start --claim evaluator --selector kitaru/requires-credentials=typesafe
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Connections are resolved when a job is created. To recover an existing job pending for lack of credentials, start a worker with the key and selector above. Creating a default connection afterward only helps new jobs; submit a new evaluation after creating it.
|
|
98
|
+
|
|
99
|
+
## Ask a question
|
|
100
|
+
|
|
101
|
+
Save the following as `questions.json` in your working directory and keep that file in version control. The question text is the logic:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"questions": {
|
|
106
|
+
"invented_timeline": {
|
|
107
|
+
"type": "noul",
|
|
108
|
+
"pass_when": "no",
|
|
109
|
+
"instructions": "Does `final_answer` promise the customer a specific number of days or a date, where that number or date does not appear in any `tool_calls` result?"
|
|
110
|
+
},
|
|
111
|
+
"action_executed": {
|
|
112
|
+
"type": "noul",
|
|
113
|
+
"pass_when": "yes",
|
|
114
|
+
"instructions": "Does `tool_calls` contain a successful call that performs the action named in `final_answer.action` (issue_refund for refund, create_replacement for replacement, escalate_to_human for escalate)?"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
kitaru session evaluate "$SESSION_ID" \
|
|
122
|
+
--evaluator typesafe-judge@latest \
|
|
123
|
+
--evaluator-params "typesafe-judge@latest=$(cat questions.json)" \
|
|
124
|
+
--wait
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Each question becomes its own evaluation result, named after its key, carrying the probability of yes as the score and the full params that produced it. This is an illustrative summary, not literal CLI output:
|
|
128
|
+
|
|
129
|
+
```text
|
|
130
|
+
invented_timeline passed=False score=0.94 jev-1.13.0 · p(yes)=0.94 · fail: p(no)=0.06 is at or below 0.20
|
|
131
|
+
action_executed passed=True score=0.99 jev-1.13.0 · p(yes)=0.99 · pass: p(yes)=0.99 is at or above 0.80
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Read stored results with `kitaru evaluation list` and `kitaru evaluation get EVALUATION_ID`. The explanations above are generated threshold calculations, not model reasoning. Task completion does not mean every question passed. Missing session evidence does not automatically produce a held result, and model probabilities are not measured accuracy.
|
|
135
|
+
|
|
136
|
+
Use these questions for exploration first. Before using them as a gate, validate each failure check against human labels on sessions kept separate from question development, and report incorrect verdicts, held results, operational failures, and coverage.
|
|
137
|
+
|
|
138
|
+
See the [judge evaluations guide](https://docs.zenml.io/kitaru/guides/judge-evaluations) for the full params reference, the two state views, how to write questions jev answers steadily, what not to ask it, and how to calibrate it against human verdicts.
|
|
139
|
+
|
|
140
|
+
## Links
|
|
141
|
+
|
|
142
|
+
- [Kitaru documentation](https://docs.zenml.io/kitaru)
|
|
143
|
+
- [Source code](https://github.com/zenml-io/kitaru)
|
|
144
|
+
- [Issue tracker](https://github.com/zenml-io/kitaru/issues)
|
|
145
|
+
|
|
146
|
+
Licensed under Apache-2.0.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Kitaru TypeSafe evaluator
|
|
2
|
+
|
|
3
|
+
Judge recorded and imported Kitaru sessions with jev, TypeSafe's hosted model that answers typed questions about a piece of state. You write the questions as evaluator params, the evaluator sends one request per session, and Kitaru stores one evaluation result per question.
|
|
4
|
+
|
|
5
|
+
## This package sends session content to TypeSafe
|
|
6
|
+
|
|
7
|
+
Every run of this evaluator sends part of a recorded session to TypeSafe's hosted API: what the user asked, the tool calls with their arguments and results, the final answer, and, on the `full` view, the system prompt and the model messages. Nothing is redacted for you.
|
|
8
|
+
|
|
9
|
+
That is why this is a separate package. Kitaru does not install it with the server, the server does not register it at startup, and no Kitaru deployment starts talking to TypeSafe until you submit an evaluation task and a worker executes it. The built-in `kitaru-evaluator` package stays offline and free; this one does not.
|
|
10
|
+
|
|
11
|
+
## Register the evaluator
|
|
12
|
+
|
|
13
|
+
You need a configured Kitaru CLI connected to your workspace, a TypeSafe API key, and a completed recorded or imported session. The [quickstart](https://docs.zenml.io/kitaru/getting-started/quickstart) provides returns-agent sessions matching the example below. Choose a session with `kitaru session list` and set `SESSION_ID` to its ID. Adapt the questions when evaluating another agent.
|
|
14
|
+
|
|
15
|
+
Save the connection schema that ships in the wheel at `kitaru_typesafe_evaluator/connection-schema.json` as `connection-schema.json` in your working directory:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"description": "TypeSafe connection.",
|
|
20
|
+
"properties": {
|
|
21
|
+
"TYPESAFE_API_KEY": {
|
|
22
|
+
"format": "password",
|
|
23
|
+
"title": "Typesafe Api Key",
|
|
24
|
+
"type": "string",
|
|
25
|
+
"writeOnly": true
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"required": ["TYPESAFE_API_KEY"],
|
|
29
|
+
"title": "TypeSafeConnection",
|
|
30
|
+
"type": "object"
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This file holds no secret. It declares a shape, and the shape is "this plugin needs one secret string called `TYPESAFE_API_KEY`". Registering the evaluator with it tells Kitaru what to ask you for later, nothing more. Never put your key in this file.
|
|
35
|
+
|
|
36
|
+
You type the key itself at a hidden prompt when you run `kitaru connection create`, and the server keeps it as an encrypted secret, the same way Kitaru's importers and analyzers hold their provider credentials.
|
|
37
|
+
|
|
38
|
+
Then register the evaluator under a name you choose:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
kitaru evaluator register typesafe-judge \
|
|
42
|
+
--package "kitaru-typesafe-evaluator==0.1.0" \
|
|
43
|
+
--entrypoint kitaru_typesafe_evaluator.judge:judge \
|
|
44
|
+
--provider typesafe \
|
|
45
|
+
--connection-schema connection-schema.json
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The worker installs the package itself when it claims the first evaluation task.
|
|
49
|
+
|
|
50
|
+
## Give the evaluator an API key
|
|
51
|
+
|
|
52
|
+
The evaluator creates a TypeSafe client, which reads `TYPESAFE_API_KEY` from the task's environment. Because you registered the evaluator with a provider and a connection schema, the key has to arrive one of two ways. If you set up neither, the evaluation job stays `pending` and no worker ever claims it.
|
|
53
|
+
|
|
54
|
+
Store the key on the server, and an evaluator worker can run the task:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
kitaru connection create typesafe-prod --evaluator typesafe-judge --default
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Ensure an evaluator worker is running. If needed, run `kitaru worker start --claim evaluator` in another terminal.
|
|
61
|
+
|
|
62
|
+
Or keep the key on one worker, and tell that worker to claim tasks that need it:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
export TYPESAFE_API_KEY=...
|
|
66
|
+
kitaru worker start --claim evaluator --selector kitaru/requires-credentials=typesafe
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Connections are resolved when a job is created. To recover an existing job pending for lack of credentials, start a worker with the key and selector above. Creating a default connection afterward only helps new jobs; submit a new evaluation after creating it.
|
|
70
|
+
|
|
71
|
+
## Ask a question
|
|
72
|
+
|
|
73
|
+
Save the following as `questions.json` in your working directory and keep that file in version control. The question text is the logic:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"questions": {
|
|
78
|
+
"invented_timeline": {
|
|
79
|
+
"type": "noul",
|
|
80
|
+
"pass_when": "no",
|
|
81
|
+
"instructions": "Does `final_answer` promise the customer a specific number of days or a date, where that number or date does not appear in any `tool_calls` result?"
|
|
82
|
+
},
|
|
83
|
+
"action_executed": {
|
|
84
|
+
"type": "noul",
|
|
85
|
+
"pass_when": "yes",
|
|
86
|
+
"instructions": "Does `tool_calls` contain a successful call that performs the action named in `final_answer.action` (issue_refund for refund, create_replacement for replacement, escalate_to_human for escalate)?"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
kitaru session evaluate "$SESSION_ID" \
|
|
94
|
+
--evaluator typesafe-judge@latest \
|
|
95
|
+
--evaluator-params "typesafe-judge@latest=$(cat questions.json)" \
|
|
96
|
+
--wait
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Each question becomes its own evaluation result, named after its key, carrying the probability of yes as the score and the full params that produced it. This is an illustrative summary, not literal CLI output:
|
|
100
|
+
|
|
101
|
+
```text
|
|
102
|
+
invented_timeline passed=False score=0.94 jev-1.13.0 · p(yes)=0.94 · fail: p(no)=0.06 is at or below 0.20
|
|
103
|
+
action_executed passed=True score=0.99 jev-1.13.0 · p(yes)=0.99 · pass: p(yes)=0.99 is at or above 0.80
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Read stored results with `kitaru evaluation list` and `kitaru evaluation get EVALUATION_ID`. The explanations above are generated threshold calculations, not model reasoning. Task completion does not mean every question passed. Missing session evidence does not automatically produce a held result, and model probabilities are not measured accuracy.
|
|
107
|
+
|
|
108
|
+
Use these questions for exploration first. Before using them as a gate, validate each failure check against human labels on sessions kept separate from question development, and report incorrect verdicts, held results, operational failures, and coverage.
|
|
109
|
+
|
|
110
|
+
See the [judge evaluations guide](https://docs.zenml.io/kitaru/guides/judge-evaluations) for the full params reference, the two state views, how to write questions jev answers steadily, what not to ask it, and how to calibrate it against human verdicts.
|
|
111
|
+
|
|
112
|
+
## Links
|
|
113
|
+
|
|
114
|
+
- [Kitaru documentation](https://docs.zenml.io/kitaru)
|
|
115
|
+
- [Source code](https://github.com/zenml-io/kitaru)
|
|
116
|
+
- [Issue tracker](https://github.com/zenml-io/kitaru/issues)
|
|
117
|
+
|
|
118
|
+
Licensed under Apache-2.0.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "kitaru-typesafe-evaluator"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Judge Kitaru sessions with TypeSafe's jev model and your own questions."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
requires-python = ">=3.11"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "ZenML GmbH", email = "info@zenml.io" },
|
|
10
|
+
]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Intended Audience :: Science/Research",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
|
+
]
|
|
24
|
+
keywords = ["ai-agents", "evaluation", "kitaru", "llm", "typesafe", "jev"]
|
|
25
|
+
dependencies = ["kitaru>=0.22.0", "typesafe-sdk==0.6.0"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://kitaru.ai"
|
|
29
|
+
Documentation = "https://docs.zenml.io/kitaru/guides/judge-evaluations"
|
|
30
|
+
Repository = "https://github.com/zenml-io/kitaru"
|
|
31
|
+
Issues = "https://github.com/zenml-io/kitaru/issues"
|
|
32
|
+
Changelog = "https://github.com/zenml-io/kitaru/blob/develop/plugins/packages/typesafe-evaluator/CHANGELOG.md"
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["hatchling==1.32.0"]
|
|
36
|
+
build-backend = "hatchling.build"
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.wheel]
|
|
39
|
+
packages = ["src/kitaru_typesafe_evaluator"]
|
|
40
|
+
|
|
41
|
+
[tool.kitaru.artifact]
|
|
42
|
+
import-module = "kitaru_typesafe_evaluator"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright (c) ZenML GmbH 2026. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at:
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
12
|
+
# or implied. See the License for the specific language governing
|
|
13
|
+
# permissions and limitations under the License.
|
|
14
|
+
"""Judge evaluator for Kitaru backed by TypeSafe's jev model."""
|
|
15
|
+
|
|
16
|
+
from kitaru_typesafe_evaluator.connection import TypeSafeConnection
|
|
17
|
+
from kitaru_typesafe_evaluator.params import JudgeParams
|
|
18
|
+
|
|
19
|
+
__all__ = ["JudgeParams", "TypeSafeConnection"]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "TypeSafe connection.",
|
|
3
|
+
"properties": {
|
|
4
|
+
"TYPESAFE_API_KEY": {
|
|
5
|
+
"format": "password",
|
|
6
|
+
"title": "Typesafe Api Key",
|
|
7
|
+
"type": "string",
|
|
8
|
+
"writeOnly": true
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"required": [
|
|
12
|
+
"TYPESAFE_API_KEY"
|
|
13
|
+
],
|
|
14
|
+
"title": "TypeSafeConnection",
|
|
15
|
+
"type": "object"
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Copyright (c) ZenML GmbH 2026. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at:
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
12
|
+
# or implied. See the License for the specific language governing
|
|
13
|
+
# permissions and limitations under the License.
|
|
14
|
+
"""Connection values the judge evaluator reads."""
|
|
15
|
+
|
|
16
|
+
from pydantic import BaseModel, SecretStr
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TypeSafeConnection(BaseModel):
|
|
20
|
+
"""TypeSafe connection."""
|
|
21
|
+
|
|
22
|
+
TYPESAFE_API_KEY: SecretStr
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Copyright (c) ZenML GmbH 2026. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at:
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
12
|
+
# or implied. See the License for the specific language governing
|
|
13
|
+
# permissions and limitations under the License.
|
|
14
|
+
"""Judge evaluator entrypoint."""
|
|
15
|
+
|
|
16
|
+
import os
|
|
17
|
+
from typing import Any, cast
|
|
18
|
+
|
|
19
|
+
from typesafe_sdk import (
|
|
20
|
+
Question,
|
|
21
|
+
TypeSafeAuthenticationError,
|
|
22
|
+
TypeSafeBadRequestError,
|
|
23
|
+
TypeSafeClient,
|
|
24
|
+
TypeSafePermissionDeniedError,
|
|
25
|
+
)
|
|
26
|
+
from typesafe_sdk.constants import API_KEY_ENV
|
|
27
|
+
|
|
28
|
+
from kitaru.api_models.v1.evaluation import EvaluationResult
|
|
29
|
+
from kitaru.task.evaluator import SessionView
|
|
30
|
+
from kitaru_typesafe_evaluator.params import JudgeParams
|
|
31
|
+
from kitaru_typesafe_evaluator.results import build_result, build_unavailable_results
|
|
32
|
+
from kitaru_typesafe_evaluator.state import build_state, check_params_against_view
|
|
33
|
+
|
|
34
|
+
_TOO_LARGE = "max_tokens_exceeded"
|
|
35
|
+
_KEY_HELP = (
|
|
36
|
+
f"Set {API_KEY_ENV} in the worker environment, or store it once with "
|
|
37
|
+
"`kitaru connection create NAME --evaluator YOUR_EVALUATOR --default`."
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _build_client() -> TypeSafeClient:
|
|
42
|
+
"""Create the TypeSafe client from the task environment."""
|
|
43
|
+
if not os.environ.get(API_KEY_ENV):
|
|
44
|
+
raise RuntimeError(f"{API_KEY_ENV} is not set. {_KEY_HELP}")
|
|
45
|
+
return TypeSafeClient()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _is_too_large(error: TypeSafeBadRequestError) -> bool:
|
|
49
|
+
"""Check for jev's machine-readable size-limit tag."""
|
|
50
|
+
detail = error.body.get("detail") if isinstance(error.body, dict) else None
|
|
51
|
+
return isinstance(detail, dict) and detail.get("error_type") == _TOO_LARGE
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def judge(session: SessionView, **params: Any) -> list[EvaluationResult]:
|
|
55
|
+
"""Ask jev the configured questions about one session."""
|
|
56
|
+
config = JudgeParams.model_validate(params)
|
|
57
|
+
check_params_against_view(config)
|
|
58
|
+
state = build_state(session, config)
|
|
59
|
+
# to_wire() dumps a validated pydantic model, so its dict shape always
|
|
60
|
+
# matches one of the SDK's question TypedDicts; the cast just tells ty.
|
|
61
|
+
questions = cast(
|
|
62
|
+
"dict[str, Question]",
|
|
63
|
+
{name: question.to_wire() for name, question in config.questions.items()},
|
|
64
|
+
)
|
|
65
|
+
try:
|
|
66
|
+
with _build_client() as client:
|
|
67
|
+
response = client.system_one(
|
|
68
|
+
state=state, questions=questions, model=config.model
|
|
69
|
+
)
|
|
70
|
+
except TypeSafeBadRequestError as error:
|
|
71
|
+
# Only the size tag describes this one session. Any other 400 is a
|
|
72
|
+
# bug in the params or the request and would repeat on every session.
|
|
73
|
+
if not _is_too_large(error):
|
|
74
|
+
raise
|
|
75
|
+
# A run already on the 'outcome' view has no smaller built-in view left
|
|
76
|
+
# to fall back to, so only suggest narrowing it further with include.
|
|
77
|
+
hint = (
|
|
78
|
+
"Use the 'outcome' view or narrow it with include."
|
|
79
|
+
if config.state == "full"
|
|
80
|
+
else "Narrow it with include."
|
|
81
|
+
)
|
|
82
|
+
return build_unavailable_results(
|
|
83
|
+
config.questions,
|
|
84
|
+
f"The '{config.state}' state of this session is over jev's input "
|
|
85
|
+
f"limit. {hint}",
|
|
86
|
+
)
|
|
87
|
+
except (TypeSafeAuthenticationError, TypeSafePermissionDeniedError) as error:
|
|
88
|
+
raise RuntimeError(f"TypeSafe rejected {API_KEY_ENV}. {_KEY_HELP}") from error
|
|
89
|
+
missing = [name for name in config.questions if name not in response.answers]
|
|
90
|
+
if missing:
|
|
91
|
+
raise RuntimeError(f"jev returned no answer for questions {missing}")
|
|
92
|
+
return [
|
|
93
|
+
build_result(name, question, response.answers[name], response.model)
|
|
94
|
+
for name, question in config.questions.items()
|
|
95
|
+
]
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Copyright (c) ZenML GmbH 2026. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at:
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
12
|
+
# or implied. See the License for the specific language governing
|
|
13
|
+
# permissions and limitations under the License.
|
|
14
|
+
"""Params accepted by the judge evaluator."""
|
|
15
|
+
|
|
16
|
+
from typing import Annotated, Any, Literal, Self
|
|
17
|
+
|
|
18
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
19
|
+
|
|
20
|
+
from kitaru.api_models.v1.evaluation import EvaluationName
|
|
21
|
+
|
|
22
|
+
# jev rejects more than 255 choice options and more than 10 score levels.
|
|
23
|
+
MAX_CHOICE_OPTIONS = 255
|
|
24
|
+
MAX_SCORE_LEVELS = 10
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class _Question(BaseModel):
|
|
28
|
+
"""Fields shared by every question type."""
|
|
29
|
+
|
|
30
|
+
model_config = ConfigDict(extra="forbid")
|
|
31
|
+
|
|
32
|
+
instructions: str = Field(min_length=1)
|
|
33
|
+
|
|
34
|
+
def to_wire(self) -> dict[str, Any]:
|
|
35
|
+
"""Build the question object jev receives."""
|
|
36
|
+
return self.model_dump(include={"type", "instructions", "criteria"})
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class NoulQuestion(_Question):
|
|
40
|
+
"""Yes/no question answered with the probability of yes."""
|
|
41
|
+
|
|
42
|
+
type: Literal["noul"]
|
|
43
|
+
pass_when: Literal["yes", "no"] | None = None
|
|
44
|
+
decisive_at: float = Field(default=0.8, gt=0.5, le=1.0)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ChoiceQuestion(_Question):
|
|
48
|
+
"""Question answered with one label from a fixed set."""
|
|
49
|
+
|
|
50
|
+
type: Literal["choice"]
|
|
51
|
+
criteria: dict[str, str | None] = Field(min_length=2, max_length=MAX_CHOICE_OPTIONS)
|
|
52
|
+
pass_when: list[str] | None = Field(default=None, min_length=1)
|
|
53
|
+
|
|
54
|
+
@model_validator(mode="after")
|
|
55
|
+
def _check_pass_when_labels(self) -> Self:
|
|
56
|
+
unknown = set(self.pass_when or []) - set(self.criteria)
|
|
57
|
+
if unknown:
|
|
58
|
+
raise ValueError(
|
|
59
|
+
f"pass_when names labels missing from criteria: {sorted(unknown)}"
|
|
60
|
+
)
|
|
61
|
+
return self
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class ScoreQuestion(_Question):
|
|
65
|
+
"""Question answered with a position on ordered levels."""
|
|
66
|
+
|
|
67
|
+
type: Literal["score"]
|
|
68
|
+
criteria: list[str] = Field(min_length=2, max_length=MAX_SCORE_LEVELS)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Question = Annotated[
|
|
72
|
+
NoulQuestion | ChoiceQuestion | ScoreQuestion, Field(discriminator="type")
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class JudgeParams(BaseModel):
|
|
77
|
+
"""Params block of one judge run."""
|
|
78
|
+
|
|
79
|
+
model_config = ConfigDict(extra="forbid")
|
|
80
|
+
|
|
81
|
+
state: Literal["outcome", "full"] = "outcome"
|
|
82
|
+
include: list[str] | None = Field(default=None, min_length=1)
|
|
83
|
+
model: str | None = None
|
|
84
|
+
questions: dict[EvaluationName, Question] = Field(min_length=1)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Copyright (c) ZenML GmbH 2026. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at:
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
12
|
+
# or implied. See the License for the specific language governing
|
|
13
|
+
# permissions and limitations under the License.
|
|
14
|
+
"""Map jev answers onto Kitaru evaluation results."""
|
|
15
|
+
|
|
16
|
+
from collections.abc import Iterable
|
|
17
|
+
from typing import Literal
|
|
18
|
+
|
|
19
|
+
from typesafe_sdk import ChoiceAnswer, NoulAnswer, ScoreAnswer
|
|
20
|
+
|
|
21
|
+
from kitaru.api_models.v1.evaluation import EvaluationResult
|
|
22
|
+
from kitaru_typesafe_evaluator.params import ChoiceQuestion, NoulQuestion, ScoreQuestion
|
|
23
|
+
|
|
24
|
+
# TypeSafe advises never acting on a choice whose confidence is under 0.5.
|
|
25
|
+
CHOICE_MIN_CONFIDENCE = 0.5
|
|
26
|
+
|
|
27
|
+
Answer = NoulAnswer | ChoiceAnswer | ScoreAnswer
|
|
28
|
+
Question = NoulQuestion | ChoiceQuestion | ScoreQuestion
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def decide_noul_verdict(
|
|
32
|
+
probability_yes: float,
|
|
33
|
+
pass_when: Literal["yes", "no"] | None,
|
|
34
|
+
decisive_at: float,
|
|
35
|
+
) -> bool | None:
|
|
36
|
+
"""Turn jev's probability of yes into pass, fail, or held.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
probability_yes: Probability jev gave to the answer yes.
|
|
40
|
+
pass_when: Answer that counts as passing, or None for no verdict.
|
|
41
|
+
decisive_at: Probability the good answer must reach to pass. The
|
|
42
|
+
bad answer fails the check at the same level.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
True for pass, False for fail, None when held or when pass_when is None.
|
|
46
|
+
"""
|
|
47
|
+
if pass_when is None:
|
|
48
|
+
return None
|
|
49
|
+
good = probability_yes if pass_when == "yes" else 1 - probability_yes
|
|
50
|
+
# Round before comparing at the band edges: 1 - 0.8 is 0.19999999999999996
|
|
51
|
+
# in binary floats, so an unrounded 0.20 would be held instead of failed.
|
|
52
|
+
good = round(good, 9)
|
|
53
|
+
bad = round(1 - good, 9)
|
|
54
|
+
if good >= decisive_at:
|
|
55
|
+
return True
|
|
56
|
+
if bad >= decisive_at:
|
|
57
|
+
return False
|
|
58
|
+
return None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _explain_noul(
|
|
62
|
+
question: NoulQuestion, probability_yes: float, passed: bool | None
|
|
63
|
+
) -> str:
|
|
64
|
+
"""Explain a noul verdict in terms of the probability band that decided it."""
|
|
65
|
+
if question.pass_when is None:
|
|
66
|
+
return f"p(yes)={probability_yes:.2f}"
|
|
67
|
+
low, high = 1 - question.decisive_at, question.decisive_at
|
|
68
|
+
if passed is None:
|
|
69
|
+
return f"p(yes)={probability_yes:.2f} · held: between {low:.2f} and {high:.2f}"
|
|
70
|
+
good = probability_yes if question.pass_when == "yes" else 1 - probability_yes
|
|
71
|
+
if passed:
|
|
72
|
+
return (
|
|
73
|
+
f"p(yes)={probability_yes:.2f} · pass: p({question.pass_when})={good:.2f} "
|
|
74
|
+
f"is at or above {high:.2f}"
|
|
75
|
+
)
|
|
76
|
+
return (
|
|
77
|
+
f"p(yes)={probability_yes:.2f} · fail: p({question.pass_when})={good:.2f} "
|
|
78
|
+
f"is at or below {low:.2f}"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def build_result(
|
|
83
|
+
name: str, question: Question, answer: Answer, model: str
|
|
84
|
+
) -> EvaluationResult:
|
|
85
|
+
"""Build the evaluation result for one answered question."""
|
|
86
|
+
if isinstance(question, NoulQuestion) and isinstance(answer, NoulAnswer):
|
|
87
|
+
passed = decide_noul_verdict(
|
|
88
|
+
answer.noul, question.pass_when, question.decisive_at
|
|
89
|
+
)
|
|
90
|
+
return EvaluationResult(
|
|
91
|
+
name=name,
|
|
92
|
+
score=answer.noul,
|
|
93
|
+
min_score=0.0,
|
|
94
|
+
max_score=1.0,
|
|
95
|
+
passed=passed,
|
|
96
|
+
explanation=f"{model} · {_explain_noul(question, answer.noul, passed)}",
|
|
97
|
+
)
|
|
98
|
+
if isinstance(question, ChoiceQuestion) and isinstance(answer, ChoiceAnswer):
|
|
99
|
+
sure = answer.confidence >= CHOICE_MIN_CONFIDENCE
|
|
100
|
+
passed = (
|
|
101
|
+
answer.choice in question.pass_when if question.pass_when and sure else None
|
|
102
|
+
)
|
|
103
|
+
return EvaluationResult(
|
|
104
|
+
name=name,
|
|
105
|
+
value=answer.choice,
|
|
106
|
+
score=answer.confidence,
|
|
107
|
+
passed=passed,
|
|
108
|
+
explanation=f"{model} · confidence={answer.confidence:.2f}",
|
|
109
|
+
)
|
|
110
|
+
if isinstance(question, ScoreQuestion) and isinstance(answer, ScoreAnswer):
|
|
111
|
+
return EvaluationResult(
|
|
112
|
+
name=name,
|
|
113
|
+
score=answer.score,
|
|
114
|
+
min_score=0.0,
|
|
115
|
+
max_score=float(len(question.criteria) - 1),
|
|
116
|
+
explanation=f"{model} · confidence={answer.confidence:.2f}",
|
|
117
|
+
)
|
|
118
|
+
raise TypeError(
|
|
119
|
+
f"jev answered question '{name}' with a {type(answer).__name__}, which "
|
|
120
|
+
f"does not match its type '{question.type}'"
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def build_unavailable_results(
|
|
125
|
+
names: Iterable[str], reason: str
|
|
126
|
+
) -> list[EvaluationResult]:
|
|
127
|
+
"""Build one unavailable result per question."""
|
|
128
|
+
return [
|
|
129
|
+
EvaluationResult(name=name, value="unavailable", explanation=reason)
|
|
130
|
+
for name in names
|
|
131
|
+
]
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Copyright (c) ZenML GmbH 2026. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at:
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
12
|
+
# or implied. See the License for the specific language governing
|
|
13
|
+
# permissions and limitations under the License.
|
|
14
|
+
"""Build the state jev judges from a recorded session."""
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
from datetime import date
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
from kitaru.api_models.v1.session_node import NodeType, SessionNodeResponse
|
|
22
|
+
from kitaru.json_pointer import resolve_json_pointer
|
|
23
|
+
from kitaru.task.evaluator import SessionView
|
|
24
|
+
from kitaru_typesafe_evaluator.params import (
|
|
25
|
+
ChoiceQuestion,
|
|
26
|
+
JudgeParams,
|
|
27
|
+
NoulQuestion,
|
|
28
|
+
ScoreQuestion,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
_OUTCOME_FIELDS = ("request", "tool_calls", "final_answer")
|
|
32
|
+
# Questions name these fields in backticks, so renaming one silently degrades
|
|
33
|
+
# every question a user has already written.
|
|
34
|
+
VIEW_FIELDS: dict[str, tuple[str, ...]] = {
|
|
35
|
+
"outcome": _OUTCOME_FIELDS,
|
|
36
|
+
"full": (*_OUTCOME_FIELDS, "system_prompt", "model_messages"),
|
|
37
|
+
}
|
|
38
|
+
_BACKTICKED = re.compile(r"`([^`]+)`")
|
|
39
|
+
_FIRST_SEGMENT = re.compile(r"[A-Za-z_]+")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _resolve_text(document: Any, pointer: str | None) -> Any:
|
|
43
|
+
"""Return the value a JSON pointer selects, or None when it selects nothing."""
|
|
44
|
+
if pointer is None:
|
|
45
|
+
return None
|
|
46
|
+
found, value = resolve_json_pointer(document, pointer)
|
|
47
|
+
return value if found else None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _sort_nodes(nodes: list[SessionNodeResponse]) -> list[SessionNodeResponse]:
|
|
51
|
+
"""Order nodes by start time, nodes without one kept last in recorded order."""
|
|
52
|
+
# Pair each timed node with its original index so the sort key never needs
|
|
53
|
+
# to narrow `started_at` back from `datetime | None`, and ties break by
|
|
54
|
+
# recorded order instead of relying on Python's stable-sort side effect.
|
|
55
|
+
timed = sorted(
|
|
56
|
+
(
|
|
57
|
+
(node.started_at, index, node)
|
|
58
|
+
for index, node in enumerate(nodes)
|
|
59
|
+
if node.started_at is not None
|
|
60
|
+
),
|
|
61
|
+
key=lambda item: item[:2],
|
|
62
|
+
)
|
|
63
|
+
return [node for _, _, node in timed] + [
|
|
64
|
+
node for node in nodes if node.started_at is None
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _find_request(session: SessionView, nodes: list[SessionNodeResponse]) -> Any:
|
|
69
|
+
"""Find what the user asked for."""
|
|
70
|
+
selected = _resolve_text(
|
|
71
|
+
session.session.inputs, session.session.input_text_selector
|
|
72
|
+
)
|
|
73
|
+
if selected is not None:
|
|
74
|
+
return selected
|
|
75
|
+
# Imported sessions wrap their inputs together with their outputs, so the
|
|
76
|
+
# first node's own input text is the cleanest statement of the request.
|
|
77
|
+
for node in nodes:
|
|
78
|
+
selected = _resolve_text(node.inputs, node.input_text_selector)
|
|
79
|
+
if selected is not None:
|
|
80
|
+
return selected
|
|
81
|
+
return session.session.inputs
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _find_system_prompt(nodes: list[SessionNodeResponse]) -> Any:
|
|
85
|
+
for node in nodes:
|
|
86
|
+
selected = _resolve_text(node.inputs, node.system_prompt_selector)
|
|
87
|
+
if selected is not None:
|
|
88
|
+
return selected
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _to_json_safe(value: Any) -> str:
|
|
93
|
+
"""Render a value json cannot encode, keeping dates in ISO form."""
|
|
94
|
+
return value.isoformat() if isinstance(value, date) else str(value)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def build_state(session: SessionView, params: JudgeParams) -> dict[str, Any]:
|
|
98
|
+
"""Build the JSON state for the chosen view, narrowed by include."""
|
|
99
|
+
nodes = _sort_nodes(session.nodes)
|
|
100
|
+
llm_calls = [n for n in nodes if n.node_type is NodeType.LLM_CALL]
|
|
101
|
+
fields: dict[str, Any] = {
|
|
102
|
+
"request": _find_request(session, nodes),
|
|
103
|
+
"tool_calls": [
|
|
104
|
+
{
|
|
105
|
+
"tool": n.tool_name or n.name,
|
|
106
|
+
"arguments": n.inputs,
|
|
107
|
+
"result": n.outputs,
|
|
108
|
+
"error": n.error,
|
|
109
|
+
}
|
|
110
|
+
for n in nodes
|
|
111
|
+
if n.node_type is NodeType.TOOL_CALL
|
|
112
|
+
],
|
|
113
|
+
"final_answer": session.session.outputs,
|
|
114
|
+
"system_prompt": _find_system_prompt(llm_calls),
|
|
115
|
+
"model_messages": [
|
|
116
|
+
{"model": n.model, "input": n.inputs, "output": n.outputs}
|
|
117
|
+
for n in llm_calls
|
|
118
|
+
],
|
|
119
|
+
}
|
|
120
|
+
keep = params.include or VIEW_FIELDS[params.state]
|
|
121
|
+
state = {name: fields[name] for name in VIEW_FIELDS[params.state] if name in keep}
|
|
122
|
+
# Recorded payloads can hold datetimes and decimals the SDK cannot serialize.
|
|
123
|
+
return json.loads(json.dumps(state, default=_to_json_safe))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _get_question_texts(
|
|
127
|
+
question: NoulQuestion | ChoiceQuestion | ScoreQuestion,
|
|
128
|
+
) -> list[str]:
|
|
129
|
+
texts = [question.instructions]
|
|
130
|
+
if isinstance(question, ChoiceQuestion):
|
|
131
|
+
texts += [*question.criteria, *(d for d in question.criteria.values() if d)]
|
|
132
|
+
if isinstance(question, ScoreQuestion):
|
|
133
|
+
texts += question.criteria
|
|
134
|
+
return texts
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def check_params_against_view(params: JudgeParams) -> None:
|
|
138
|
+
"""Reject include names and question field references the state will not contain."""
|
|
139
|
+
view_fields = VIEW_FIELDS[params.state]
|
|
140
|
+
unknown = [name for name in params.include or [] if name not in view_fields]
|
|
141
|
+
if unknown:
|
|
142
|
+
raise ValueError(
|
|
143
|
+
f"include names {unknown} are not fields of the '{params.state}' "
|
|
144
|
+
f"view {list(view_fields)}"
|
|
145
|
+
)
|
|
146
|
+
sent = set(params.include or view_fields)
|
|
147
|
+
known = set(VIEW_FIELDS["full"])
|
|
148
|
+
for question_id, question in params.questions.items():
|
|
149
|
+
for text in _get_question_texts(question):
|
|
150
|
+
for reference in _BACKTICKED.findall(text):
|
|
151
|
+
match = _FIRST_SEGMENT.match(reference)
|
|
152
|
+
field = match.group(0) if match else None
|
|
153
|
+
if field in known and field not in sent:
|
|
154
|
+
hint = (
|
|
155
|
+
"use the 'full' view"
|
|
156
|
+
if field not in view_fields
|
|
157
|
+
else "add it to include"
|
|
158
|
+
)
|
|
159
|
+
raise ValueError(
|
|
160
|
+
f"Question '{question_id}' refers to `{field}`, which is "
|
|
161
|
+
f"not sent to jev; {hint}."
|
|
162
|
+
)
|