verifiers 0.4.2.dev65__py3-none-any.whl → 0.4.2.dev67__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/__init__.py CHANGED
@@ -13,7 +13,14 @@ if TYPE_CHECKING:
13
13
  from pydantic_config import BaseConfig
14
14
 
15
15
  from verifiers.v1.acp import ACPConfig, ACPHarness, ACPTurn
16
- from verifiers.v1.agent import Agent, Agents, Interaction, Segment, make_agent
16
+ from verifiers.v1.agent import (
17
+ Agent,
18
+ AgentRun,
19
+ Agents,
20
+ Interaction,
21
+ Segment,
22
+ make_agent,
23
+ )
17
24
  from verifiers.v1.clients import (
18
25
  Client,
19
26
  ModelContext,
@@ -206,6 +213,7 @@ _NAME_TO_MODULE = {
206
213
  "ACP_SEMANTIC_EDGES_METADATA_KEY": "verifiers.v1.semantic",
207
214
  "ARTIFACTS_DIR": "verifiers.v1.utils.artifacts",
208
215
  "Agent": "verifiers.v1.agent",
216
+ "AgentRun": "verifiers.v1.agent",
209
217
  "AgentConfig": "verifiers.v1.configs.agent",
210
218
  "AgentInfo": "verifiers.v1.trace",
211
219
  "AgentSpan": "verifiers.v1.trace",
@@ -517,6 +525,7 @@ __all__ = [ # noqa: RUF022 - grouped by public API area
517
525
  "RetryRule",
518
526
  # agent
519
527
  "Agent",
528
+ "AgentRun",
520
529
  "Agents",
521
530
  "make_agent",
522
531
  # loaders
@@ -293,6 +293,9 @@ class ACPHarnessSession(HarnessSession):
293
293
  return {"outcome": "promptRequired", "reason": "noRunningTurn"}
294
294
  response = await self._request("steer", message=message, message_id=message_id)
295
295
  if not response.get("ok"):
296
+ if response.get("error_type") == "NotImplementedError":
297
+ error = str(response.get("error"))
298
+ raise NotImplementedError(error.removeprefix("NotImplementedError: "))
296
299
  raise RuntimeError(response.get("error") or "ACP steering failed")
297
300
  result = response.get("result")
298
301
  if not isinstance(result, dict):
@@ -388,7 +388,11 @@ async def serve_stream() -> None:
388
388
  response = {"ok": True, "result": result}
389
389
  except Exception as error: # noqa: BLE001 - serialize protocol failures
390
390
  traceback.print_exc()
391
- response = {"ok": False, "error": f"{type(error).__name__}: {error}"}
391
+ response = {
392
+ "ok": False,
393
+ "error": f"{type(error).__name__}: {error}",
394
+ "error_type": type(error).__name__,
395
+ }
392
396
  if isinstance(error, RequestError) and isinstance(error.data, dict):
393
397
  response["error"] = error.data.get("details") or str(error)
394
398
  response["error_data"] = error.data
verifiers/v1/agent.py CHANGED
@@ -9,11 +9,12 @@ server; un-entered, each run brings its own."""
9
9
 
10
10
  import asyncio
11
11
  import uuid
12
- from collections.abc import AsyncIterator, Awaitable, Callable, Mapping
12
+ from collections.abc import AsyncIterator, Awaitable, Callable, Coroutine, Mapping
13
13
  from contextlib import asynccontextmanager, nullcontext
14
14
  from contextvars import ContextVar
15
15
  from dataclasses import dataclass, field
16
- from typing import Generic, Literal, Self, cast
16
+ from functools import partial
17
+ from typing import Any, Generic, Literal, Self, cast
17
18
  from weakref import WeakValueDictionary
18
19
 
19
20
  from typing_extensions import TypeVar
@@ -201,6 +202,63 @@ class _PendingMessage:
201
202
  done: asyncio.Event = field(default_factory=asyncio.Event)
202
203
 
203
204
 
205
+ class AgentRun:
206
+ """One execution scheduled by Agent.start(), including its retry attempts."""
207
+
208
+ def __init__(self, execute: Callable[[Self], Coroutine[Any, Any, Trace]]) -> None:
209
+ self._active: Rollout | None = None
210
+ self._taken: dict[str, tuple[str, dict]] = {}
211
+ self._lock = asyncio.Lock()
212
+ self._deliveries: set[asyncio.Task[dict]] = set()
213
+ self._task = asyncio.create_task(execute(self))
214
+
215
+ async def wait(self) -> Trace:
216
+ """Wait for the final trace. Cancelling this wait also cancels the run."""
217
+ return await self._task
218
+
219
+ async def steer(self, message: str, *, message_id: str | None = None) -> dict:
220
+ """Send input to the current attempt. Accepted receipts identify the attempt."""
221
+ if not isinstance(message, str) or not message.strip():
222
+ raise ValueError("delivery requires a nonempty user message")
223
+ # Capture the attempt before waiting for other deliveries.
224
+ delivery = asyncio.create_task(self._deliver(self._active, message, message_id))
225
+ self._deliveries.add(delivery)
226
+ delivery.add_done_callback(self._delivery_done)
227
+ return dict(await asyncio.shield(delivery))
228
+
229
+ def _delivery_done(self, delivery: asyncio.Task[dict]) -> None:
230
+ self._deliveries.discard(delivery)
231
+ if not delivery.cancelled():
232
+ delivery.exception() # The caller may have cancelled its wait for this receipt.
233
+
234
+ async def _deliver(
235
+ self, run: Rollout | None, message: str, message_id: str | None
236
+ ) -> dict:
237
+ async with self._lock:
238
+ if message_id is not None and message_id in self._taken:
239
+ previous, receipt = self._taken[message_id]
240
+ if previous != message:
241
+ raise ValueError(
242
+ "steering message ID reused with different content"
243
+ )
244
+ return receipt
245
+ if run is None or run is not self._active:
246
+ return {"outcome": "promptRequired", "reason": "noRunningTurn"}
247
+ try:
248
+ receipt = await run.steer(message, message_id=message_id)
249
+ except NotImplementedError:
250
+ raise
251
+ except RuntimeError:
252
+ if run.closed or not run.ok:
253
+ return {"outcome": "promptRequired", "reason": "noRunningTurn"}
254
+ raise
255
+ if receipt.get("outcome") == "injected":
256
+ receipt = {**receipt, "attempt": run.trace.attempt}
257
+ if message_id is not None:
258
+ self._taken[message_id] = (message, receipt)
259
+ return receipt
260
+
261
+
204
262
  class Interaction:
205
263
  """An agent's rollout, held open turn-by-turn: the caller IS the run's user.
206
264
 
@@ -703,6 +761,54 @@ class Agent:
703
761
  `route` is where its model turns go, from the agent's model, client and
704
762
  sampling unless given; the caller may change it while the rollout runs
705
763
  (`ModelRoute.update`), and a retry takes it as it is then."""
764
+ return await self._run(
765
+ None,
766
+ task,
767
+ runtime=runtime,
768
+ tools=tools,
769
+ on_trace=on_trace,
770
+ collect_artifacts=collect_artifacts,
771
+ on_score=on_score,
772
+ route=route,
773
+ )
774
+
775
+ def start(
776
+ self,
777
+ task: Task,
778
+ *,
779
+ runtime: Runtime | None = None,
780
+ tools: Mapping[str, SharedToolServer] | None = None,
781
+ on_trace: Callable[[Trace], None] | None = None,
782
+ collect_artifacts: bool = False,
783
+ on_score: Callable[[Trace, Runtime], Awaitable[None]] | None = None,
784
+ route: ModelRoute | None = None,
785
+ ) -> AgentRun:
786
+ """Schedule a rollout and return the object used to steer it and await its trace."""
787
+ return AgentRun(
788
+ partial(
789
+ self._run,
790
+ task=task,
791
+ runtime=runtime,
792
+ tools=tools,
793
+ on_trace=on_trace,
794
+ collect_artifacts=collect_artifacts,
795
+ on_score=on_score,
796
+ route=route,
797
+ )
798
+ )
799
+
800
+ async def _run(
801
+ self,
802
+ handle: AgentRun | None,
803
+ task: Task,
804
+ *,
805
+ runtime: Runtime | None = None,
806
+ tools: Mapping[str, SharedToolServer] | None = None,
807
+ on_trace: Callable[[Trace], None] | None = None,
808
+ collect_artifacts: bool = False,
809
+ on_score: Callable[[Trace, Runtime], Awaitable[None]] | None = None,
810
+ route: ModelRoute | None = None,
811
+ ) -> Trace:
706
812
  if self._closed:
707
813
  raise RuntimeError("Agent is closed; create a new agent")
708
814
  route = route or ModelRoute(self.ctx)
@@ -720,6 +826,7 @@ class Agent:
720
826
  collect_artifacts,
721
827
  on_score,
722
828
  route,
829
+ handle,
723
830
  trace_id=trace_id,
724
831
  attempt=attempt + 1,
725
832
  )
@@ -760,6 +867,7 @@ class Agent:
760
867
  collect_artifacts: bool,
761
868
  on_score: Callable[[Trace, Runtime], Awaitable[None]] | None,
762
869
  route: ModelRoute,
870
+ handle: AgentRun | None,
763
871
  *,
764
872
  trace_id: str,
765
873
  attempt: int,
@@ -778,7 +886,13 @@ class Agent:
778
886
  )
779
887
  try:
780
888
  if await run.open():
781
- await run.step()
889
+ if handle is not None:
890
+ handle._active = run
891
+ try:
892
+ await run.step()
893
+ finally:
894
+ if handle is not None:
895
+ handle._active = None
782
896
  if run.ok:
783
897
  run.trace.stop("agent_completed")
784
898
  trace = await run.close()
@@ -1024,8 +1138,9 @@ class _EpisodeAgent(Agent):
1024
1138
 
1025
1139
  return score
1026
1140
 
1027
- async def run(
1141
+ async def _run(
1028
1142
  self,
1143
+ handle: AgentRun | None,
1029
1144
  task: Task,
1030
1145
  *,
1031
1146
  runtime: Runtime | None = None,
@@ -1036,7 +1151,8 @@ class _EpisodeAgent(Agent):
1036
1151
  route: ModelRoute | None = None,
1037
1152
  ) -> Trace:
1038
1153
  async with self._gate or nullcontext():
1039
- trace = await super().run(
1154
+ trace = await super()._run(
1155
+ handle,
1040
1156
  task,
1041
1157
  runtime=runtime,
1042
1158
  tools=tools if tools is not None else self._shared_for(task),
@@ -81,6 +81,10 @@ class PrimeAgentHarnessConfig(HarnessConfig):
81
81
 
82
82
  autonomous: bool = False
83
83
  """Enable Prime Agent's autonomous continuation loop."""
84
+ api: str | None = None
85
+ """The API Prime Agent speaks to the model's provider, e.g. `openai-completions` for an
86
+ OpenAI-compatible endpoint that serves only chat completions. Unset, Prime Agent picks the
87
+ provider's native API (Responses for `openai`)."""
84
88
  dialect: Literal["auto"] = "auto"
85
89
 
86
90
 
@@ -217,6 +221,7 @@ class PrimeAgentHarness(ACPHarness[PrimeAgentHarnessConfig]):
217
221
  # The native provider owns its API path, including any version prefix.
218
222
  "baseUrl": endpoint.removesuffix("/v1"),
219
223
  "apiKey": KEY_VAR,
224
+ **({"api": self.config.api} if self.config.api else {}),
220
225
  "models": [
221
226
  {
222
227
  "id": model,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verifiers
3
- Version: 0.4.2.dev65
3
+ Version: 0.4.2.dev67
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
- verifiers/v1/__init__.py,sha256=uBxLATpzAgN-Wi_j2_4yoh1JOitrJFQun2y33emEPRk,18870
3
- verifiers/v1/agent.py,sha256=Qf4P2wJCJsWRmKTHFvICXuHIBQ2zpxrzHzzBVQWaxi4,49723
2
+ verifiers/v1/__init__.py,sha256=7JZopLlXRErCQc-x1t-bSzwuenwlbh4-ayh3JrwOd7M,18991
3
+ verifiers/v1/agent.py,sha256=zhg7rn8MjU_57QS_kKTz_UKAG8TwYEPn8nt-ebHuv8A,54286
4
4
  verifiers/v1/delta.py,sha256=23USfU7G5L3TBnV3apyuOa0M_uQAgvTo6a4Ke4msRV0,12205
5
5
  verifiers/v1/env.py,sha256=UA1FdNd64XywIevJliNyL54afa2StN1ND6ro9HrjlVo,20566
6
6
  verifiers/v1/episode.py,sha256=ExeTkNEBsDuG40m6VogV6Gd4IHdO4SMPIzQSpt_V96U,6984
@@ -18,8 +18,8 @@ verifiers/v1/task.py,sha256=zcWjBjhJrkGIL29JTnxxw6v2pbJoiek_tF5RVAVV2ZY,15919
18
18
  verifiers/v1/taskset.py,sha256=PRwMfPtUL0Sg9pwKzJYnpLBDqJCmQ4skQPhF1oocyyw,9504
19
19
  verifiers/v1/trace.py,sha256=o7vnIt3pXRbn5JT_gYO05YaL4NlP0k8T_UlpJK3oqnA,40595
20
20
  verifiers/v1/types.py,sha256=0yhesjtRWnhgJz2cTJWWm4EaieE7ozXwH382onCHrMA,13104
21
- verifiers/v1/acp/__init__.py,sha256=jY7nLAbB6uzSl-f6YCz05zBH5tarBLErNTkvV0vlaho,16613
22
- verifiers/v1/acp/runner.py,sha256=sFsg0UgWeDjpjihejUidIV2yTapVj1Ap0cDTaEktjkI,15484
21
+ verifiers/v1/acp/__init__.py,sha256=5Cg5UdSWio0gn29l2RhNLg76KYdCdOJ001FlVbqpAfo,16819
22
+ verifiers/v1/acp/runner.py,sha256=3LW6GJKXqECdX4c4eLiPIrh1GpKzsOZXVDnpbMX4lfg,15583
23
23
  verifiers/v1/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  verifiers/v1/cli/debug.py,sha256=baX6LRtqBNjIbmHbdaogmz3FyyItN1Z4B-TVccuYI4k,11688
25
25
  verifiers/v1/cli/output.py,sha256=vCscZ-g-sa-SLWDDQNoXBWelC_Je8lBdodvZGOe__eo,3285
@@ -104,7 +104,7 @@ verifiers/v1/harnesses/pi/__init__.py,sha256=1mSnzOf-RdEchdeg6IHtcdobG5KIpAhuTdU
104
104
  verifiers/v1/harnesses/pi/gate.mjs,sha256=vk_OqHXhRdYzQL7YMX8Teajm0fh9tokzDvLHVOd2I9o,449
105
105
  verifiers/v1/harnesses/pi/harness.py,sha256=-E7_gBp7FswP3ObGpKh-RrkxsGGsygrUt7i-UHO7AFQ,8052
106
106
  verifiers/v1/harnesses/prime_agent/__init__.py,sha256=xfPC4RrlnyYWaf38tPAOZq4YL6M55lMpj5BoRLmaK8I,171
107
- verifiers/v1/harnesses/prime_agent/harness.py,sha256=a3PbDBejqYt31sLKkCHRCjn5h0_T3FpwZdru6w6jo2Y,12617
107
+ verifiers/v1/harnesses/prime_agent/harness.py,sha256=bIkPyMReT4y_qxNn8JaysN6NRpl9q0Jyaq1JoZsCHaI,12963
108
108
  verifiers/v1/harnesses/rlm/__init__.py,sha256=hwx51xTdEWzzYgMj-p4ETNcptoub3IPMDbEdJ4uB8Ns,122
109
109
  verifiers/v1/harnesses/rlm/harness.py,sha256=NZdJBsC1sFcmb0GXmIcJDl4Pi3YJDUNJ2sQ1i1tcLTQ,15839
110
110
  verifiers/v1/harnesses/stirrup/__init__.py,sha256=a-NQxX1bOwaGx8QHj2jWcRJEGiLIxdY6XUMbojr9dOk,142
@@ -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=Qo9qvsJAl8PoRUavjQAfUB2VNxmUtYQtU2ejLKPzY9c,3382
190
190
  verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
191
- verifiers-0.4.2.dev65.dist-info/METADATA,sha256=TS_ifYCs3klcs9smrz9eTIPBHmGfwMexAghyBKzXABo,5116
192
- verifiers-0.4.2.dev65.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
193
- verifiers-0.4.2.dev65.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
194
- verifiers-0.4.2.dev65.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
195
- verifiers-0.4.2.dev65.dist-info/RECORD,,
191
+ verifiers-0.4.2.dev67.dist-info/METADATA,sha256=Zl5ie4LKxZtCnA0UZjCYfwPpA27dWHo2ua9VYu-72c8,5116
192
+ verifiers-0.4.2.dev67.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
193
+ verifiers-0.4.2.dev67.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
194
+ verifiers-0.4.2.dev67.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
195
+ verifiers-0.4.2.dev67.dist-info/RECORD,,