tuieval 0.2.0.dev166__py3-none-any.whl → 0.3.0.dev2__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.
- tuieval/_version.py +2 -2
- tuieval/adapters/__init__.py +1 -0
- tuieval/adapters/pi.py +352 -0
- tuieval/agents.py +14 -4
- tuieval/builtin.toml +12 -2
- tuieval/compare.py +10 -1
- tuieval/engine.py +5 -3
- {tuieval-0.2.0.dev166.dist-info → tuieval-0.3.0.dev2.dist-info}/METADATA +1 -1
- {tuieval-0.2.0.dev166.dist-info → tuieval-0.3.0.dev2.dist-info}/RECORD +12 -10
- {tuieval-0.2.0.dev166.dist-info → tuieval-0.3.0.dev2.dist-info}/WHEEL +0 -0
- {tuieval-0.2.0.dev166.dist-info → tuieval-0.3.0.dev2.dist-info}/entry_points.txt +0 -0
- {tuieval-0.2.0.dev166.dist-info → tuieval-0.3.0.dev2.dist-info}/licenses/LICENSE +0 -0
tuieval/_version.py
CHANGED
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '0.
|
|
22
|
-
__version_tuple__ = version_tuple = (0,
|
|
21
|
+
__version__ = version = '0.3.0.dev2'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 3, 0, 'dev2')
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Adapters that run command-line agents for agent packs (docs/agent-packs.md)."""
|
tuieval/adapters/pi.py
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"""The built-in adapter for pi (https://github.com/earendil-works/pi), for agent packs: runs bare pi on the
|
|
2
|
+
model tuieval serves.
|
|
3
|
+
|
|
4
|
+
[agents.pi] cmd = ["{tuieval_python}", "-m", "tuieval.adapters.pi"] (built in)
|
|
5
|
+
[agents.pi-scouts] cmd = ["{tuieval_python}", "-m", "tuieval.adapters.pi", "--scouts"] (built in)
|
|
6
|
+
|
|
7
|
+
pi gets a scratch config folder with one provider, "tuieval", pointing at TUIEVAL_BASE_URL (context size and
|
|
8
|
+
sampling from tuieval), and runs with no extensions, skills, context files, prompt templates, themes, MCP or saved
|
|
9
|
+
session, so your own pi setup never changes a result. One line per turn and tool call is printed for the live
|
|
10
|
+
view; the stats go to TUIEVAL_STATS_FILE.
|
|
11
|
+
|
|
12
|
+
On macOS pi runs inside a sandbox (sandbox-exec, see sandbox_profile): it can't read your home folder or the temp
|
|
13
|
+
folders, apart from the task's work folder, the adapter's own scratch folder and the pack's Python, and it can
|
|
14
|
+
write only those two folders. So a model can't look up hidden tests or reference fixes, or leave notes for the
|
|
15
|
+
next model. HOME and TMPDIR point into the scratch folder. TUIEVAL_NO_SANDBOX=1 turns the sandbox off (the run
|
|
16
|
+
line then says "sandbox OFF"); without sandbox-exec (other systems) there is none.
|
|
17
|
+
|
|
18
|
+
--scouts adds pi's example subagent extension (the one explicit -e; everything else stays off) and one agent,
|
|
19
|
+
"scout": read-only tools (read, grep, find, ls), the model tuieval serves at thinking "low", and SCOUT_PROMPT.
|
|
20
|
+
The lead gets one appended system line saying the tool exists (SCOUT_HINT); the task text is unchanged, and
|
|
21
|
+
whether to delegate is the lead's own choice. Scouts are child pi processes of the sandboxed pi, so the sandbox
|
|
22
|
+
covers them too, and they use the same scratch config. Their turns and tokens are added to the run's totals and
|
|
23
|
+
also written as subagent_* stats; the turn limit counts the lead's turns only.
|
|
24
|
+
|
|
25
|
+
Standard library only: it runs with tuieval's own Python, whatever the pack's Python is.
|
|
26
|
+
"""
|
|
27
|
+
import json
|
|
28
|
+
import os
|
|
29
|
+
import shutil
|
|
30
|
+
import signal
|
|
31
|
+
import subprocess
|
|
32
|
+
import sys
|
|
33
|
+
import tempfile
|
|
34
|
+
|
|
35
|
+
PI_LEVELS = ("off", "minimal", "low", "medium", "high", "xhigh", "max")
|
|
36
|
+
SAMPLING_KEYS = ("temperature", "top_p", "top_k", "min_p", "presence_penalty", "repeat_penalty")
|
|
37
|
+
# provider errors that are the server's fault, not the model's (tuieval asks the task again)
|
|
38
|
+
SERVER_ERRORS = ("ECONNREFUSED", "ECONNRESET", "socket hang up", "fetch failed", "502", "503",
|
|
39
|
+
"Internal Server Error", "Service Unavailable", "Bad Gateway")
|
|
40
|
+
SUBAGENT_STATS = ("subagent_calls", "subagent_tasks", "subagent_failed", "subagent_turns", "subagent_input_tokens",
|
|
41
|
+
"subagent_output_tokens")
|
|
42
|
+
|
|
43
|
+
SCOUT_HINT = ("You have a `subagent` tool with a read-only `scout` agent (read, grep, find, ls). When a task needs "
|
|
44
|
+
"context from several independent parts of the code, you can send scouts in parallel to gather it "
|
|
45
|
+
"first; edits, commands and tests stay with you.")
|
|
46
|
+
SCOUT_PROMPT = """You are a scout. Quickly investigate a codebase and return structured findings that another agent can use without re-reading everything.
|
|
47
|
+
|
|
48
|
+
Your output will be passed to an agent who has NOT seen the files you explored.
|
|
49
|
+
|
|
50
|
+
Thoroughness (infer from task, default medium):
|
|
51
|
+
- Quick: Targeted lookups, key files only
|
|
52
|
+
- Medium: Follow imports, read critical sections
|
|
53
|
+
- Thorough: Trace all dependencies, check tests/types
|
|
54
|
+
|
|
55
|
+
Strategy:
|
|
56
|
+
1. grep/find to locate relevant code
|
|
57
|
+
2. Read key sections (not entire files)
|
|
58
|
+
3. Identify types, interfaces, key functions
|
|
59
|
+
4. Note dependencies between files
|
|
60
|
+
|
|
61
|
+
Output format:
|
|
62
|
+
|
|
63
|
+
## Files Retrieved
|
|
64
|
+
List with exact line ranges:
|
|
65
|
+
1. `path/to/file.ts` (lines 10-50) - Description of what's here
|
|
66
|
+
2. `path/to/other.ts` (lines 100-150) - Description
|
|
67
|
+
3. ...
|
|
68
|
+
|
|
69
|
+
## Key Code
|
|
70
|
+
Critical types, interfaces, or functions:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
interface Example {
|
|
74
|
+
// actual code from the files
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
function keyFunction() {
|
|
80
|
+
// actual implementation
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Architecture
|
|
85
|
+
Brief explanation of how the pieces connect.
|
|
86
|
+
|
|
87
|
+
## Start Here
|
|
88
|
+
Which file to look at first and why.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def pi_version():
|
|
93
|
+
try:
|
|
94
|
+
out = subprocess.run(["pi", "--version"], capture_output=True, text=True, timeout=30).stdout.strip()
|
|
95
|
+
return f"pi {out}" if out else "pi"
|
|
96
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
97
|
+
return "pi"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def subagent_extension():
|
|
101
|
+
"""pi's example subagent extension, found from the pi on PATH (its package root holds examples/)."""
|
|
102
|
+
d = os.path.dirname(os.path.realpath(shutil.which("pi") or "pi"))
|
|
103
|
+
while d != os.path.dirname(d):
|
|
104
|
+
pkg = os.path.join(d, "package.json")
|
|
105
|
+
if os.path.isfile(pkg):
|
|
106
|
+
try:
|
|
107
|
+
name = json.load(open(pkg)).get("name", "")
|
|
108
|
+
except ValueError:
|
|
109
|
+
name = ""
|
|
110
|
+
if name.endswith("/pi-coding-agent"):
|
|
111
|
+
ext = os.path.join(d, "examples", "extensions", "subagent", "index.ts")
|
|
112
|
+
if os.path.isfile(ext):
|
|
113
|
+
return ext
|
|
114
|
+
break
|
|
115
|
+
d = os.path.dirname(d)
|
|
116
|
+
return None
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def config(dest, sampling, model_id, scouts=False):
|
|
120
|
+
"""A pi config folder with one provider, "tuieval", serving model_id (and, for scouts, the scout agent)."""
|
|
121
|
+
ctx = int(os.environ.get("TUIEVAL_CONTEXT") or 32768)
|
|
122
|
+
params = {k: sampling[k] for k in SAMPLING_KEYS if k in sampling}
|
|
123
|
+
if "enable_thinking" in sampling:
|
|
124
|
+
params["chat_template_kwargs"] = {"enable_thinking": bool(sampling["enable_thinking"])}
|
|
125
|
+
model = {"id": model_id, "name": model_id, "reasoning": True, "input": ["text"], "contextWindow": ctx,
|
|
126
|
+
"maxTokens": min(int(sampling.get("max_tokens") or 16384), ctx), "samplingParams": params,
|
|
127
|
+
# requests like tuieval's own: max_tokens (not max_completion_tokens), and reasoning_effort only
|
|
128
|
+
# when the model sets one (pi would otherwise send its default level)
|
|
129
|
+
"compat": {"maxTokensField": "max_tokens",
|
|
130
|
+
**({} if sampling.get("reasoning_effort") else {"supportsReasoningEffort": False})}}
|
|
131
|
+
providers = {"tuieval": {"baseUrl": os.environ["TUIEVAL_BASE_URL"], "api": "openai-completions",
|
|
132
|
+
"apiKey": os.environ.get("TUIEVAL_API_KEY") or "none", "models": [model]}}
|
|
133
|
+
os.makedirs(dest, mode=0o700, exist_ok=True)
|
|
134
|
+
with open(os.path.join(dest, "models.json"), "w") as f:
|
|
135
|
+
json.dump({"providers": providers}, f, indent=1)
|
|
136
|
+
with open(os.path.join(dest, "settings.json"), "w") as f:
|
|
137
|
+
json.dump({"quietStartup": True}, f)
|
|
138
|
+
if scouts:
|
|
139
|
+
os.makedirs(os.path.join(dest, "agents"), exist_ok=True)
|
|
140
|
+
with open(os.path.join(dest, "agents", "scout.md"), "w") as f:
|
|
141
|
+
f.write("---\nname: scout\ndescription: Fast codebase recon that returns compressed context for handoff "
|
|
142
|
+
f"to other agents\ntools: read, grep, find, ls\nmodel: tuieval/{model_id}:low\n---\n\n"
|
|
143
|
+
+ SCOUT_PROMPT)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def sandbox_profile(work, scratch, python_dirs):
|
|
147
|
+
"""A macOS sandbox (sandbox-exec) profile for pi and everything it runs, so a model can't look up answers
|
|
148
|
+
or leave notes for the next model:
|
|
149
|
+
reads nothing in your home folder, the temp folders or /Volumes, except the task's work folder, the
|
|
150
|
+
adapter's own scratch folder (pi config, HOME, TMPDIR) and the pack's Python
|
|
151
|
+
writes only the work folder, the scratch folder and /dev
|
|
152
|
+
escapes no Apple Events (Office, Terminal, System Events…), no LaunchServices (`open -a …`), no
|
|
153
|
+
launchctl/at/crontab, no ssh to this Mac: each would run code outside the sandbox
|
|
154
|
+
Everything else (the pi install, system libraries, the network to the model server) is allowed."""
|
|
155
|
+
q = lambda p: json.dumps(os.path.realpath(p)) # SBPL strings use the same escapes as JSON
|
|
156
|
+
home = os.path.realpath(os.path.expanduser("~"))
|
|
157
|
+
hidden = [home, "/private/tmp", "/private/var/tmp", "/private/var/folders"]
|
|
158
|
+
hidden += [p for p in ("/Volumes",) if os.path.isdir(p)]
|
|
159
|
+
ok_rw = [work, scratch]
|
|
160
|
+
rules = ["(version 1)", "(allow default)",
|
|
161
|
+
"(deny file-read* " + " ".join(f"(subpath {q(p)})" for p in hidden) + ")",
|
|
162
|
+
"(allow file-read* " + " ".join(f"(subpath {q(p)})" for p in ok_rw + python_dirs) + ")",
|
|
163
|
+
"(allow file-read-metadata)", # stat() on parent folders, which path lookups need; no contents
|
|
164
|
+
"(deny file-write* (require-not (require-any "
|
|
165
|
+
+ " ".join(f"(subpath {q(p)})" for p in ok_rw) + ' (subpath "/dev"))))',
|
|
166
|
+
"(deny appleevent-send)",
|
|
167
|
+
'(deny mach-lookup (global-name "com.apple.coreservices.launchservicesd")'
|
|
168
|
+
' (global-name "com.apple.coreservices.quarantine-resolver"))',
|
|
169
|
+
'(deny process-exec (literal "/bin/launchctl") (literal "/usr/bin/at") (literal "/usr/bin/crontab")'
|
|
170
|
+
' (literal "/usr/bin/open") (literal "/usr/bin/ssh") (literal "/usr/bin/osascript")'
|
|
171
|
+
' (literal "/usr/bin/shortcuts") (literal "/usr/bin/automator"))',
|
|
172
|
+
'(deny network-outbound (remote tcp "localhost:22"))']
|
|
173
|
+
return "\n".join(rules)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def python_dirs():
|
|
177
|
+
"""Folders the pack's Python needs to read: its venv (first on PATH, put there by tuieval) and the base
|
|
178
|
+
install the venv points at."""
|
|
179
|
+
dirs = []
|
|
180
|
+
first = (os.environ.get("PATH") or "").split(os.pathsep)[0]
|
|
181
|
+
venv = os.path.dirname(first)
|
|
182
|
+
cfg = os.path.join(venv, "pyvenv.cfg")
|
|
183
|
+
if os.path.isfile(cfg):
|
|
184
|
+
dirs.append(venv)
|
|
185
|
+
for line in open(cfg):
|
|
186
|
+
k, _, v = line.partition("=")
|
|
187
|
+
if k.strip() == "home" and v.strip():
|
|
188
|
+
dirs.append(os.path.dirname(os.path.realpath(v.strip()))) # …/bin -> the install
|
|
189
|
+
return dirs
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def thinking(sampling):
|
|
193
|
+
if sampling.get("enable_thinking") is False:
|
|
194
|
+
return "off"
|
|
195
|
+
effort = sampling.get("reasoning_effort")
|
|
196
|
+
return effort if effort in PI_LEVELS else None
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def short(v, n=140):
|
|
200
|
+
v = " ".join(str(v).split())
|
|
201
|
+
return v if len(v) <= n else v[:n - 1] + "…"
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def add_subagents(stats, ev):
|
|
205
|
+
"""Count a finished subagent tool call (pi's example extension) into stats; returns its summary line."""
|
|
206
|
+
rs = ((ev.get("result") or {}).get("details") or {}).get("results") or []
|
|
207
|
+
stats["subagent_calls"] += 1
|
|
208
|
+
turns = out = 0
|
|
209
|
+
for r in rs:
|
|
210
|
+
u = r.get("usage") or {}
|
|
211
|
+
stats["subagent_tasks"] += 1
|
|
212
|
+
stats["subagent_failed"] += int(r.get("exitCode") not in (0, None) or r.get("status") == "failed")
|
|
213
|
+
tokens_in = (u.get("input") or 0) + (u.get("cacheRead") or 0)
|
|
214
|
+
stats["subagent_turns"] += u.get("turns") or 0
|
|
215
|
+
stats["subagent_input_tokens"] += tokens_in
|
|
216
|
+
stats["subagent_output_tokens"] += u.get("output") or 0
|
|
217
|
+
stats["input_tokens"] += tokens_in
|
|
218
|
+
stats["output_tokens"] += u.get("output") or 0
|
|
219
|
+
turns += u.get("turns") or 0
|
|
220
|
+
out += u.get("output") or 0
|
|
221
|
+
if ev.get("isError"):
|
|
222
|
+
stats["tool_errors"] += 1
|
|
223
|
+
return f" subagents: {len(rs)} task(s), {turns} turns, {out} output tokens" + (" [error]" if ev.get("isError") else "")
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def build_command(model_id, sampling, prompt, scouts, extension):
|
|
227
|
+
cmd = ["pi", "--mode", "json", "--no-session", "--no-extensions", "--no-skills", "--no-context-files",
|
|
228
|
+
"--no-prompt-templates", "--no-themes", "--no-mcp", "--no-approve", "--offline",
|
|
229
|
+
"--model", "tuieval/" + model_id]
|
|
230
|
+
if scouts:
|
|
231
|
+
cmd += ["-e", extension, "--append-system-prompt", SCOUT_HINT]
|
|
232
|
+
level = thinking(sampling)
|
|
233
|
+
if level:
|
|
234
|
+
cmd += ["--thinking", level]
|
|
235
|
+
return cmd + ["--", prompt], level
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def main(argv=None):
|
|
239
|
+
argv = sys.argv[1:] if argv is None else argv
|
|
240
|
+
scouts = "--scouts" in argv
|
|
241
|
+
sampling = json.loads(os.environ.get("TUIEVAL_SAMPLING") or "{}")
|
|
242
|
+
max_turns = int(os.environ.get("TUIEVAL_MAX_TURNS") or 40)
|
|
243
|
+
prompt = open(os.environ["TUIEVAL_PROMPT_FILE"]).read()
|
|
244
|
+
model_id = os.environ["TUIEVAL_MODEL_ID"]
|
|
245
|
+
stats = {"agent": pi_version() + (" + scouts" if scouts else ""), "turns": 0, "input_tokens": 0,
|
|
246
|
+
"output_tokens": 0, "tool_calls": 0, "tool_errors": 0, "ran_tests": False, "stop": "", "final_message": ""}
|
|
247
|
+
extension = None
|
|
248
|
+
if scouts:
|
|
249
|
+
stats.update(dict.fromkeys(SUBAGENT_STATS, 0))
|
|
250
|
+
extension = subagent_extension()
|
|
251
|
+
if not extension:
|
|
252
|
+
print("pi's examples/extensions/subagent/index.ts wasn't found next to the pi on PATH", flush=True)
|
|
253
|
+
stats.update(stop="error", final_message="no subagent extension")
|
|
254
|
+
save(stats)
|
|
255
|
+
return 1
|
|
256
|
+
tmp = tempfile.mkdtemp(prefix="pi-adapter-")
|
|
257
|
+
cfg_dir = os.path.join(tmp, "pi-config")
|
|
258
|
+
config(cfg_dir, sampling, model_id, scouts)
|
|
259
|
+
cmd, level = build_command(model_id, sampling, prompt, scouts, extension)
|
|
260
|
+
env = dict(os.environ, PI_CODING_AGENT_DIR=cfg_dir, PI_OFFLINE="1", PI_TELEMETRY="0")
|
|
261
|
+
shown = " ".join(cmd[:-1])
|
|
262
|
+
sandbox = os.environ.get("TUIEVAL_NO_SANDBOX") != "1" and shutil.which("sandbox-exec")
|
|
263
|
+
if sandbox:
|
|
264
|
+
fake_home, fake_tmp = os.path.join(tmp, "home"), os.path.join(tmp, "tmp")
|
|
265
|
+
os.makedirs(fake_home)
|
|
266
|
+
os.makedirs(fake_tmp)
|
|
267
|
+
env.update(HOME=fake_home, TMPDIR=fake_tmp + "/", ZDOTDIR=fake_home)
|
|
268
|
+
pi = shutil.which("pi") or "pi"
|
|
269
|
+
cmd = ["sandbox-exec", "-p", sandbox_profile(os.getcwd(), tmp, python_dirs()), pi] + cmd[1:]
|
|
270
|
+
print(f"$ {shown} <task> (thinking {level or 'default'}, max {max_turns} turns, "
|
|
271
|
+
f"sandbox {'on' if sandbox else 'OFF'})", flush=True)
|
|
272
|
+
try:
|
|
273
|
+
proc = subprocess.Popen(cmd, env=env, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
|
|
274
|
+
stderr=subprocess.PIPE, start_new_session=True)
|
|
275
|
+
except OSError as e:
|
|
276
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
277
|
+
stats.update(stop="error", final_message=f"can't start pi: {e}")
|
|
278
|
+
save(stats)
|
|
279
|
+
return 1
|
|
280
|
+
|
|
281
|
+
def stop_pi(*_):
|
|
282
|
+
try:
|
|
283
|
+
os.killpg(proc.pid, signal.SIGKILL)
|
|
284
|
+
except ProcessLookupError:
|
|
285
|
+
pass
|
|
286
|
+
signal.signal(signal.SIGTERM, lambda *a: (stop_pi(), save(stats), sys.exit(1)))
|
|
287
|
+
error = ""
|
|
288
|
+
try:
|
|
289
|
+
for raw in iter(proc.stdout.readline, b""):
|
|
290
|
+
try:
|
|
291
|
+
ev = json.loads(raw)
|
|
292
|
+
except ValueError:
|
|
293
|
+
continue
|
|
294
|
+
kind = ev.get("type")
|
|
295
|
+
if kind == "message_end" and ev.get("message", {}).get("role") == "assistant":
|
|
296
|
+
m = ev["message"]
|
|
297
|
+
u = m.get("usage") or {}
|
|
298
|
+
stats["turns"] += 1
|
|
299
|
+
stats["output_tokens"] += u.get("output") or 0
|
|
300
|
+
stats["input_tokens"] += (u.get("input") or 0) + (u.get("cacheRead") or 0)
|
|
301
|
+
text = "".join(c.get("text", "") for c in m.get("content", []) if c.get("type") == "text").strip()
|
|
302
|
+
if text:
|
|
303
|
+
stats["final_message"] = text
|
|
304
|
+
if m.get("errorMessage"):
|
|
305
|
+
error = str(m["errorMessage"])
|
|
306
|
+
print(f"turn {stats['turns']}: {u.get('output') or 0} tokens, {m.get('stopReason')}"
|
|
307
|
+
+ (f": {short(text)}" if text else "") + (f" [error: {short(error)}]" if error else ""),
|
|
308
|
+
flush=True)
|
|
309
|
+
if stats["turns"] >= max_turns and m.get("stopReason") == "toolUse":
|
|
310
|
+
stats["stop"] = "turn limit"
|
|
311
|
+
print(f"turn limit ({max_turns}) reached", flush=True)
|
|
312
|
+
break
|
|
313
|
+
elif kind == "tool_execution_start":
|
|
314
|
+
stats["tool_calls"] += 1
|
|
315
|
+
args = ev.get("args") or {}
|
|
316
|
+
what = args.get("command") or args.get("path") or json.dumps(args)
|
|
317
|
+
if "pytest" in json.dumps(args) or "unittest" in json.dumps(args):
|
|
318
|
+
stats["ran_tests"] = True
|
|
319
|
+
print(f" {ev.get('toolName')}: {short(what)}", flush=True)
|
|
320
|
+
elif kind == "tool_execution_end" and ev.get("toolName") == "subagent" and scouts:
|
|
321
|
+
print(add_subagents(stats, ev), flush=True)
|
|
322
|
+
elif kind == "tool_execution_end" and ev.get("isError"):
|
|
323
|
+
if ev.get("toolName") != "bash": # a failed edit or a bad call, not a failing command
|
|
324
|
+
stats["tool_errors"] += 1
|
|
325
|
+
out = " ".join(c.get("text", "") for c in (ev.get("result") or {}).get("content", []))
|
|
326
|
+
print(f" ! {ev.get('toolName')} failed: {short(out)}", flush=True)
|
|
327
|
+
elif kind == "agent_settled":
|
|
328
|
+
stats["stop"] = stats["stop"] or ("error" if ev.get("aborted") or error else "done")
|
|
329
|
+
break
|
|
330
|
+
finally:
|
|
331
|
+
stop_pi()
|
|
332
|
+
proc.wait()
|
|
333
|
+
err = proc.stderr.read().decode("utf-8", "replace").strip()
|
|
334
|
+
if err:
|
|
335
|
+
print("pi stderr: " + short(err, 600), flush=True)
|
|
336
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
337
|
+
if not stats["stop"]:
|
|
338
|
+
stats["stop"] = "error"
|
|
339
|
+
error = error or f"pi exited ({proc.returncode})"
|
|
340
|
+
if error and any(s in error for s in SERVER_ERRORS):
|
|
341
|
+
stats["server_error"] = error # the server failed, not the model: tuieval asks the task again
|
|
342
|
+
save(stats)
|
|
343
|
+
return 0
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def save(stats):
|
|
347
|
+
with open(os.environ["TUIEVAL_STATS_FILE"], "w") as f:
|
|
348
|
+
json.dump(stats, f)
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
if __name__ == "__main__":
|
|
352
|
+
sys.exit(main())
|
tuieval/agents.py
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"""Agent packs: coding tasks a command-line agent works on, graded by tests.
|
|
2
2
|
|
|
3
|
-
models.toml says how to start each agent (any program; {root} is the workspace
|
|
3
|
+
models.toml says how to start each agent (any program; {root} is the workspace, {tuieval_python} the Python
|
|
4
|
+
tuieval runs with):
|
|
4
5
|
|
|
5
6
|
[agents.my-agent]
|
|
6
7
|
cmd = ["python3", "{root}/agents/my_agent.py"]
|
|
7
8
|
|
|
9
|
+
Built in (builtin.toml, replaced by an [agents.<name>] of the same name): "pi" and "pi-scouts", pi through
|
|
10
|
+
tuieval/adapters/pi.py.
|
|
11
|
+
|
|
8
12
|
[defaults]
|
|
9
13
|
agent = "my-agent" # for agent packs that don't name one (pack.toml agent = "...")
|
|
10
14
|
|
|
@@ -28,9 +32,11 @@ The agent learns the rest from its environment:
|
|
|
28
32
|
TUIEVAL_STATS_FILE where it may write its stats as JSON when it finishes (all optional):
|
|
29
33
|
agent ("name version"), turns, input_tokens, output_tokens, tool_calls,
|
|
30
34
|
tool_errors (failed edits, bad tool calls; not commands that exit nonzero),
|
|
31
|
-
ran_tests, stop ("done", "turn limit" or "error"), final_message,
|
|
35
|
+
ran_tests, stop ("done", "turn limit" or "error"), final_message,
|
|
32
36
|
server_error: the model's server failed, not the model (the task isn't counted
|
|
33
|
-
and is asked again)
|
|
37
|
+
and is asked again), and subagent_calls, subagent_tasks, subagent_failed,
|
|
38
|
+
subagent_turns, subagent_input_tokens, subagent_output_tokens for work handed to
|
|
39
|
+
subagents (also counted in input_tokens and output_tokens)
|
|
34
40
|
|
|
35
41
|
PATH starts with the pack's Python (pack.toml python, else tuieval's), so `python` runs the tasks'
|
|
36
42
|
code and tests. The agent's exit code decides nothing; the tests do.
|
|
@@ -55,8 +61,12 @@ PROMPT_TAIL = "\n\nYou're working in a project in the current directory. Run Pyt
|
|
|
55
61
|
GRADE_TIMEOUT_S = 300
|
|
56
62
|
DIFF_KEEP = 20_000 # characters of the diff kept in the result (the whole diff is in the log)
|
|
57
63
|
HIDDEN_RE = re.compile(r"\.?_hidden\b") # junit names of the hidden tests (a collection error starts with ".")
|
|
64
|
+
# subagent_*: work the agent handed to subagents (counted in its own input/output tokens too), e.g. the
|
|
65
|
+
# built-in pi-scouts agent's scouts
|
|
66
|
+
SUBAGENT_KEYS = ("subagent_calls", "subagent_tasks", "subagent_failed", "subagent_turns", "subagent_input_tokens",
|
|
67
|
+
"subagent_output_tokens")
|
|
58
68
|
STATS_KEYS = ("agent", "turns", "input_tokens", "output_tokens", "tool_calls", "tool_errors", "ran_tests", "stop",
|
|
59
|
-
"final_message", "server_error")
|
|
69
|
+
"final_message", "server_error", *SUBAGENT_KEYS)
|
|
60
70
|
|
|
61
71
|
|
|
62
72
|
class AgentError(Exception):
|
tuieval/builtin.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Built-in defaults and
|
|
1
|
+
# Built-in defaults, servers and agents, used when a workspace's models.toml doesn't define them.
|
|
2
2
|
# [defaults] fill in key by key; [sampling] only when models.toml has no [sampling] at all (it's part of
|
|
3
|
-
# every result's fingerprint); a server here is replaced whole by one of the same name in models.toml.
|
|
3
|
+
# every result's fingerprint); a server or agent here is replaced whole by one of the same name in models.toml.
|
|
4
4
|
|
|
5
5
|
[defaults]
|
|
6
6
|
repeat = 3
|
|
@@ -85,3 +85,13 @@ pin_endpoint = true
|
|
|
85
85
|
api_key_env = "OPENROUTER_API_KEY"
|
|
86
86
|
thinking_param = "reasoning" # [sampling] enable_thinking -> OpenRouter's reasoning.enabled
|
|
87
87
|
headers = { "X-Title" = "tuieval" }
|
|
88
|
+
|
|
89
|
+
# pi (https://github.com/earendil-works/pi) for agent packs, through the built-in adapter (tuieval/adapters/pi.py):
|
|
90
|
+
# bare pi on the served model, sandboxed on macOS. pi-scouts adds pi's subagent extension and a read-only "scout"
|
|
91
|
+
# agent on the same model, which the lead may send in parallel. pi must be on PATH. {tuieval_python} is the
|
|
92
|
+
# Python tuieval runs with. Use one in a pack with agent = "pi" (pack.toml) or [defaults] agent = "pi".
|
|
93
|
+
[agents.pi]
|
|
94
|
+
cmd = ["{tuieval_python}", "-m", "tuieval.adapters.pi"]
|
|
95
|
+
|
|
96
|
+
[agents.pi-scouts]
|
|
97
|
+
cmd = ["{tuieval_python}", "-m", "tuieval.adapters.pi", "--scouts"]
|
tuieval/compare.py
CHANGED
|
@@ -639,7 +639,9 @@ def items(rows):
|
|
|
639
639
|
|
|
640
640
|
def agent_table(rows):
|
|
641
641
|
"""(header, table) summing up agent-pack tasks per model and pack, or None without any. A pack run
|
|
642
|
-
by more than one agent version is marked, since a new version can change how models do.
|
|
642
|
+
by more than one agent version is marked, since a new version can change how models do. A
|
|
643
|
+
"subagent tasks" column (tasks handed to subagents, out of the agent's calls) appears only when
|
|
644
|
+
some agent reported subagent stats."""
|
|
643
645
|
groups = collections.defaultdict(list)
|
|
644
646
|
for r in rows:
|
|
645
647
|
if r.get("agent"):
|
|
@@ -648,6 +650,9 @@ def agent_table(rows):
|
|
|
648
650
|
return None
|
|
649
651
|
header = ["model", "pack", "passed", "med min", "med turns", "out tokens", "tool errors", "ran tests",
|
|
650
652
|
"limits hit", "tests edited", "agent"]
|
|
653
|
+
subagents = any("subagent_tasks" in r["agent"] for rs in groups.values() for r in rs)
|
|
654
|
+
if subagents:
|
|
655
|
+
header.insert(-1, "subagent tasks")
|
|
651
656
|
table = []
|
|
652
657
|
for (model, suite), rs in sorted(groups.items()):
|
|
653
658
|
a = [r["agent"] for r in rs]
|
|
@@ -662,6 +667,10 @@ def agent_table(rows):
|
|
|
662
667
|
str(sum(x.get("stop") in ("time limit", "turn limit") for x in a)),
|
|
663
668
|
str(sum(bool(x.get("tests_edited")) for x in a)),
|
|
664
669
|
" + ".join(versions) + (" (MIXED)" if len(versions) > 1 else "")])
|
|
670
|
+
if subagents:
|
|
671
|
+
sub = [x for x in a if "subagent_tasks" in x]
|
|
672
|
+
table[-1].insert(-1, f"{sum(x['subagent_tasks'] for x in sub)} in "
|
|
673
|
+
f"{sum(x.get('subagent_calls') or 0 for x in sub)} calls" if sub else "-")
|
|
665
674
|
return header, table
|
|
666
675
|
|
|
667
676
|
|
tuieval/engine.py
CHANGED
|
@@ -45,6 +45,7 @@ import socket
|
|
|
45
45
|
import statistics
|
|
46
46
|
import string
|
|
47
47
|
import subprocess
|
|
48
|
+
import sys
|
|
48
49
|
import tempfile
|
|
49
50
|
import threading
|
|
50
51
|
import time
|
|
@@ -105,7 +106,7 @@ def hosted(cfg, m):
|
|
|
105
106
|
def load_config(path):
|
|
106
107
|
"""Read models.toml, fill in the built-ins it leaves out (builtin.toml) and each model's defaults.
|
|
107
108
|
[defaults] are filled key by key; [sampling] only when models.toml has none (sampling is part of
|
|
108
|
-
every result's fingerprint, so a workspace's own keys are never added to); servers by name."""
|
|
109
|
+
every result's fingerprint, so a workspace's own keys are never added to); servers and agents by name."""
|
|
109
110
|
with open(path, "rb") as f:
|
|
110
111
|
cfg = tomllib.load(f)
|
|
111
112
|
builtin = builtin_config()
|
|
@@ -117,6 +118,7 @@ def load_config(path):
|
|
|
117
118
|
own = cfg.get("servers", {})
|
|
118
119
|
cfg["servers"] = {**builtin["servers"], **own}
|
|
119
120
|
cfg["builtin_servers"] = sorted(set(builtin["servers"]) - set(own)) # not defined in models.toml
|
|
121
|
+
cfg["agents"] = {**builtin.get("agents", {}), **cfg.get("agents", {})}
|
|
120
122
|
cfg.setdefault("models", [])
|
|
121
123
|
seen = set()
|
|
122
124
|
for m in cfg["models"]:
|
|
@@ -2310,7 +2312,7 @@ class Engine:
|
|
|
2310
2312
|
python = agents.python_for(job.pack, self.root)
|
|
2311
2313
|
m, s = job.model, job.sampling
|
|
2312
2314
|
key_env = self.cfg["servers"][m["server"]].get("api_key_env")
|
|
2313
|
-
cmd = [expand(str(a), root=self.root) for a in agent["cmd"]]
|
|
2315
|
+
cmd = [expand(str(a), root=self.root, tuieval_python=sys.executable) for a in agent["cmd"]]
|
|
2314
2316
|
live = os.path.join(self.log_dir, "live")
|
|
2315
2317
|
os.makedirs(live, exist_ok=True)
|
|
2316
2318
|
waits = list(self.SERVER_RETRY_WAITS_S)
|
|
@@ -2377,7 +2379,7 @@ class Engine:
|
|
|
2377
2379
|
"agent": {"name": name, "version": stats.get("agent"), "stop": stop if stop != "exited" else
|
|
2378
2380
|
stats.get("stop") or "exited",
|
|
2379
2381
|
**{k: stats[k] for k in ("turns", "input_tokens", "output_tokens", "tool_calls",
|
|
2380
|
-
"tool_errors", "ran_tests") if k in stats},
|
|
2382
|
+
"tool_errors", "ran_tests", *agents.SUBAGENT_KEYS) if k in stats},
|
|
2381
2383
|
"exit_code": code, "tests_edited": edited, "visible": g["visible"],
|
|
2382
2384
|
"hidden": g["hidden"], "failed": g["failed"], "diff": patch[:agents.DIFF_KEEP],
|
|
2383
2385
|
"diff_cut": len(patch) > agents.DIFF_KEEP}}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: tuieval
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0.dev2
|
|
4
4
|
Summary: Evaluate local and frontier LLMs on your own questions: accuracy, speed, tokens and PASS/FAIL verdicts, in the terminal.
|
|
5
5
|
Project-URL: Homepage, https://github.com/ashe-wb/tuieval
|
|
6
6
|
Project-URL: Issues, https://github.com/ashe-wb/tuieval/issues
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
tuieval/__init__.py,sha256=myVXVX7htbwezW6k3x_FuKgn1RSZ2WcTaDEMByGn6Wg,312
|
|
2
2
|
tuieval/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
|
|
3
|
-
tuieval/_version.py,sha256=
|
|
4
|
-
tuieval/agents.py,sha256=
|
|
5
|
-
tuieval/builtin.toml,sha256=
|
|
3
|
+
tuieval/_version.py,sha256=Dvv6eOPcbaU80c-ESaC-CYYk_TtRZ5mMu0o3MINCfNg,533
|
|
4
|
+
tuieval/agents.py,sha256=3WFNlON_rGOmsYjHqPv2OqbYu2zXvCHH0ixVEAX-IWQ,16141
|
|
5
|
+
tuieval/builtin.toml,sha256=du2r1TxAH8StbiMDoTWUzy6xSRx4Y3cO1W_x_6P7iac,5387
|
|
6
6
|
tuieval/cli.py,sha256=Q9-b9sg6LSAfNq6o-c3J3hiOIoINgvH_Fe_U1x-0W4U,4915
|
|
7
7
|
tuieval/client.py,sha256=O77uftaxqgQ8b8rMnpR5822kmYFfr574w1pZlaSOFEE,14304
|
|
8
|
-
tuieval/compare.py,sha256=
|
|
8
|
+
tuieval/compare.py,sha256=h1Fy14yr5aE47leignmGvj_o9Z8eMb0rCX-KRIXaUik,40216
|
|
9
9
|
tuieval/ctxbench.py,sha256=VLl6Em7iCbZz2wwI9rTHMaWFMehcaJ7SYUL7g93B3j8,34366
|
|
10
10
|
tuieval/dates.py,sha256=CVazlwNjCRhD__D12zXLdeqF2ySt15X3xLUQeE-o6PY,6293
|
|
11
11
|
tuieval/doctor.py,sha256=j2MdDORstsAGPnRmpsnxau1_fR6sTc_oEFGM5zugTJU,7246
|
|
12
|
-
tuieval/engine.py,sha256=
|
|
12
|
+
tuieval/engine.py,sha256=Ji9spgPj3jQRcpXXVFXNMhC7rPF0aixzwtiKPqgeAMU,145568
|
|
13
13
|
tuieval/export.py,sha256=dbHQgL_ubWtIPM1sLzAew_gETnrDJyd0zgqVA5vkpXM,9657
|
|
14
14
|
tuieval/insights.py,sha256=32mpNiLgSoxxZaJq9LBZKj5iJJCKChpGQYHSnar7bSo,30074
|
|
15
15
|
tuieval/logs.py,sha256=01gZK6tf53dIThaIrs1bEsz9eqKYVlcxpyaLnSPTVxo,8127
|
|
@@ -28,6 +28,8 @@ tuieval/verdict.py,sha256=eBPTAS6GTtslOe5t3PkH80bf-ZGu6TfK5-0448yFfwU,21843
|
|
|
28
28
|
tuieval/watch_proxy.py,sha256=bnDO1i6n6yUs1hODoUWcMppJMGPavoQqs6aNYrIxpT8,11416
|
|
29
29
|
tuieval/workspace.py,sha256=V_HhkaN1odr0OpjNsPYradRWLpzDldM7SwpvxohBL4U,895
|
|
30
30
|
tuieval/yamlout.py,sha256=r1IokjLqW-Ztpg1fSn33ZW3VK00v1VvxymmU5Qy7GEw,606
|
|
31
|
+
tuieval/adapters/__init__.py,sha256=EO0CiSKdLLe68GWfy6-V3eVL4XIY9nypkOgDs3AHArY,83
|
|
32
|
+
tuieval/adapters/pi.py,sha256=y4wm20XCPZz1ClUH3mh8ozNZxS9JatN-l2YjZY5WNtE,17318
|
|
31
33
|
tuieval/graders/__init__.py,sha256=HEjlh6FnCCuiMHfFwJgkJSdFIdNHH26O2VeEJlS4BY4,6384
|
|
32
34
|
tuieval/graders/answer.py,sha256=pTETs2LzOWPhtuuowMVXpLFwdnNjMw-7sELqrFV6ocQ,2125
|
|
33
35
|
tuieval/graders/code.py,sha256=eLjV1CfaBO398bBSWvNvEoJJTRXLVnTv51WKNqYzMSw,4459
|
|
@@ -51,8 +53,8 @@ tuieval/templates/packs/tool_call/pack.toml,sha256=n4bx0lGJHSmW41uVqhfIXJ2BWZpmT
|
|
|
51
53
|
tuieval/templates/packs/tool_call/system.txt,sha256=mKxu-lB-0YjLHXdgeFJa8x2C180OvcNz5cHv2N5Bg3U,254
|
|
52
54
|
tuieval/templates/packs/tool_call/tests.yaml,sha256=Nv7c4syrzJ9cU8EBKSK_1ZSFx9V02aCjW4-2TBCPT7s,1859
|
|
53
55
|
tuieval/templates/packs/tool_call/tools.yaml,sha256=HgxCkh0On2VwbHSsjAGM8tNCK7ZtKLGrs7lMCn3Fprs,1048
|
|
54
|
-
tuieval-0.
|
|
55
|
-
tuieval-0.
|
|
56
|
-
tuieval-0.
|
|
57
|
-
tuieval-0.
|
|
58
|
-
tuieval-0.
|
|
56
|
+
tuieval-0.3.0.dev2.dist-info/METADATA,sha256=hLTky7Ts9hSQwjSjBSRjxvJZxaTP6yG672IYa-gsHwY,15304
|
|
57
|
+
tuieval-0.3.0.dev2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
58
|
+
tuieval-0.3.0.dev2.dist-info/entry_points.txt,sha256=7eIhi1GpFxBP2OLJV02Nn8LwsNuO512eKOGt1IBbj04,45
|
|
59
|
+
tuieval-0.3.0.dev2.dist-info/licenses/LICENSE,sha256=7wfRgGtBGH1aXhZkIn47oUznqKC18kEPMvUVgol7Ffc,1077
|
|
60
|
+
tuieval-0.3.0.dev2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|