argus-bench 0.1.0__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.
- argus_bench/__init__.py +327 -0
- argus_bench/_auto.py +15 -0
- argus_bench/check.py +73 -0
- argus_bench/cli.py +28 -0
- argus_bench-0.1.0.dist-info/METADATA +45 -0
- argus_bench-0.1.0.dist-info/RECORD +10 -0
- argus_bench-0.1.0.dist-info/WHEEL +4 -0
- argus_bench-0.1.0.dist-info/entry_points.txt +2 -0
- argus_bench-0.1.0.dist-info/licenses/LICENSE +21 -0
- argus_bench.pth +1 -0
argus_bench/__init__.py
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
"""argus_bench: write down what a model was shown and what it said, one JSON line per model call.
|
|
2
|
+
|
|
3
|
+
import argus_bench
|
|
4
|
+
argus_bench.record_to("rollout.jsonl") # every OpenAI-SDK chat call from here on is logged (sync, async, streaming)
|
|
5
|
+
|
|
6
|
+
argus_bench.log(messages, output, tools=tools, model="Qwen/Qwen3-1.7B") # anything else: one call, two values
|
|
7
|
+
|
|
8
|
+
No model, library or server specific flags. Nothing to configure per library. Check the file with `argus-bench check rollout.jsonl`.
|
|
9
|
+
If the agent runs in another process or container and you cannot edit its code, set ARGUS_BENCH_LOG=/path/rollout.jsonl in its environment instead
|
|
10
|
+
(optionally ARGUS_BENCH_META='{"revision": "..."}'); the installed package then starts recording in every Python process there.
|
|
11
|
+
"""
|
|
12
|
+
import functools
|
|
13
|
+
import inspect
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import platform
|
|
17
|
+
import threading
|
|
18
|
+
import time
|
|
19
|
+
import warnings
|
|
20
|
+
import atexit
|
|
21
|
+
|
|
22
|
+
__version__ = "0.1.0"
|
|
23
|
+
__all__ = ["record_to", "log", "env_state", "stop"]
|
|
24
|
+
|
|
25
|
+
SAMPLING_KEYS = ("temperature", "top_p", "top_k", "min_p", "max_tokens", "max_completion_tokens", "seed", "repetition_penalty",
|
|
26
|
+
"presence_penalty", "frequency_penalty", "stop")
|
|
27
|
+
_S = {"path": None, "lock": threading.Lock(), "meta": {}, "n": 0, "env": None, "hooked": False}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# ------------------------------------------------------------------ writing
|
|
31
|
+
def _jsonable(x):
|
|
32
|
+
if hasattr(x, "model_dump"):
|
|
33
|
+
return x.model_dump(exclude_none=True)
|
|
34
|
+
if isinstance(x, dict):
|
|
35
|
+
return {k: _jsonable(v) for k, v in x.items()}
|
|
36
|
+
if isinstance(x, (list, tuple)):
|
|
37
|
+
return [_jsonable(v) for v in x]
|
|
38
|
+
if isinstance(x, (str, int, float, bool)) or x is None:
|
|
39
|
+
return x
|
|
40
|
+
return str(x)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _write(rec):
|
|
44
|
+
if not _S["path"]:
|
|
45
|
+
return
|
|
46
|
+
_S["n"] += 1
|
|
47
|
+
with _S["lock"]:
|
|
48
|
+
h = _S.pop("header", None)
|
|
49
|
+
data = (json.dumps(_jsonable(h), ensure_ascii=False) + "\n" if h else "") + json.dumps(_jsonable(rec), ensure_ascii=False) + "\n"
|
|
50
|
+
fd = os.open(_S["path"], os.O_WRONLY | os.O_APPEND | os.O_CREAT, 0o644) # one write() call: lines from several processes never interleave
|
|
51
|
+
try:
|
|
52
|
+
os.write(fd, data.encode("utf-8"))
|
|
53
|
+
finally:
|
|
54
|
+
os.close(fd)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def record_to(path, _quiet=False, **meta):
|
|
58
|
+
"""Start appending one record per model call to `path`. `meta` goes in the header. Declare what you can:
|
|
59
|
+
revision="<full hf commit hash>", rollout_id="...", library="vllm 0.23", quantization="none" | "gguf-q4_k_m" | ...,
|
|
60
|
+
chat_template="default" | "<name or hash of a custom template>", dtype="bfloat16"."""
|
|
61
|
+
_S["path"], _S["meta"], _S["n"], _S["quiet"] = os.fspath(path), meta, 0, _quiet
|
|
62
|
+
header = {"header": {"argus_bench": __version__, "python": platform.python_version(), "started": time.time(), **meta}}
|
|
63
|
+
try:
|
|
64
|
+
import openai
|
|
65
|
+
header["header"]["openai_sdk"] = openai.__version__
|
|
66
|
+
except ImportError:
|
|
67
|
+
pass
|
|
68
|
+
_S["header"] = header # written together with the first record, so processes that make no model call leave no trace
|
|
69
|
+
_patch_openai()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def stop():
|
|
73
|
+
_S["path"] = None
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def env_state(state):
|
|
77
|
+
"""Declare the environment state to attach to every following call, as a JSON-able value or a zero-argument function.
|
|
78
|
+
A function is called at the START of each model call (so state that changes between calls is captured when the OpenAI hook is used);
|
|
79
|
+
with log() it is called when you log. Pass None to stop. Keep it small: put big state in a file and record its path or hash here."""
|
|
80
|
+
_S["env"] = state
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _env():
|
|
84
|
+
e = _S["env"]
|
|
85
|
+
if e is None:
|
|
86
|
+
return None, False
|
|
87
|
+
try:
|
|
88
|
+
return (e() if callable(e) else e), True
|
|
89
|
+
except Exception as ex:
|
|
90
|
+
return f"env_state error: {ex!r}", True
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _no_calls_warning():
|
|
94
|
+
if _S["path"] and _S["n"] == 0 and not _S.get("quiet"):
|
|
95
|
+
warnings.warn(f"argus_bench: record_to({_S['path']!r}) was called but no model call was recorded. Is the model called through the "
|
|
96
|
+
"openai Python SDK /chat/completions in this process? Otherwise call argus_bench.log(...) yourself.", stacklevel=1)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
atexit.register(_no_calls_warning)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _norm_output(output):
|
|
103
|
+
if isinstance(output, str):
|
|
104
|
+
return {"content": output}
|
|
105
|
+
out = dict(output)
|
|
106
|
+
return {k: v for k, v in out.items() if v not in (None, "", [])}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def log(messages, output, tools=None, model=None, sampling=None, **extra):
|
|
110
|
+
"""Log one model call. `messages`: the chat messages the model was given (OpenAI format). `output`: the generated text, or a dict with
|
|
111
|
+
content / reasoning_content / tool_calls. `sampling`: temperature, top_p, ... if you know them. Without a prior record_to(), call
|
|
112
|
+
argus_bench.record_to(path) first. An `env_state=` keyword overrides the value set with argus_bench.env_state()."""
|
|
113
|
+
if "env_state" not in extra:
|
|
114
|
+
v, on = _env()
|
|
115
|
+
if on:
|
|
116
|
+
extra["env_state"] = v
|
|
117
|
+
_write({"t": time.time(), "model": model, "messages": messages, "tools": tools, "sampling": sampling or {},
|
|
118
|
+
"output": _norm_output(output), **extra})
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
# ------------------------------------------------------------------ OpenAI SDK hook
|
|
122
|
+
def _request_fields(kw):
|
|
123
|
+
s = {k: kw[k] for k in SAMPLING_KEYS if kw.get(k) is not None}
|
|
124
|
+
for k, v in (kw.get("extra_body") or {}).items():
|
|
125
|
+
if k in SAMPLING_KEYS:
|
|
126
|
+
s[k] = v
|
|
127
|
+
rec = {"model": kw.get("model"), "messages": kw.get("messages"), "tools": kw.get("tools") or None, "sampling": s}
|
|
128
|
+
if "__env_state" in kw:
|
|
129
|
+
rec["env_state"] = kw["__env_state"]
|
|
130
|
+
return rec
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _msg_output(m):
|
|
134
|
+
extra = getattr(m, "model_extra", None) or {}
|
|
135
|
+
out = {"content": getattr(m, "content", None), "reasoning_content": extra.get("reasoning_content") or extra.get("reasoning")}
|
|
136
|
+
calls = getattr(m, "tool_calls", None)
|
|
137
|
+
if calls:
|
|
138
|
+
out["tool_calls"] = [{"id": c.id, "name": c.function.name, "arguments": c.function.arguments} for c in calls]
|
|
139
|
+
return _norm_output(out)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _log_completion(kw, res):
|
|
143
|
+
for ch in getattr(res, "choices", None) or []:
|
|
144
|
+
_write({"t": time.time(), **_request_fields(kw), "output": _msg_output(ch.message), "finish_reason": ch.finish_reason,
|
|
145
|
+
"source": "openai-sdk"})
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class _Acc:
|
|
149
|
+
"""Rebuilds the final message from streamed chunks."""
|
|
150
|
+
|
|
151
|
+
def __init__(self, kw):
|
|
152
|
+
self.kw, self.content, self.reasoning, self.calls, self.finish, self.done = kw, [], [], {}, None, False
|
|
153
|
+
|
|
154
|
+
def add(self, chunk):
|
|
155
|
+
for ch in getattr(chunk, "choices", None) or []:
|
|
156
|
+
d = ch.delta
|
|
157
|
+
extra = getattr(d, "model_extra", None) or {}
|
|
158
|
+
if d.content:
|
|
159
|
+
self.content.append(d.content)
|
|
160
|
+
r = extra.get("reasoning_content") or extra.get("reasoning")
|
|
161
|
+
if r:
|
|
162
|
+
self.reasoning.append(r)
|
|
163
|
+
for tc in d.tool_calls or []:
|
|
164
|
+
c = self.calls.setdefault(tc.index, {"id": None, "name": "", "arguments": ""})
|
|
165
|
+
c["id"] = tc.id or c["id"]
|
|
166
|
+
if tc.function:
|
|
167
|
+
c["name"] += tc.function.name or ""
|
|
168
|
+
c["arguments"] += tc.function.arguments or ""
|
|
169
|
+
self.finish = ch.finish_reason or self.finish
|
|
170
|
+
|
|
171
|
+
def flush(self):
|
|
172
|
+
if self.done:
|
|
173
|
+
return
|
|
174
|
+
self.done = True
|
|
175
|
+
out = _norm_output({"content": "".join(self.content), "reasoning_content": "".join(self.reasoning),
|
|
176
|
+
"tool_calls": [self.calls[i] for i in sorted(self.calls)]})
|
|
177
|
+
_write({"t": time.time(), **_request_fields(self.kw), "output": out, "finish_reason": self.finish, "source": "openai-sdk", "stream": True})
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class _TeeStream:
|
|
181
|
+
"""Behaves like the SDK's Stream: iterable, an iterator (LiteLLM calls next()), a context manager, closable."""
|
|
182
|
+
|
|
183
|
+
def __init__(self, stream, kw):
|
|
184
|
+
self._s, self._it, self._a = stream, None, _Acc(kw)
|
|
185
|
+
|
|
186
|
+
def __iter__(self):
|
|
187
|
+
return self
|
|
188
|
+
|
|
189
|
+
def __next__(self):
|
|
190
|
+
if self._it is None:
|
|
191
|
+
self._it = iter(self._s)
|
|
192
|
+
try:
|
|
193
|
+
chunk = next(self._it)
|
|
194
|
+
except BaseException:
|
|
195
|
+
self._a.flush()
|
|
196
|
+
raise
|
|
197
|
+
self._a.add(chunk)
|
|
198
|
+
return chunk
|
|
199
|
+
|
|
200
|
+
def __enter__(self):
|
|
201
|
+
self._s.__enter__()
|
|
202
|
+
return self
|
|
203
|
+
|
|
204
|
+
def __exit__(self, *a):
|
|
205
|
+
self._a.flush()
|
|
206
|
+
return self._s.__exit__(*a)
|
|
207
|
+
|
|
208
|
+
def close(self):
|
|
209
|
+
self._a.flush()
|
|
210
|
+
return self._s.close()
|
|
211
|
+
|
|
212
|
+
def __del__(self):
|
|
213
|
+
try:
|
|
214
|
+
self._a.flush() # consumer stopped early without closing: still log what the model produced
|
|
215
|
+
except Exception:
|
|
216
|
+
pass
|
|
217
|
+
|
|
218
|
+
def __getattr__(self, name):
|
|
219
|
+
return getattr(self._s, name)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
class _TeeAsyncStream(_TeeStream):
|
|
223
|
+
def __aiter__(self):
|
|
224
|
+
return self
|
|
225
|
+
|
|
226
|
+
async def __anext__(self):
|
|
227
|
+
if self._it is None:
|
|
228
|
+
self._it = self._s.__aiter__()
|
|
229
|
+
try:
|
|
230
|
+
chunk = await self._it.__anext__()
|
|
231
|
+
except BaseException:
|
|
232
|
+
self._a.flush()
|
|
233
|
+
raise
|
|
234
|
+
self._a.add(chunk)
|
|
235
|
+
return chunk
|
|
236
|
+
|
|
237
|
+
async def __aenter__(self):
|
|
238
|
+
await self._s.__aenter__()
|
|
239
|
+
return self
|
|
240
|
+
|
|
241
|
+
async def __aexit__(self, *a):
|
|
242
|
+
self._a.flush()
|
|
243
|
+
return await self._s.__aexit__(*a)
|
|
244
|
+
|
|
245
|
+
async def close(self):
|
|
246
|
+
self._a.flush()
|
|
247
|
+
return await self._s.close()
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _handle(kw, res):
|
|
251
|
+
"""Log a parsed result (ChatCompletion or Stream) and return what the caller should get back."""
|
|
252
|
+
if kw.get("stream"):
|
|
253
|
+
return (_TeeAsyncStream if hasattr(res, "__aiter__") else _TeeStream)(res, kw)
|
|
254
|
+
_log_completion(kw, res)
|
|
255
|
+
return res
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def _wrap_result(body, res, is_async):
|
|
259
|
+
"""Log the parsed result (ChatCompletion or Stream); handle `with_raw_response`, where the parsed object only exists after .parse()."""
|
|
260
|
+
if hasattr(res, "parse") and not hasattr(res, "choices"):
|
|
261
|
+
parse, cache = res.parse, []
|
|
262
|
+
|
|
263
|
+
def parse_logged(*a, **k):
|
|
264
|
+
r = parse(*a, **k)
|
|
265
|
+
if inspect.isawaitable(r):
|
|
266
|
+
async def finish():
|
|
267
|
+
if not cache:
|
|
268
|
+
cache.append(_handle(body, await r))
|
|
269
|
+
return cache[0]
|
|
270
|
+
return finish()
|
|
271
|
+
if not cache:
|
|
272
|
+
cache.append(_handle(body, r))
|
|
273
|
+
return cache[0]
|
|
274
|
+
res.parse = parse_logged
|
|
275
|
+
return res
|
|
276
|
+
return _handle(body, res)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _chat_body(args, kw):
|
|
280
|
+
options = kw.get("options") or (args[1] if len(args) > 1 else None)
|
|
281
|
+
url = str(getattr(options, "url", "") or "")
|
|
282
|
+
body = getattr(options, "json_data", None)
|
|
283
|
+
if not (url.rstrip("/").endswith("/chat/completions") and isinstance(body, dict)):
|
|
284
|
+
return None
|
|
285
|
+
return {**body, **(getattr(options, "extra_json", None) or {})} # extra_body fields (top_k, min_p, ...) are merged into the request
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def _patch_openai():
|
|
289
|
+
"""Patch the SDK's single HTTP entry point, so every way of calling chat completions is covered: client.chat.completions.create,
|
|
290
|
+
with_raw_response, client.post(...) (LiteLLM), LangChain, the Agents SDK's chat-completions model, sync / async / streaming."""
|
|
291
|
+
try:
|
|
292
|
+
import openai
|
|
293
|
+
except ImportError:
|
|
294
|
+
return # no openai SDK: only log() is available
|
|
295
|
+
try:
|
|
296
|
+
from openai._base_client import AsyncAPIClient, SyncAPIClient
|
|
297
|
+
assert callable(SyncAPIClient.request) and callable(AsyncAPIClient.request)
|
|
298
|
+
except Exception:
|
|
299
|
+
warnings.warn(f"argus_bench: cannot hook openai {getattr(openai, '__version__', '?')} (its internals changed). "
|
|
300
|
+
"Calls through the SDK will NOT be recorded; use argus_bench.log(...) instead.", stacklevel=3)
|
|
301
|
+
return
|
|
302
|
+
if getattr(SyncAPIClient.request, "_argus_bench", False):
|
|
303
|
+
return
|
|
304
|
+
sync_request, async_request = SyncAPIClient.request, AsyncAPIClient.request
|
|
305
|
+
|
|
306
|
+
@functools.wraps(sync_request)
|
|
307
|
+
def request(self, *args, **kw):
|
|
308
|
+
body = _chat_body(args, kw)
|
|
309
|
+
if body is not None:
|
|
310
|
+
v, on = _env()
|
|
311
|
+
if on:
|
|
312
|
+
body["__env_state"] = v
|
|
313
|
+
res = sync_request(self, *args, **kw)
|
|
314
|
+
return _wrap_result(body, res, False) if body is not None else res
|
|
315
|
+
|
|
316
|
+
@functools.wraps(async_request)
|
|
317
|
+
async def arequest(self, *args, **kw):
|
|
318
|
+
body = _chat_body(args, kw)
|
|
319
|
+
if body is not None:
|
|
320
|
+
v, on = _env()
|
|
321
|
+
if on:
|
|
322
|
+
body["__env_state"] = v
|
|
323
|
+
res = await async_request(self, *args, **kw)
|
|
324
|
+
return _wrap_result(body, res, True) if body is not None else res
|
|
325
|
+
|
|
326
|
+
request._argus_bench = arequest._argus_bench = True
|
|
327
|
+
SyncAPIClient.request, AsyncAPIClient.request = request, arequest
|
argus_bench/_auto.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Started by argus_bench.pth in every Python process whose environment has ARGUS_BENCH_LOG set."""
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def start():
|
|
7
|
+
path = os.environ.get("ARGUS_BENCH_LOG")
|
|
8
|
+
if not path:
|
|
9
|
+
return
|
|
10
|
+
try:
|
|
11
|
+
meta = json.loads(os.environ.get("ARGUS_BENCH_META") or "{}")
|
|
12
|
+
except ValueError:
|
|
13
|
+
meta = {}
|
|
14
|
+
import argus_bench
|
|
15
|
+
argus_bench.record_to(path, _quiet=True, **meta)
|
argus_bench/check.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Structural check of a rollout file. No model needed."""
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def load(path):
|
|
6
|
+
header, recs = {}, []
|
|
7
|
+
for i, line in enumerate(open(path), 1):
|
|
8
|
+
if not line.strip():
|
|
9
|
+
continue
|
|
10
|
+
try:
|
|
11
|
+
obj = json.loads(line)
|
|
12
|
+
except json.JSONDecodeError as e:
|
|
13
|
+
raise ValueError(f"{path}:{i}: not valid JSON ({e})")
|
|
14
|
+
if "header" in obj:
|
|
15
|
+
header.update(obj["header"])
|
|
16
|
+
else:
|
|
17
|
+
recs.append(obj)
|
|
18
|
+
return header, recs
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _same(a, b):
|
|
22
|
+
return json.dumps(a, sort_keys=True, default=str) == json.dumps(b, sort_keys=True, default=str)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def check(path):
|
|
26
|
+
"""Returns (problems, warnings, info)."""
|
|
27
|
+
header, recs = load(path)
|
|
28
|
+
problems, warnings, info = [], [], {}
|
|
29
|
+
if not recs:
|
|
30
|
+
return ["no model calls in file"], [], {}
|
|
31
|
+
for i, r in enumerate(recs):
|
|
32
|
+
w = f"call {i}"
|
|
33
|
+
if not r.get("messages"):
|
|
34
|
+
problems.append(f"{w}: no messages")
|
|
35
|
+
out = r.get("output") or {}
|
|
36
|
+
if not (out.get("content") or out.get("tool_calls") or out.get("reasoning_content")):
|
|
37
|
+
problems.append(f"{w}: empty output")
|
|
38
|
+
for tc in out.get("tool_calls") or []:
|
|
39
|
+
a = tc.get("arguments")
|
|
40
|
+
if isinstance(a, str):
|
|
41
|
+
try:
|
|
42
|
+
json.loads(a)
|
|
43
|
+
except json.JSONDecodeError:
|
|
44
|
+
warnings.append(f"{w}: tool call '{tc.get('name')}' has arguments that are not valid JSON (kept as-is)")
|
|
45
|
+
models = {r.get("model") for r in recs}
|
|
46
|
+
if None in models or "" in models:
|
|
47
|
+
warnings.append("some calls have no `model`; pass model=... to log()")
|
|
48
|
+
if not header.get("revision"):
|
|
49
|
+
warnings.append("no model revision in the header: use record_to(path, revision='<full hf commit hash>')")
|
|
50
|
+
if not header.get("library"):
|
|
51
|
+
warnings.append("no `library` in the header (e.g. library='vllm 0.23.0 (server)')")
|
|
52
|
+
if not header.get("dtype"):
|
|
53
|
+
warnings.append("no `dtype` in the header (e.g. dtype='bfloat16')")
|
|
54
|
+
if not header.get("quantization"):
|
|
55
|
+
warnings.append("no `quantization` declared in the header (e.g. quantization='none')")
|
|
56
|
+
if not header.get("chat_template"):
|
|
57
|
+
warnings.append("no `chat_template` declared in the header (e.g. chat_template='default')")
|
|
58
|
+
if not any(r.get("sampling") for r in recs):
|
|
59
|
+
warnings.append("no sampling settings recorded (temperature/top_p/...)")
|
|
60
|
+
# how the context evolved: extension of the previous call, or something else (e.g. compaction, a new thread)
|
|
61
|
+
ext = other = 0
|
|
62
|
+
prev = None
|
|
63
|
+
for r in recs:
|
|
64
|
+
if prev is not None:
|
|
65
|
+
base = prev["messages"] + [{"role": "assistant"}]
|
|
66
|
+
if len(r["messages"]) >= len(base) and all(_same(a, b) for a, b in zip(prev["messages"], r["messages"])):
|
|
67
|
+
ext += 1
|
|
68
|
+
else:
|
|
69
|
+
other += 1
|
|
70
|
+
prev = r
|
|
71
|
+
info = {"calls": len(recs), "models": sorted(m for m in models if m), "calls_extending_previous": ext,
|
|
72
|
+
"calls_with_new_context (compaction / new thread)": other, "header": header}
|
|
73
|
+
return problems, warnings, info
|
argus_bench/cli.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from .check import check
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main(argv=None):
|
|
9
|
+
ap = argparse.ArgumentParser(prog="argus-bench")
|
|
10
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
11
|
+
c = sub.add_parser("check", help="check that a rollout file is well-formed")
|
|
12
|
+
c.add_argument("files", nargs="+")
|
|
13
|
+
a = ap.parse_args(argv)
|
|
14
|
+
bad = False
|
|
15
|
+
for f in a.files:
|
|
16
|
+
problems, warnings, info = check(f)
|
|
17
|
+
print(f"{f}: {info.get('calls', 0)} calls {json.dumps({k: v for k, v in info.items() if k != 'header' and k != 'calls'})}")
|
|
18
|
+
for p in problems:
|
|
19
|
+
print(" PROBLEM:", p); bad = True
|
|
20
|
+
for w in warnings:
|
|
21
|
+
print(" warning:", w)
|
|
22
|
+
if not problems:
|
|
23
|
+
print(" OK")
|
|
24
|
+
return 1 if bad else 0
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
sys.exit(main())
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: argus-bench
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Record every model call (what the model saw, what it said) of an agent run in one unified JSONL format, for any inference library.
|
|
5
|
+
Author: The ARGUS authors
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: agents,benchmark,llm,logging,rollouts,sglang,vllm
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Provides-Extra: test
|
|
14
|
+
Requires-Dist: openai; extra == 'test'
|
|
15
|
+
Requires-Dist: pytest; extra == 'test'
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# argus-bench
|
|
19
|
+
|
|
20
|
+
Record every model call of an agent run, whatever inference library runs the model, in one plain JSON Lines file.
|
|
21
|
+
For each call it stores what the model was shown and what it produced.
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
pip install argus-bench
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
import argus_bench
|
|
29
|
+
argus_bench.record_to("rollout.jsonl", revision="<full model commit hash>", library="vllm 0.23.0 (server)",
|
|
30
|
+
dtype="bfloat16", quantization="none", chat_template="default")
|
|
31
|
+
# ... run your agent as usual: every OpenAI-SDK chat call (vLLM, SGLang, llama.cpp, Ollama, LiteLLM, LangChain; sync, async, streaming) is recorded
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Model runs inside your own process (transformers, vLLM `LLM`, SGLang `Engine`, llama-cpp-python)? One call after each generation:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
argus_bench.log(messages, generated_text, tools=tools, model="Qwen/Qwen3-1.7B", sampling={"temperature": 0.7, "top_p": 0.95})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Agent you cannot edit, or one that runs in a container? Set `ARGUS_BENCH_LOG=/path/rollout.jsonl` in its environment.
|
|
41
|
+
Check the result with `argus-bench check rollout.jsonl`.
|
|
42
|
+
|
|
43
|
+
* [docs/USAGE.md](docs/USAGE.md): how to record with every supported way of running a model
|
|
44
|
+
* [docs/FORMAT.md](docs/FORMAT.md): the exact file format, so you can produce it without this package
|
|
45
|
+
* [docs/TESTED.md](docs/TESTED.md): what has and has not been tested
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
argus_bench/__init__.py,sha256=W3EKcbejulA_ELi9_3QFm88Xs6DktA5XFVAknKHYIe8,12715
|
|
2
|
+
argus_bench/_auto.py,sha256=34AC4KIebnnIV9Z-RqjPl6rhqW2egQ5GK0vfFEQJ7kU,410
|
|
3
|
+
argus_bench/check.py,sha256=l4ZJ_Vca4cPuPBpBGxMo2P1ZjG3Vw6erQRaGvbFI8WQ,3133
|
|
4
|
+
argus_bench/cli.py,sha256=HG7zb6NB3DupCzMhHRmOwTvaMhp-Sk7m9to-ap1m2m4,823
|
|
5
|
+
argus_bench.pth,sha256=o6m0sH8BI1ba-drwR4uJTe-LlkfVaFlYFzP8iOcyczA,109
|
|
6
|
+
argus_bench-0.1.0.dist-info/METADATA,sha256=ITi9V3T-aJilk7iou7E1C61jNwGPwtRtd5r5eyQBKfE,1998
|
|
7
|
+
argus_bench-0.1.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
8
|
+
argus_bench-0.1.0.dist-info/entry_points.txt,sha256=h-ii__Q3hXxsP7eWOW6v3zG0OwkqBGgf4cMj6LAiNl4,53
|
|
9
|
+
argus_bench-0.1.0.dist-info/licenses/LICENSE,sha256=f0Ler2hlaEFG_pcMvdcqDEQ714HUc9XOg0X93yuTjFI,1074
|
|
10
|
+
argus_bench-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The ARGUS authors
|
|
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.
|
argus_bench.pth
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import os; os.environ.get("ARGUS_BENCH_LOG") and __import__("argus_bench._auto", fromlist=["start"]).start()
|