verifiers 0.4.2.dev3__py3-none-any.whl → 0.4.2.dev5__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 CHANGED
@@ -9,6 +9,7 @@ server; un-entered, each run brings its own."""
9
9
 
10
10
  import asyncio
11
11
  import logging
12
+ import uuid
12
13
  from collections.abc import AsyncIterator, Awaitable, Callable, Mapping
13
14
  from contextlib import asynccontextmanager, nullcontext
14
15
  from contextvars import ContextVar
@@ -675,7 +676,8 @@ class Agent:
675
676
  moment it's minted, before any I/O. `collect_artifacts` captures the task's
676
677
  declared artifacts after its finalizer while its container runtime is still
677
678
  alive. Retries whole while the trace ends with a retryable error
678
- (`config.retries`) — never into a borrowed box; the final trace keeps earlier
679
+ (`config.retries`) — never into a borrowed box; every attempt's trace keeps
680
+ the run's id with its own `attempt`, and the final trace keeps earlier
679
681
  attempts' errors. `on_score(trace, runtime)` runs after task scoring in
680
682
  the selected verifier workspace, inside its timeout and retry boundary."""
681
683
  if self._closed:
@@ -683,9 +685,17 @@ class Agent:
683
685
  retry = self.config.retries
684
686
  retry_state = RetryState(retry)
685
687
  history: list = []
688
+ trace_id = uuid.uuid4().hex
686
689
  for attempt in range(retry_state.max_retries + 1):
687
690
  trace = await self._run_once(
688
- task, runtime, tools, on_trace, collect_artifacts, on_score
691
+ task,
692
+ runtime,
693
+ tools,
694
+ on_trace,
695
+ collect_artifacts,
696
+ on_score,
697
+ trace_id=trace_id,
698
+ attempt=attempt + 1,
689
699
  )
690
700
  if attempt == retry_state.max_retries or trace.ok:
691
701
  break
@@ -722,6 +732,9 @@ class Agent:
722
732
  on_trace: Callable[[Trace], None] | None,
723
733
  collect_artifacts: bool,
724
734
  on_score: Callable[[Trace, Runtime], Awaitable[None]] | None,
735
+ *,
736
+ trace_id: str,
737
+ attempt: int,
725
738
  ) -> Trace:
726
739
  params = self._rollout_params(task, runtime, dict(shared_tools or {}))
727
740
  if (
@@ -737,6 +750,8 @@ class Agent:
737
750
  on_trace=on_trace,
738
751
  collect_artifacts=collect_artifacts,
739
752
  on_score=on_score,
753
+ trace_id=trace_id,
754
+ attempt=attempt,
740
755
  **params,
741
756
  )
742
757
  try:
@@ -921,8 +936,8 @@ class _EpisodeAgent(Agent):
921
936
  if trace.agent is not None:
922
937
  trace.agent.name = self._name
923
938
  trace.agent.trainable = self.trainable
924
- # A per-agent retry mints a replacement: the abandoned attempt's trace
925
- # must leave live views (only the final one joins the episode).
939
+ # A per-agent retry replaces the trace under the same id: the abandoned
940
+ # attempt must leave live views (only the final one joins the episode).
926
941
  if last is not None and self._on_discard is not None:
927
942
  self._on_discard(last)
928
943
  last = trace
verifiers/v1/env.py CHANGED
@@ -4,6 +4,7 @@ import asyncio
4
4
  import contextlib
5
5
  import logging
6
6
  import traceback
7
+ import uuid
7
8
  from abc import ABC, abstractmethod
8
9
  from collections.abc import Awaitable, Callable
9
10
  from dataclasses import dataclass, field
@@ -58,6 +59,8 @@ class RunSlot:
58
59
  at dispatch so the slot still reads as running."""
59
60
 
60
61
  task: Task
62
+ id: str = field(default_factory=lambda: uuid.uuid4().hex)
63
+ """The episode's id. Stable across retries."""
61
64
  traces: list[Trace] = field(default_factory=list)
62
65
  episode: Episode | None = None
63
66
  done: bool = False
@@ -67,6 +70,7 @@ class RunSlot:
67
70
  def finished(cls, episode: Episode) -> "RunSlot":
68
71
  return cls(
69
72
  task=Task(episode.task.data),
73
+ id=episode.id,
70
74
  traces=list(episode.traces),
71
75
  episode=episode,
72
76
  done=True,
@@ -238,6 +242,8 @@ class Env(ABC, Generic[ConfigT]):
238
242
  *,
239
243
  on_trace: Callable[[Trace], None] | None = None,
240
244
  on_discard: Callable[[Trace], None] | None = None,
245
+ episode_id: str | None = None,
246
+ attempt: int = 1,
241
247
  ) -> Episode:
242
248
  """One episode of `task`, minted as the wire atom: `setup()` then `run()`
243
249
  over fresh agents, then `finalize()`. Its agents run one at a time
@@ -246,8 +252,11 @@ class Env(ABC, Generic[ConfigT]):
246
252
  Traces join the episode as runs complete — a hook raising mid-way yields the
247
253
  completed subset, its exception on the episode's `errors`. `on_trace` observes
248
254
  each agent-run's trace at mint; `on_discard` its abandonment (a per-agent
249
- retry mints a replacement)."""
255
+ retry replaces it). `episode_id` and `attempt` place a retry under the
256
+ episode it repeats."""
250
257
  episode = Episode(
258
+ **({"id": episode_id} if episode_id is not None else {}),
259
+ attempt=attempt,
251
260
  env=EnvInfo(id=self.config.env_id),
252
261
  task=TraceTask(
253
262
  type=type(task).__name__,
@@ -319,7 +328,11 @@ class Env(ABC, Generic[ConfigT]):
319
328
  `on_complete` (the runners' persistence hook, which fires when final).
320
329
  `on_trace` sees each trace at mint, after it joined `slot.traces`."""
321
330
 
331
+ attempts = 0
332
+
322
333
  async def attempt() -> Episode:
334
+ nonlocal attempts
335
+ attempts += 1
323
336
  slot.traces = [] # a retry shows the fresh attempt's traces
324
337
  live = slot.traces
325
338
 
@@ -339,6 +352,8 @@ class Env(ABC, Generic[ConfigT]):
339
352
  ctx,
340
353
  on_trace=minted,
341
354
  on_discard=discard,
355
+ episode_id=slot.id,
356
+ attempt=attempts,
342
357
  )
343
358
 
344
359
  episode = await run_episode_with_retry(attempt, self.config.retries)
verifiers/v1/episode.py CHANGED
@@ -46,6 +46,9 @@ class Episode(BaseModel, Generic[DataT, StateT, AgentConfigT]):
46
46
  """The artifact Env.run produces. Contains multiple agents' traces."""
47
47
 
48
48
  id: str = Field(default_factory=lambda: uuid.uuid4().hex)
49
+ """Unique ID for this episode, auto-generated. Stable across retries."""
50
+ attempt: int = 1
51
+ """Which attempt of the episode this is, from 1."""
49
52
 
50
53
  env: EnvInfo = Field(default_factory=EnvInfo)
51
54
  """The env that produced this episode."""
@@ -119,8 +119,10 @@ class GEPAAdapter:
119
119
  def _episode_score(episode: Episode) -> float:
120
120
  """A candidate's score on one episode: the mean reward of the episode's scored
121
121
  traces. Seats that recorded no rewards (a reward-less judge) don't dilute the
122
- signal; an episode with no scored traces scores 0."""
122
+ signal; a successful episode with no scored traces scores 0."""
123
123
  if any(trace.is_dropped for trace in episode.traces):
124
124
  raise ValueError("GEPA cannot score an episode containing dropped traces")
125
+ if not episode.ok:
126
+ raise ValueError(f"GEPA cannot score failed episode {episode.id!r}")
125
127
  scored = [trace.reward for trace in episode.traces if trace.rewards]
126
128
  return sum(scored) / len(scored) if scored else 0.0
verifiers/v1/rollout.py CHANGED
@@ -115,6 +115,8 @@ class Rollout:
115
115
  on_trace: Callable[[Trace], None] | None = None,
116
116
  collect_artifacts: bool = False,
117
117
  on_score: Callable[[Trace, Runtime], Awaitable[None]] | None = None,
118
+ trace_id: str | None = None,
119
+ attempt: int = 1,
118
120
  ) -> None:
119
121
  self._on_score = on_score
120
122
  self.task = task
@@ -136,6 +138,8 @@ class Rollout:
136
138
  self._borrowed_runtime = runtime
137
139
  self._collect_artifacts = collect_artifacts
138
140
  self.trace: Trace = Trace(
141
+ **({"id": trace_id} if trace_id is not None else {}),
142
+ attempt=attempt,
139
143
  task=TraceTask(
140
144
  type=type(task).__name__,
141
145
  data=task.data,
@@ -8,6 +8,7 @@ import os
8
8
  import shutil
9
9
  import signal
10
10
  import stat
11
+ import tempfile
11
12
  from collections.abc import AsyncIterator
12
13
  from pathlib import Path
13
14
  from typing import ClassVar
@@ -99,8 +100,10 @@ class SubprocessBackend(RuntimeBackend):
99
100
  self._children: list[asyncio.subprocess.Process] = []
100
101
 
101
102
  async def start(self) -> None:
102
- self.workdir = CACHE_DIR / "runtimes" / "subprocess" / self.name
103
- self.workdir.mkdir(parents=True)
103
+ root = CACHE_DIR / "runtimes" / "subprocess"
104
+ root.mkdir(parents=True, exist_ok=True)
105
+ # Names repeat across retries, and a failed teardown can leave a workdir behind.
106
+ self.workdir = Path(tempfile.mkdtemp(prefix=f"{self.name}-", dir=root))
104
107
  self.info.id = str(self.workdir)
105
108
 
106
109
  async def run(
verifiers/v1/trace.py CHANGED
@@ -576,7 +576,9 @@ class Trace(BaseModel, Generic[DataT, StateT, AgentConfigT]):
576
576
  version: int = TRACE_VERSION
577
577
  """The trace schema this trace serializes as."""
578
578
  id: str = Field(default_factory=lambda: uuid.uuid4().hex)
579
- """Unique ID for this trace, auto-generated."""
579
+ """Unique ID for this agent run, auto-generated. Stable across retries."""
580
+ attempt: int = 1
581
+ """Which attempt of the agent run this trace records, from 1."""
580
582
  verifiers: VersionInfo = Field(default_factory=_current_build)
581
583
  """The verifiers version that produced this trace."""
582
584
  task: TraceTask[DataT]
@@ -121,10 +121,10 @@ async def run_episode_with_retry(
121
121
  run: Callable[[], Awaitable[Episode]],
122
122
  retry: RetryConfig,
123
123
  ) -> Episode:
124
- """Run one episode (each attempt mints a fresh one), retrying while
125
- it ends with a retryable error. When the final attempt fails too, the earlier
126
- attempts' errors are prepended so the episode shows the full history; a final
127
- good attempt returns clean."""
124
+ """Run one episode (each attempt builds a fresh one under the same id),
125
+ retrying while it ends with a retryable error. When the final attempt fails
126
+ too, the earlier attempts' errors are prepended so the episode shows the full
127
+ history; a final good attempt returns clean."""
128
128
  history: list = []
129
129
  state = RetryState(retry)
130
130
  for attempt in range(state.max_retries + 1):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verifiers
3
- Version: 0.4.2.dev3
3
+ Version: 0.4.2.dev5
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,20 +1,20 @@
1
1
  verifiers/__init__.py,sha256=F5IVMw6mhGaPBMCw7QKk0la_r5mMwydP2hdTTdQucik,352
2
2
  verifiers/v1/__init__.py,sha256=gVnDxIQXsDjha93fZzdLw2b1G5i8i28drSf75JHmmHY,18617
3
- verifiers/v1/agent.py,sha256=_PBWiO3dmAGQvD4rCb5SIW6nLvYd7BBsPf1qxsQIXPw,47290
4
- verifiers/v1/env.py,sha256=O8T22R5WO_a8_CSjjRp4JLB-3CVBbTSNIYqZCqkX9_g,18088
5
- verifiers/v1/episode.py,sha256=bQnelv7mCvId3SP58VTDpPkoPDINP9NATEWDWtZ6APQ,6790
3
+ verifiers/v1/agent.py,sha256=M5Ja5vU7dFBpX3pcBfH6BqDvAYHjQ8GETQ-avDIekzw,47693
4
+ verifiers/v1/env.py,sha256=cTCK5f4gPNBfUYT2RtIEsMgslYgtzXtam2coCPsOzqc,18631
5
+ verifiers/v1/episode.py,sha256=U87tUbAKbZYKyNJLXi2h2_tX0u14ZHgV2CmpzYO67Ag,6944
6
6
  verifiers/v1/errors.py,sha256=OieUBIOZ6FW7oKygbXIRoag6RrPxKYpMPfEYPcCnVVE,5863
7
7
  verifiers/v1/grading.py,sha256=Z8J9-UiQA_P8MOMn1CAGsD_SgmrQd6-H_VPmD27ezss,9685
8
8
  verifiers/v1/graph.py,sha256=wsVUZmCSfu6FuEwEI1cDrroABFbBRnJX9yNVdNOi45A,48126
9
9
  verifiers/v1/harness.py,sha256=Hvul6cbb9uWQl4GmHubvcRHqKdfeCY3n44r_ga0csfI,16806
10
10
  verifiers/v1/judge.py,sha256=T-TyYVcLGIoyUADYKy_pCBj2CTLhERlct5pmmWqPpTA,10507
11
- verifiers/v1/rollout.py,sha256=LYzSO39TjWWBD1P18B7pfKVptaff60Op1f778U-VU8c,46048
11
+ verifiers/v1/rollout.py,sha256=icIjp62QKkImVyJ-ypmNh1Jj2qdpKWAZ6ZDrmg54ev8,46206
12
12
  verifiers/v1/semantic.py,sha256=nqKPPUoPL5Oh8Es_XjtcbDiQiIMKTYayXEm-EPB-jAE,5129
13
13
  verifiers/v1/session.py,sha256=fuw4eEVxTw_KlkSspxbgejEhmSXJYjX7bUquq2LJ_CU,29640
14
14
  verifiers/v1/state.py,sha256=EckF2bWp-vV4b1jYJ9sLI5xrfGuI5spIgYYwW926toI,595
15
15
  verifiers/v1/task.py,sha256=emEKiNthgFKyJA3k-omloxSnFGbRR7cXkTiKXJh_3U4,15529
16
16
  verifiers/v1/taskset.py,sha256=LE_3ogL7itU2Amk-N20cHkZ7Ev6MznJ0HpC8B1xb4w0,9482
17
- verifiers/v1/trace.py,sha256=uipmTRX93FchbQa0g_zt0xhScxXT4ysBm3CZ-Wo_RGI,40650
17
+ verifiers/v1/trace.py,sha256=4OC13ee0oBWkBDQzZ2GIGBpUwgMD3LkpPv-jfsf4Ycc,40767
18
18
  verifiers/v1/types.py,sha256=mEy4C9Hl3fK9091kxqalqbVZNRnSI5A0npRHchpsFsM,14800
19
19
  verifiers/v1/acp/__init__.py,sha256=jY7nLAbB6uzSl-f6YCz05zBH5tarBLErNTkvV0vlaho,16613
20
20
  verifiers/v1/acp/runner.py,sha256=sFsg0UgWeDjpjihejUidIV2yTapVj1Ap0cDTaEktjkI,15484
@@ -68,7 +68,7 @@ verifiers/v1/envs/single_agent/env.py,sha256=iH-AnS5-5rDZM3MaYFxzaHSVqJAaw9mQJaa
68
68
  verifiers/v1/envs/user_sim/__init__.py,sha256=nnT695HdqjAEouYL5wtVu6MhIp2wf5yuK-EYgxOVx0s,118
69
69
  verifiers/v1/envs/user_sim/env.py,sha256=deI4r-Utn_v4E_Vb9P_X3LzFh2GRkCO4OlQt8BOCMGY,4942
70
70
  verifiers/v1/gepa/__init__.py,sha256=6nmdRE0-34AKioPHBjTxUg5Jo_2z7tMX-OU3zMNpAJI,197
71
- verifiers/v1/gepa/adapter.py,sha256=YFQKf4H-sxZevylJWaBC5PDs2YDTalwIgtx39HzWDFg,6252
71
+ verifiers/v1/gepa/adapter.py,sha256=J35ZBiI4N--Zgt0RuBzGZwOGxeF-nnIVEBf3rIc0Pgc,6362
72
72
  verifiers/v1/gepa/config.py,sha256=e1qYZOKzvfN6hehFSKba4hEdbR22yQEYeSEFOCqchYI,4735
73
73
  verifiers/v1/gepa/dataset.py,sha256=cS4MtQVoBOnAHKs8REQm5lKGeqUpdXPU1hROU67aBG4,2130
74
74
  verifiers/v1/gepa/reflection.py,sha256=V1VSXuszkw5Fikwqwe5KSwunhlibudZ7F8csUXraENk,1144
@@ -152,7 +152,7 @@ verifiers/v1/runtimes/strategies.py,sha256=nQC_dsuYwpPz46js2LNY5nuGyFXv8znKU7_xH
152
152
  verifiers/v1/runtimes/backends/custom.py,sha256=Iz1Brd4dBTpO1zYVc2KA0u5sxz5ZUROY_Cdme5W33hM,2875
153
153
  verifiers/v1/runtimes/backends/docker.py,sha256=S6xwCYUR8RwNcdG45H0Bw_lNDo7_049MG0Y3CznoMtM,31476
154
154
  verifiers/v1/runtimes/backends/prime.py,sha256=Lf92Wo64W9rgejTE5KBVZFqfCDaQYmRYiAmiyGnn9S8,24444
155
- verifiers/v1/runtimes/backends/subprocess.py,sha256=dCfazoyJHwrfb2fMNRv6QzD6EsYlZXcEDT0x-8MAp3I,8419
155
+ verifiers/v1/runtimes/backends/subprocess.py,sha256=naOWJGmcaOlu2ZdRbUwhJicJdxASDRAUhDT0jzDff3w,8591
156
156
  verifiers/v1/tasksets/__init__.py,sha256=2ijE3qIlLoUA02g6iysOwWQylyBBQL1GhSpjv8_bp0w,521
157
157
  verifiers/v1/tasksets/harbor/__init__.py,sha256=FjW4tM3rgGALMK-8p7ux26G4-d4ZFVmaAmO6Fni6e_g,214
158
158
  verifiers/v1/tasksets/harbor/taskset.py,sha256=Ganz72MxzVn7zfdk-GCK3KMULAelGRtDQBdE6tXYMjc,42720
@@ -184,13 +184,13 @@ verifiers/v1/utils/memory.py,sha256=ZkIvGk6uITAH5sKon65LifKPbvZr8mJ__PVc23FZpOQ,
184
184
  verifiers/v1/utils/network.py,sha256=SI6_PXHIAPows6VBpK75N6dMbPw6lWQQ3OjBQkSDGN4,1463
185
185
  verifiers/v1/utils/paths.py,sha256=it_4JWf_8bPZe4TRcyvL7_KJ4fsbEsxhhIY_xA8Ikus,308
186
186
  verifiers/v1/utils/prime.py,sha256=UTYRjp9cbjNb6CVmBHda-1wWZAIIfxNOmTyNuT7_wL4,970
187
- verifiers/v1/utils/retries.py,sha256=xTDdORf9BmFq7HhxEjNkhuduOSVekCl4l2ei9ZlQIIQ,6052
187
+ verifiers/v1/utils/retries.py,sha256=eoYF1r4SCWVdAq8tEQkE4ZJGBlzy5r8HWllQqMDTdYU,6071
188
188
  verifiers/v1/utils/scope.py,sha256=ivYGJ8GhzyRKbP4L48VsUDWFxpmFsjeaE_7KYBKJ_c0,826
189
189
  verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
190
190
  verifiers/v1/utils/trace_store.py,sha256=Qo9qvsJAl8PoRUavjQAfUB2VNxmUtYQtU2ejLKPzY9c,3382
191
191
  verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
192
- verifiers-0.4.2.dev3.dist-info/METADATA,sha256=VDWv-iflXOR06Mj1X98E4xZ31Ss7JiC8C9otfu7JlBY,5136
193
- verifiers-0.4.2.dev3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
194
- verifiers-0.4.2.dev3.dist-info/entry_points.txt,sha256=3M8Wr0w1cUKiB-fJ6YHB6eK5WuKYg-Y3OC4wCuUje_c,174
195
- verifiers-0.4.2.dev3.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
196
- verifiers-0.4.2.dev3.dist-info/RECORD,,
192
+ verifiers-0.4.2.dev5.dist-info/METADATA,sha256=HvILRmI7bwxVCtg-4o0w_skC0qvx9w0-L_I297j3c4c,5136
193
+ verifiers-0.4.2.dev5.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
194
+ verifiers-0.4.2.dev5.dist-info/entry_points.txt,sha256=3M8Wr0w1cUKiB-fJ6YHB6eK5WuKYg-Y3OC4wCuUje_c,174
195
+ verifiers-0.4.2.dev5.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
196
+ verifiers-0.4.2.dev5.dist-info/RECORD,,