verifiers 0.4.2.dev127__py3-none-any.whl → 0.4.2.dev129__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.
- verifiers/v1/agent.py +56 -11
- verifiers/v1/cli/run.py +42 -15
- verifiers/v1/task.py +5 -0
- {verifiers-0.4.2.dev127.dist-info → verifiers-0.4.2.dev129.dist-info}/METADATA +1 -1
- {verifiers-0.4.2.dev127.dist-info → verifiers-0.4.2.dev129.dist-info}/RECORD +8 -8
- {verifiers-0.4.2.dev127.dist-info → verifiers-0.4.2.dev129.dist-info}/WHEEL +0 -0
- {verifiers-0.4.2.dev127.dist-info → verifiers-0.4.2.dev129.dist-info}/entry_points.txt +0 -0
- {verifiers-0.4.2.dev127.dist-info → verifiers-0.4.2.dev129.dist-info}/licenses/LICENSE +0 -0
verifiers/v1/agent.py
CHANGED
|
@@ -34,6 +34,7 @@ from verifiers.v1.configs.agent import (
|
|
|
34
34
|
)
|
|
35
35
|
from verifiers.v1.configs.runtime import NetworkPolicyConfig
|
|
36
36
|
from verifiers.v1.dialects import parse_message
|
|
37
|
+
from verifiers.v1.errors import RolloutError, TaskError, boundary
|
|
37
38
|
from verifiers.v1.harness import Harness
|
|
38
39
|
from verifiers.v1.interception import Interception, InterceptionServer
|
|
39
40
|
from verifiers.v1.mcp import SharedToolServer
|
|
@@ -62,6 +63,7 @@ from verifiers.v1.utils.compile import (
|
|
|
62
63
|
resolve_runtime_config,
|
|
63
64
|
validate_pairing,
|
|
64
65
|
)
|
|
66
|
+
from verifiers.v1.utils.decorators import invoke
|
|
65
67
|
from verifiers.v1.utils.format import format_time
|
|
66
68
|
from verifiers.v1.utils.logging import (
|
|
67
69
|
clip,
|
|
@@ -200,6 +202,14 @@ class Segment:
|
|
|
200
202
|
return ""
|
|
201
203
|
|
|
202
204
|
|
|
205
|
+
def _as_messages(message: str | Messages) -> Messages:
|
|
206
|
+
if isinstance(message, str):
|
|
207
|
+
return [UserMessage(content=message)]
|
|
208
|
+
# A turn's messages may arrive typed or as wire dicts (env code naturally
|
|
209
|
+
# writes `{"role": "user", ...}`); the trace speaks typed, so normalize.
|
|
210
|
+
return [parse_message(m) if isinstance(m, dict) else m for m in message]
|
|
211
|
+
|
|
212
|
+
|
|
203
213
|
@dataclass
|
|
204
214
|
class _PendingMessage:
|
|
205
215
|
text: str
|
|
@@ -576,13 +586,9 @@ class Interaction:
|
|
|
576
586
|
"a bare turn() before answering (or hand the interaction a task "
|
|
577
587
|
"with `prompt=None` to open the conversation yourself)"
|
|
578
588
|
)
|
|
579
|
-
messages: Messages | None =
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
elif message is not None:
|
|
583
|
-
# A turn's messages may arrive typed or as wire dicts (env code naturally
|
|
584
|
-
# writes `{"role": "user", ...}`); the trace speaks typed, so normalize.
|
|
585
|
-
messages = [parse_message(m) if isinstance(m, dict) else m for m in message]
|
|
589
|
+
messages: Messages | None = (
|
|
590
|
+
_as_messages(message) if message is not None else None
|
|
591
|
+
)
|
|
586
592
|
self._started = True
|
|
587
593
|
turns_before = self.trace.num_turns
|
|
588
594
|
nodes_before = len(self.trace.nodes)
|
|
@@ -1060,10 +1066,49 @@ class Agent:
|
|
|
1060
1066
|
if handle is not None:
|
|
1061
1067
|
handle._active = run
|
|
1062
1068
|
try:
|
|
1063
|
-
|
|
1064
|
-
await run.restore()
|
|
1065
|
-
|
|
1066
|
-
|
|
1069
|
+
continuable = (
|
|
1070
|
+
await run.restore() if restore is not None else await run.step()
|
|
1071
|
+
)
|
|
1072
|
+
while continuable and run.runtime is not None:
|
|
1073
|
+
loop = asyncio.get_running_loop()
|
|
1074
|
+
budget = run._agent_time_remaining
|
|
1075
|
+
started = loop.time()
|
|
1076
|
+
deadline = asyncio.timeout(
|
|
1077
|
+
max(0.0, budget) if budget is not None else None
|
|
1078
|
+
)
|
|
1079
|
+
try:
|
|
1080
|
+
async with (
|
|
1081
|
+
deadline,
|
|
1082
|
+
boundary(TaskError, "task nudge"),
|
|
1083
|
+
):
|
|
1084
|
+
nudge = await invoke(
|
|
1085
|
+
task.nudge,
|
|
1086
|
+
{
|
|
1087
|
+
"trace": run.trace,
|
|
1088
|
+
"runtime": run.runtime,
|
|
1089
|
+
"deployment": run.deployment,
|
|
1090
|
+
},
|
|
1091
|
+
)
|
|
1092
|
+
messages = (
|
|
1093
|
+
_as_messages(nudge) if nudge is not None else None
|
|
1094
|
+
)
|
|
1095
|
+
except TimeoutError as exc:
|
|
1096
|
+
if deadline.expired():
|
|
1097
|
+
run.timeout("agent")
|
|
1098
|
+
else:
|
|
1099
|
+
run.fail(exc, stage="agent")
|
|
1100
|
+
break
|
|
1101
|
+
except RolloutError as exc:
|
|
1102
|
+
run.fail(exc, stage="agent")
|
|
1103
|
+
break
|
|
1104
|
+
finally:
|
|
1105
|
+
elapsed = max(0.0, loop.time() - started)
|
|
1106
|
+
run._agent_time_spent += elapsed
|
|
1107
|
+
if budget is not None:
|
|
1108
|
+
run._agent_time_remaining = max(0.0, budget - elapsed)
|
|
1109
|
+
if messages is None:
|
|
1110
|
+
break
|
|
1111
|
+
continuable = await run.step(messages)
|
|
1067
1112
|
finally:
|
|
1068
1113
|
if handle is not None:
|
|
1069
1114
|
handle._active = None
|
verifiers/v1/cli/run.py
CHANGED
|
@@ -8,6 +8,7 @@ import asyncio
|
|
|
8
8
|
import os
|
|
9
9
|
import sys
|
|
10
10
|
from pathlib import Path
|
|
11
|
+
from typing import Literal, overload
|
|
11
12
|
|
|
12
13
|
from pydantic_config import cli
|
|
13
14
|
|
|
@@ -42,9 +43,24 @@ def ensure_fresh(out: Path) -> None:
|
|
|
42
43
|
)
|
|
43
44
|
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
@overload
|
|
47
|
+
async def run_episodes(
|
|
48
|
+
config: RunnerConfig, *, collect: Literal[True] = True
|
|
49
|
+
) -> list[Episode]: ...
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@overload
|
|
53
|
+
async def run_episodes(
|
|
54
|
+
config: RunnerConfig, *, collect: Literal[False]
|
|
55
|
+
) -> tuple[int, int, float]: ...
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def run_episodes(
|
|
59
|
+
config: RunnerConfig, *, collect: bool = True
|
|
60
|
+
) -> list[Episode] | tuple[int, int, float]:
|
|
46
61
|
"""Run `num_rollouts` episodes per selected task and append each to `traces.jsonl`
|
|
47
|
-
as it completes.
|
|
62
|
+
as it completes. With `collect=False`, stream-aggregate `(ok, episodes, mean_reward)`
|
|
63
|
+
and drop each finished episode immediately instead of keeping them all in memory."""
|
|
48
64
|
env = load_environment(config.env)
|
|
49
65
|
taskset = env.taskset.select(config.select)
|
|
50
66
|
if not taskset.bounded:
|
|
@@ -61,29 +77,43 @@ async def run_episodes(config: RunnerConfig) -> list[Episode]:
|
|
|
61
77
|
asyncio.Semaphore(config.max_concurrent) if config.max_concurrent else None
|
|
62
78
|
)
|
|
63
79
|
write_lock = asyncio.Lock()
|
|
80
|
+
ok = episodes = traces = 0
|
|
81
|
+
reward_sum = 0.0
|
|
64
82
|
|
|
65
83
|
async def on_complete(episode: Episode) -> None:
|
|
84
|
+
nonlocal ok, episodes, traces, reward_sum
|
|
66
85
|
episode.record_run(EvalRunInfo(id=config.run.id, name=config.run.name))
|
|
67
86
|
await append_episode(out, episode, write_lock)
|
|
87
|
+
episodes += 1
|
|
88
|
+
ok += int(episode.ok)
|
|
89
|
+
traces += len(episode.traces)
|
|
90
|
+
reward_sum += sum(trace.reward for trace in episode.traces)
|
|
91
|
+
|
|
92
|
+
async def run_one(slot) -> Episode | None:
|
|
93
|
+
episode = await env.run_slot(slot, ctx, semaphore, on_complete)
|
|
94
|
+
if collect:
|
|
95
|
+
return episode
|
|
96
|
+
slot.episode = None
|
|
97
|
+
slot.traces.clear()
|
|
98
|
+
return None
|
|
68
99
|
|
|
69
100
|
async with env.serving():
|
|
70
|
-
rollouts: list[asyncio.Future[Episode]] = []
|
|
101
|
+
rollouts: list[asyncio.Future[Episode | None]] = []
|
|
71
102
|
try:
|
|
72
103
|
# Scheduled inside the try: a lazy taskset can raise after earlier tasks started.
|
|
73
104
|
for task in taskset:
|
|
74
105
|
for slot in env.slots(task, config.num_rollouts):
|
|
75
|
-
rollouts.append(
|
|
76
|
-
|
|
77
|
-
env.run_slot(slot, ctx, semaphore, on_complete)
|
|
78
|
-
)
|
|
79
|
-
)
|
|
80
|
-
return list(await asyncio.gather(*rollouts))
|
|
106
|
+
rollouts.append(asyncio.ensure_future(run_one(slot)))
|
|
107
|
+
results = await asyncio.gather(*rollouts)
|
|
81
108
|
except BaseException:
|
|
82
109
|
# Unwind every sibling before `serving()` tears down the resources they use.
|
|
83
110
|
for rollout in rollouts:
|
|
84
111
|
rollout.cancel()
|
|
85
112
|
await asyncio.gather(*rollouts, return_exceptions=True)
|
|
86
113
|
raise
|
|
114
|
+
if collect:
|
|
115
|
+
return [episode for episode in results if episode is not None]
|
|
116
|
+
return ok, episodes, reward_sum / traces if traces else 0.0
|
|
87
117
|
|
|
88
118
|
|
|
89
119
|
def main(argv: list[str] | None = None) -> None:
|
|
@@ -120,12 +150,9 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
120
150
|
# A first Ctrl-C raises KeyboardInterrupt so each rollout's teardown still runs.
|
|
121
151
|
install_interrupt()
|
|
122
152
|
try:
|
|
123
|
-
|
|
153
|
+
ok, total, reward = asyncio.run(run_episodes(config, collect=False))
|
|
124
154
|
except KeyboardInterrupt:
|
|
125
155
|
raise SystemExit(130)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
reward = sum(trace.reward for trace in traces) / len(traces) if traces else 0.0
|
|
129
|
-
print(f"{ok}/{len(episodes)} episodes ok, mean reward {reward:.3f}: {out}")
|
|
130
|
-
if ok < len(episodes):
|
|
156
|
+
print(f"{ok}/{total} episodes ok, mean reward {reward:.3f}: {out}")
|
|
157
|
+
if ok < total:
|
|
131
158
|
raise SystemExit(1)
|
verifiers/v1/task.py
CHANGED
|
@@ -215,6 +215,11 @@ class Task(Generic[DataT, StateT, ConfigT]):
|
|
|
215
215
|
async def setup(self, trace: Trace, runtime: Runtime) -> None:
|
|
216
216
|
return None
|
|
217
217
|
|
|
218
|
+
async def nudge(self, trace: Trace, runtime: Runtime) -> str | Messages | None:
|
|
219
|
+
"""Called when the agent finishes a segment. Return a prompt (or messages)
|
|
220
|
+
to run another segment in the same rollout, or None to finish."""
|
|
221
|
+
return None
|
|
222
|
+
|
|
218
223
|
async def finalize(self, trace: Trace, runtime: Runtime) -> None:
|
|
219
224
|
return None
|
|
220
225
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: verifiers
|
|
3
|
-
Version: 0.4.2.
|
|
3
|
+
Version: 0.4.2.dev129
|
|
4
4
|
Summary: Verifiers: Environments for LLM Reinforcement Learning
|
|
5
5
|
Project-URL: Homepage, https://github.com/primeintellect-ai/verifiers
|
|
6
6
|
Project-URL: Documentation, https://github.com/primeintellect-ai/verifiers
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
verifiers/__init__.py,sha256=F5IVMw6mhGaPBMCw7QKk0la_r5mMwydP2hdTTdQucik,352
|
|
2
2
|
verifiers/v1/__init__.py,sha256=VIKDoCrEqC6XP9EHKcZkrL29iBHRoge5j08yGap3jKc,19252
|
|
3
|
-
verifiers/v1/agent.py,sha256=
|
|
3
|
+
verifiers/v1/agent.py,sha256=J8ZQfC8XYhX5vl7nhiYJYZzabg8MtRtdBJkMosqhyO0,65115
|
|
4
4
|
verifiers/v1/delta.py,sha256=ZdF-b7Qqpwg4WXrNyAO_VK82OEBFsQDOr_xkNWtQROs,12561
|
|
5
5
|
verifiers/v1/env.py,sha256=5F-LhPLAfVNwcco2TR-OOAnv0QtIj49X8pc_dSa-Hgk,20748
|
|
6
6
|
verifiers/v1/episode.py,sha256=Tqjo8aQDOh4sM03he2WMXzEhmn2ybzwwtUS_QSvESsA,6983
|
|
@@ -15,7 +15,7 @@ verifiers/v1/semantic.py,sha256=nqKPPUoPL5Oh8Es_XjtcbDiQiIMKTYayXEm-EPB-jAE,5129
|
|
|
15
15
|
verifiers/v1/session.py,sha256=4O7JOFFoy2GvUOhJgWHn6FNwmpMv7tDflDA_0ffBS9k,52457
|
|
16
16
|
verifiers/v1/state.py,sha256=EckF2bWp-vV4b1jYJ9sLI5xrfGuI5spIgYYwW926toI,595
|
|
17
17
|
verifiers/v1/submission.py,sha256=zgSRbGVz82Efwz4nX4tlJ-i02AmjtKyu_vHfwfLaByw,7989
|
|
18
|
-
verifiers/v1/task.py,sha256=
|
|
18
|
+
verifiers/v1/task.py,sha256=4Uuh8TEYzst0XMfZGsoPtKq4WL4Ugwm0rXjYYreWZdg,16181
|
|
19
19
|
verifiers/v1/taskset.py,sha256=PRwMfPtUL0Sg9pwKzJYnpLBDqJCmQ4skQPhF1oocyyw,9504
|
|
20
20
|
verifiers/v1/trace.py,sha256=NrwTtf-gfghGivzN8tgLFiwt0MKcq3J-Rm3NDaC7etA,48396
|
|
21
21
|
verifiers/v1/types.py,sha256=PsYLhqy_19JZUT7uP9a8A2h-qKo7-9_KLQ_B0PqhkYg,13303
|
|
@@ -26,7 +26,7 @@ verifiers/v1/cli/debug.py,sha256=U5TwxxqyrIOz5GbITBAp2y6oSIPxjmFttuwm3XOKy0U,114
|
|
|
26
26
|
verifiers/v1/cli/output.py,sha256=vCscZ-g-sa-SLWDDQNoXBWelC_Je8lBdodvZGOe__eo,3285
|
|
27
27
|
verifiers/v1/cli/resolve.py,sha256=Q1EHM7wWQo0YkwJA898qtZbYLaIkjIVq3Q7kUp2YIxs,4346
|
|
28
28
|
verifiers/v1/cli/resume.py,sha256=hqV5AxxqeIInJeEZQerQznuijhMNijFEFcHZIltfLdE,470
|
|
29
|
-
verifiers/v1/cli/run.py,sha256=
|
|
29
|
+
verifiers/v1/cli/run.py,sha256=IpOCMbRd5gOBaVMtsWMaDSxMm6hkQxRqQ1JLNmBm1T0,5803
|
|
30
30
|
verifiers/v1/cli/validate.py,sha256=l_NekW1v00Wgr-l2f96rOti4KcLbYZgksb8CCZE3_20,20447
|
|
31
31
|
verifiers/v1/clients/__init__.py,sha256=3rXv205sRheGvG8yNDmFwpq8qK9dlt7S_ia1zGWhNk0,598
|
|
32
32
|
verifiers/v1/clients/base.py,sha256=C0G5lRm3nxt1xmPoA2cweBgCnN2KcLepmCYq1vdDrnU,1691
|
|
@@ -188,8 +188,8 @@ verifiers/v1/utils/scope.py,sha256=zbs4pj6AVk4jywlAJ3AX0Q0_kzB9dBB02nY-9H4ELdQ,8
|
|
|
188
188
|
verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
|
|
189
189
|
verifiers/v1/utils/trace_store.py,sha256=7F6xMhYgl3qmylnCU8-ekqswH16fUat1uegeM1OR9QQ,2563
|
|
190
190
|
verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
|
|
191
|
-
verifiers-0.4.2.
|
|
192
|
-
verifiers-0.4.2.
|
|
193
|
-
verifiers-0.4.2.
|
|
194
|
-
verifiers-0.4.2.
|
|
195
|
-
verifiers-0.4.2.
|
|
191
|
+
verifiers-0.4.2.dev129.dist-info/METADATA,sha256=PnxAp4-B116SB4k7q58kPzucp3WbFoKP0_YVhlSQTLg,5118
|
|
192
|
+
verifiers-0.4.2.dev129.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
193
|
+
verifiers-0.4.2.dev129.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
|
|
194
|
+
verifiers-0.4.2.dev129.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
|
|
195
|
+
verifiers-0.4.2.dev129.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|