verifiers 0.3.2.dev1__py3-none-any.whl → 0.3.2.dev3__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 +2 -1
- verifiers/v1/acp/__init__.py +42 -8
- verifiers/v1/acp/runner.py +45 -11
- verifiers/v1/agent.py +11 -4
- verifiers/v1/harnesses/rlm/harness.py +50 -48
- verifiers/v1/interception/server.py +175 -60
- verifiers/v1/rollout.py +4 -0
- verifiers/v1/session.py +20 -7
- verifiers/v1/trace.py +5 -1
- {verifiers-0.3.2.dev1.dist-info → verifiers-0.3.2.dev3.dist-info}/METADATA +1 -1
- {verifiers-0.3.2.dev1.dist-info → verifiers-0.3.2.dev3.dist-info}/RECORD +14 -14
- {verifiers-0.3.2.dev1.dist-info → verifiers-0.3.2.dev3.dist-info}/WHEEL +0 -0
- {verifiers-0.3.2.dev1.dist-info → verifiers-0.3.2.dev3.dist-info}/entry_points.txt +0 -0
- {verifiers-0.3.2.dev1.dist-info → verifiers-0.3.2.dev3.dist-info}/licenses/LICENSE +0 -0
verifiers/v1/__init__.py
CHANGED
|
@@ -2,7 +2,7 @@ import logging as _logging
|
|
|
2
2
|
|
|
3
3
|
from pydantic_config import BaseConfig
|
|
4
4
|
|
|
5
|
-
from verifiers.v1.acp import ACPConfig, ACPHarness
|
|
5
|
+
from verifiers.v1.acp import ACPConfig, ACPHarness, ACPTurn
|
|
6
6
|
from verifiers.v1.agent import Agent, Agents, Interaction, Segment, make_agent
|
|
7
7
|
from verifiers.v1.clients import (
|
|
8
8
|
BaseClientConfig,
|
|
@@ -280,6 +280,7 @@ __all__ = [ # noqa: RUF022 - grouped by public API area
|
|
|
280
280
|
"HarnessConfig",
|
|
281
281
|
"ACPConfig",
|
|
282
282
|
"ACPHarness",
|
|
283
|
+
"ACPTurn",
|
|
283
284
|
"ModelContext",
|
|
284
285
|
"Runtime",
|
|
285
286
|
"RuntimeProcess",
|
verifiers/v1/acp/__init__.py
CHANGED
|
@@ -7,7 +7,9 @@ from abc import abstractmethod
|
|
|
7
7
|
from collections.abc import AsyncIterator
|
|
8
8
|
from dataclasses import dataclass
|
|
9
9
|
from pathlib import Path
|
|
10
|
-
from typing import TypeAlias, TypeVar
|
|
10
|
+
from typing import Any, TypeAlias, TypeVar, cast
|
|
11
|
+
|
|
12
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
11
13
|
|
|
12
14
|
from verifiers.v1.clients import ModelContext
|
|
13
15
|
from verifiers.v1.configs.harness import HarnessConfig
|
|
@@ -22,7 +24,7 @@ from verifiers.v1.utils.aio import run_shielded
|
|
|
22
24
|
ACP_SOURCE = (Path(__file__).resolve().parent / "runner.py").read_text()
|
|
23
25
|
MAX_PACKET_BYTES = 128 * 1024 * 1024
|
|
24
26
|
|
|
25
|
-
__all__ = ["ACPConfig", "ACPHarness"]
|
|
27
|
+
__all__ = ["ACPConfig", "ACPHarness", "ACPTurn"]
|
|
26
28
|
|
|
27
29
|
ConfigT = TypeVar("ConfigT", bound=HarnessConfig)
|
|
28
30
|
JsonValue: TypeAlias = (
|
|
@@ -31,6 +33,17 @@ JsonValue: TypeAlias = (
|
|
|
31
33
|
JsonObject: TypeAlias = dict[str, JsonValue]
|
|
32
34
|
|
|
33
35
|
|
|
36
|
+
class ACPTurn(BaseModel):
|
|
37
|
+
"""One completed ACP prompt and its extension metadata."""
|
|
38
|
+
|
|
39
|
+
model_config = ConfigDict(extra="forbid", strict=True)
|
|
40
|
+
|
|
41
|
+
reply: str
|
|
42
|
+
stop_reason: str | None = None
|
|
43
|
+
response_metadata: dict[str, Any] = Field(default_factory=dict)
|
|
44
|
+
update_metadata: list[dict[str, Any]] = Field(default_factory=list)
|
|
45
|
+
|
|
46
|
+
|
|
34
47
|
@dataclass
|
|
35
48
|
class ACPConfig:
|
|
36
49
|
"""One harness's ACP process and initial prompt."""
|
|
@@ -51,6 +64,9 @@ class ACPHarness(Harness[ConfigT]):
|
|
|
51
64
|
ACP_SOURCE, {**self.config.resolved_env, "UV_FROZEN": "false"}
|
|
52
65
|
)
|
|
53
66
|
|
|
67
|
+
def acp_turn_result(self, trace: Trace, result: ACPTurn) -> None:
|
|
68
|
+
"""Consume the typed result of one ACP prompt."""
|
|
69
|
+
|
|
54
70
|
@abstractmethod
|
|
55
71
|
async def prepare_acp(
|
|
56
72
|
self,
|
|
@@ -73,6 +89,7 @@ class ACPHarness(Harness[ConfigT]):
|
|
|
73
89
|
secret: str,
|
|
74
90
|
mcp_urls: dict[str, str],
|
|
75
91
|
data: TaskData,
|
|
92
|
+
tool_interception_url: str | None = None,
|
|
76
93
|
) -> HarnessSession:
|
|
77
94
|
if not runtime.supports_live_processes:
|
|
78
95
|
raise HarnessError(
|
|
@@ -91,6 +108,7 @@ class ACPHarness(Harness[ConfigT]):
|
|
|
91
108
|
mcp_urls if config.mcp_urls is None else config.mcp_urls,
|
|
92
109
|
data,
|
|
93
110
|
config,
|
|
111
|
+
tool_interception_url,
|
|
94
112
|
)
|
|
95
113
|
|
|
96
114
|
async def launch(
|
|
@@ -115,6 +133,11 @@ def _packet(value: JsonObject) -> bytes:
|
|
|
115
133
|
return len(data).to_bytes(8, "big") + data
|
|
116
134
|
|
|
117
135
|
|
|
136
|
+
def _turn_result(response: JsonObject) -> ACPTurn:
|
|
137
|
+
value = response.get("result")
|
|
138
|
+
return ACPTurn.model_validate(value)
|
|
139
|
+
|
|
140
|
+
|
|
118
141
|
def _require_model_turn(trace: Trace, calls_before: int, result: ProgramResult) -> None:
|
|
119
142
|
if (
|
|
120
143
|
result.exit_code
|
|
@@ -153,7 +176,7 @@ class ACPHarnessSession(HarnessSession):
|
|
|
153
176
|
|
|
154
177
|
def __init__(
|
|
155
178
|
self,
|
|
156
|
-
harness:
|
|
179
|
+
harness: ACPHarness,
|
|
157
180
|
ctx: ModelContext,
|
|
158
181
|
trace: Trace,
|
|
159
182
|
runtime: Runtime,
|
|
@@ -162,8 +185,19 @@ class ACPHarnessSession(HarnessSession):
|
|
|
162
185
|
mcp_urls: dict[str, str],
|
|
163
186
|
data: TaskData,
|
|
164
187
|
config: ACPConfig,
|
|
188
|
+
tool_interception_url: str | None = None,
|
|
165
189
|
) -> None:
|
|
166
|
-
super().__init__(
|
|
190
|
+
super().__init__(
|
|
191
|
+
harness,
|
|
192
|
+
ctx,
|
|
193
|
+
trace,
|
|
194
|
+
runtime,
|
|
195
|
+
endpoint,
|
|
196
|
+
secret,
|
|
197
|
+
mcp_urls,
|
|
198
|
+
data,
|
|
199
|
+
tool_interception_url,
|
|
200
|
+
)
|
|
167
201
|
self.config = config
|
|
168
202
|
self._process: RuntimeProcess | None = None
|
|
169
203
|
self._reader: _PacketReader | None = None
|
|
@@ -233,15 +267,15 @@ class ACPHarnessSession(HarnessSession):
|
|
|
233
267
|
except BaseException:
|
|
234
268
|
await run_shielded(self._stop(graceful=False))
|
|
235
269
|
raise
|
|
270
|
+
turn = _turn_result(response)
|
|
271
|
+
self.trace.root_reply = turn.reply.strip()
|
|
236
272
|
if not response.get("ok"):
|
|
237
273
|
detail = response.get("error") or "ACP session request failed"
|
|
238
274
|
if stderr := self._stderr():
|
|
239
275
|
detail = f"{detail}\n\nACP process stderr:\n{stderr}"
|
|
240
276
|
raise RuntimeError(detail)
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
raise TypeError("ACP session reply must be a string")
|
|
244
|
-
result = ProgramResult(exit_code=0, stdout=reply, stderr="")
|
|
277
|
+
cast(ACPHarness, self.harness).acp_turn_result(self.trace, turn)
|
|
278
|
+
result = ProgramResult(exit_code=0, stdout=turn.reply, stderr="")
|
|
245
279
|
_require_model_turn(self.trace, calls_before, result)
|
|
246
280
|
return result
|
|
247
281
|
|
verifiers/v1/acp/runner.py
CHANGED
|
@@ -11,6 +11,7 @@ import signal
|
|
|
11
11
|
import sys
|
|
12
12
|
import traceback
|
|
13
13
|
from contextlib import AsyncExitStack, suppress
|
|
14
|
+
from dataclasses import asdict, dataclass
|
|
14
15
|
from typing import Any
|
|
15
16
|
|
|
16
17
|
from acp import (
|
|
@@ -35,16 +36,43 @@ from acp.schema import (
|
|
|
35
36
|
MAX_PACKET_BYTES = 128 * 1024 * 1024
|
|
36
37
|
|
|
37
38
|
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class ACPTurn:
|
|
41
|
+
reply: str
|
|
42
|
+
stop_reason: str | None
|
|
43
|
+
response_metadata: dict[str, Any]
|
|
44
|
+
update_metadata: list[dict[str, Any]]
|
|
45
|
+
|
|
46
|
+
|
|
38
47
|
class VerifiersACPClient(Client):
|
|
39
48
|
def __init__(self) -> None:
|
|
40
49
|
self.visible_reply = ""
|
|
41
50
|
self.message_id: str | None = None
|
|
51
|
+
self.stop_reason: str | None = None
|
|
52
|
+
self.response_metadata: dict[str, Any] = {}
|
|
53
|
+
self.update_metadata: list[dict[str, Any]] = []
|
|
42
54
|
|
|
43
55
|
def reset(self) -> None:
|
|
44
56
|
self.visible_reply = ""
|
|
45
57
|
self.message_id = None
|
|
58
|
+
self.stop_reason = None
|
|
59
|
+
self.response_metadata = {}
|
|
60
|
+
self.update_metadata = []
|
|
61
|
+
|
|
62
|
+
def turn_result(self) -> ACPTurn:
|
|
63
|
+
return ACPTurn(
|
|
64
|
+
reply=self.visible_reply,
|
|
65
|
+
stop_reason=self.stop_reason,
|
|
66
|
+
response_metadata=self.response_metadata,
|
|
67
|
+
update_metadata=self.update_metadata,
|
|
68
|
+
)
|
|
46
69
|
|
|
47
70
|
async def session_update(self, session_id: str, update: Any, **kwargs: Any) -> None:
|
|
71
|
+
metadata = dict(kwargs)
|
|
72
|
+
if isinstance(field_meta := getattr(update, "field_meta", None), dict):
|
|
73
|
+
metadata.update(field_meta)
|
|
74
|
+
if metadata:
|
|
75
|
+
self.update_metadata.append(metadata)
|
|
48
76
|
if isinstance(update, AgentMessageChunk) and isinstance(
|
|
49
77
|
update.content, TextContentBlock
|
|
50
78
|
):
|
|
@@ -117,7 +145,8 @@ async def prompt(
|
|
|
117
145
|
config: dict,
|
|
118
146
|
*,
|
|
119
147
|
is_new: bool,
|
|
120
|
-
) ->
|
|
148
|
+
) -> ACPTurn:
|
|
149
|
+
client.reset()
|
|
121
150
|
prompt_capabilities = capabilities and capabilities.prompt_capabilities
|
|
122
151
|
supports_images = bool(prompt_capabilities and prompt_capabilities.image)
|
|
123
152
|
blocks = []
|
|
@@ -126,13 +155,14 @@ async def prompt(
|
|
|
126
155
|
blocks.extend(user_content_blocks(config["user_contents"], supports_images))
|
|
127
156
|
if not blocks:
|
|
128
157
|
raise ValueError("ACP prompt has no content")
|
|
129
|
-
client.reset()
|
|
130
158
|
try:
|
|
131
|
-
await connection.prompt(session_id=session_id, prompt=blocks)
|
|
159
|
+
response = await connection.prompt(session_id=session_id, prompt=blocks)
|
|
160
|
+
client.stop_reason = response.stop_reason
|
|
161
|
+
client.response_metadata = dict(response.field_meta or {})
|
|
132
162
|
except RequestError as error:
|
|
133
163
|
detail = error.data.get("details") if isinstance(error.data, dict) else None
|
|
134
164
|
raise RuntimeError(detail or str(error)) from error
|
|
135
|
-
return client.
|
|
165
|
+
return client.turn_result()
|
|
136
166
|
|
|
137
167
|
|
|
138
168
|
class ACPSession:
|
|
@@ -180,11 +210,11 @@ class ACPSession:
|
|
|
180
210
|
self.session_id = session.session_id
|
|
181
211
|
self.is_new = True
|
|
182
212
|
|
|
183
|
-
async def run(self, config: dict) ->
|
|
213
|
+
async def run(self, config: dict) -> ACPTurn:
|
|
184
214
|
if self.connection is None:
|
|
185
215
|
await self.start(config)
|
|
186
216
|
assert self.session_id is not None
|
|
187
|
-
|
|
217
|
+
result = await prompt(
|
|
188
218
|
self.client,
|
|
189
219
|
self.connection,
|
|
190
220
|
self.capabilities,
|
|
@@ -193,7 +223,7 @@ class ACPSession:
|
|
|
193
223
|
is_new=self.is_new,
|
|
194
224
|
)
|
|
195
225
|
self.is_new = False
|
|
196
|
-
return
|
|
226
|
+
return result
|
|
197
227
|
|
|
198
228
|
async def close(self) -> None:
|
|
199
229
|
try:
|
|
@@ -204,9 +234,11 @@ class ACPSession:
|
|
|
204
234
|
if session_capabilities and session_capabilities.close is not None:
|
|
205
235
|
with suppress(Exception):
|
|
206
236
|
await self.connection.close_session(session_id=self.session_id)
|
|
207
|
-
await self.stack.aclose()
|
|
208
237
|
finally:
|
|
209
|
-
|
|
238
|
+
try:
|
|
239
|
+
await self.stack.aclose()
|
|
240
|
+
finally:
|
|
241
|
+
self._reset()
|
|
210
242
|
|
|
211
243
|
|
|
212
244
|
async def read_packet(stream: asyncio.StreamReader) -> dict | None:
|
|
@@ -249,11 +281,11 @@ async def serve_stream() -> None:
|
|
|
249
281
|
if operation == "prompt":
|
|
250
282
|
response = {
|
|
251
283
|
"ok": True,
|
|
252
|
-
"
|
|
284
|
+
"result": asdict(await session.run(request["config"])),
|
|
253
285
|
}
|
|
254
286
|
elif operation == "shutdown":
|
|
255
|
-
await session.close()
|
|
256
287
|
stop = True
|
|
288
|
+
await session.close()
|
|
257
289
|
response = {"ok": True}
|
|
258
290
|
else:
|
|
259
291
|
raise ValueError(f"unknown ACP session operation: {operation!r}")
|
|
@@ -263,6 +295,8 @@ async def serve_stream() -> None:
|
|
|
263
295
|
"ok": False,
|
|
264
296
|
"error": f"{type(error).__name__}: {error}",
|
|
265
297
|
}
|
|
298
|
+
if operation == "prompt":
|
|
299
|
+
response["result"] = asdict(session.client.turn_result())
|
|
266
300
|
write_packet(sys.stdout.buffer, response)
|
|
267
301
|
if stop:
|
|
268
302
|
break
|
verifiers/v1/agent.py
CHANGED
|
@@ -116,19 +116,23 @@ class Segment:
|
|
|
116
116
|
"""One harness segment's agent/tool output, as `Interaction.turn` returns it.
|
|
117
117
|
|
|
118
118
|
`messages` carries every model-sampled assistant message and intervening tool
|
|
119
|
-
result produced by the segment, in order
|
|
120
|
-
|
|
119
|
+
result produced by the segment, in order. `root_reply` identifies the root
|
|
120
|
+
agent's response when the trace also contains descendant branches.
|
|
121
|
+
`terminated` marks the exchange over — the run ended (a
|
|
121
122
|
limit, a `@stop`, or the harness finishing) instead of producing another
|
|
122
123
|
segment; a terminated `Segment` carries no messages (the last real segment was
|
|
123
124
|
already delivered), and the interaction's `trace` holds the full exchange.
|
|
124
125
|
"""
|
|
125
126
|
|
|
126
127
|
messages: Messages
|
|
128
|
+
root_reply: str | None = None
|
|
127
129
|
terminated: bool = False
|
|
128
130
|
|
|
129
131
|
@property
|
|
130
132
|
def last_reply(self) -> str:
|
|
131
|
-
"""The
|
|
133
|
+
"""The root agent's response, falling back to the final assistant message."""
|
|
134
|
+
if self.root_reply is not None:
|
|
135
|
+
return self.root_reply.strip()
|
|
132
136
|
for message in reversed(self.messages):
|
|
133
137
|
if isinstance(message, AssistantMessage):
|
|
134
138
|
return (message.content or "").strip()
|
|
@@ -210,7 +214,10 @@ class Interaction:
|
|
|
210
214
|
saw_assistant = True
|
|
211
215
|
elif saw_assistant and isinstance(node.message, ToolMessage):
|
|
212
216
|
segment_messages.append(node.message)
|
|
213
|
-
return Segment(
|
|
217
|
+
return Segment(
|
|
218
|
+
messages=segment_messages,
|
|
219
|
+
root_reply=self.trace.root_reply,
|
|
220
|
+
)
|
|
214
221
|
self._over = True
|
|
215
222
|
return Segment(messages=[], terminated=True)
|
|
216
223
|
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"""RLM over ACP, with MCP tools exposed as pre-imported IPython skills."""
|
|
2
2
|
|
|
3
|
-
import json
|
|
4
3
|
import logging
|
|
5
4
|
import random
|
|
6
5
|
import shlex
|
|
7
6
|
from typing import Literal
|
|
8
7
|
|
|
9
|
-
from pydantic import Field, PositiveInt, model_validator
|
|
8
|
+
from pydantic import BaseModel, ConfigDict, Field, PositiveInt, model_validator
|
|
10
9
|
|
|
11
|
-
from verifiers.v1.acp import ACPConfig, ACPHarness
|
|
10
|
+
from verifiers.v1.acp import ACPConfig, ACPHarness, ACPTurnResult, JsonObject
|
|
12
11
|
from verifiers.v1.clients import ModelContext
|
|
13
12
|
from verifiers.v1.configs.harness import HarnessConfig
|
|
14
13
|
from verifiers.v1.runtimes import Runtime
|
|
15
14
|
from verifiers.v1.task import TaskData
|
|
16
15
|
from verifiers.v1.trace import Trace
|
|
17
|
-
from verifiers.v1.utils.decorators import metric
|
|
18
16
|
|
|
19
17
|
logger = logging.getLogger(__name__)
|
|
20
18
|
|
|
@@ -25,15 +23,24 @@ RLM_DIR = "/tmp/vf-rlm"
|
|
|
25
23
|
RLM_BIN = f"{RLM_DIR}/bin/rlm"
|
|
26
24
|
SKILLS_DIR = "/task/rlm-skills"
|
|
27
25
|
RLM_STATE_DIR = ".vf-rlm"
|
|
26
|
+
RLM_RUNTIME_METADATA_KEY = "ai.prime.rlm/runtime-v1"
|
|
27
|
+
RLM_SESSION_METADATA_KEY = "ai.prime.rlm/session-v1"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class _SessionSnapshot(BaseModel):
|
|
31
|
+
model_config = ConfigDict(extra="ignore", strict=True)
|
|
32
|
+
|
|
33
|
+
session_id: str = Field(pattern=r"^[A-Za-z0-9._:-]{1,128}$")
|
|
34
|
+
metrics: dict[str, int | float]
|
|
28
35
|
|
|
29
36
|
|
|
30
37
|
class RLMHarnessConfig(HarnessConfig):
|
|
31
38
|
version: str = Field(
|
|
32
|
-
default="
|
|
39
|
+
default="5ee1c34024a183bbbd3a38a6129995f5b982631d", min_length=1
|
|
33
40
|
)
|
|
34
41
|
"""Git ref (branch, tag, or commit) of nano-rlm to install."""
|
|
35
42
|
max_depth: int = 0
|
|
36
|
-
"""Recursion depth
|
|
43
|
+
"""Recursion depth RLM may spawn sub-harnesses to."""
|
|
37
44
|
builtin_skills: list[BuiltinSkill] = Field(default_factory=list)
|
|
38
45
|
"""Built-in rlm skills to enable (RLM_SKILLS), e.g. `["edit"]`; empty enables none.
|
|
39
46
|
The tool set is fixed (ipython); the base `skills` field takes SKILL.md paths."""
|
|
@@ -54,7 +61,6 @@ class RLMHarnessConfig(HarnessConfig):
|
|
|
54
61
|
|
|
55
62
|
@model_validator(mode="after")
|
|
56
63
|
def reject_disabled_tools(self) -> "RLMHarnessConfig":
|
|
57
|
-
# rlm's only tool is ipython, which must stay enabled, so there's nothing to disable.
|
|
58
64
|
if self.disabled_tools:
|
|
59
65
|
raise ValueError(
|
|
60
66
|
"the rlm harness has a fixed tool set (ipython) and does not support "
|
|
@@ -91,41 +97,45 @@ class RLMHarness(ACPHarness[RLMHarnessConfig]):
|
|
|
91
97
|
raise RuntimeError(f"rlm install failed: {result.stderr.strip()[-500:]}")
|
|
92
98
|
await super().setup(runtime)
|
|
93
99
|
|
|
94
|
-
def summarize_threshold(self, task_idx: int | None) ->
|
|
95
|
-
"""
|
|
96
|
-
0 when unset — so a task's rollouts share one threshold). Always set — "" when disabled —
|
|
97
|
-
so the typed field, not a host var the subprocess runtime would inherit, wins."""
|
|
100
|
+
def summarize_threshold(self, task_idx: int | None) -> int | None:
|
|
101
|
+
"""Resolve a fixed or per-task compaction threshold."""
|
|
98
102
|
value = self.config.summarize_at_tokens
|
|
99
103
|
if value is None:
|
|
100
|
-
return
|
|
104
|
+
return None
|
|
101
105
|
if isinstance(value, tuple):
|
|
102
106
|
lo, hi = value
|
|
103
|
-
return
|
|
104
|
-
return
|
|
107
|
+
return random.Random(task_idx or 0).randint(lo, hi)
|
|
108
|
+
return value
|
|
105
109
|
|
|
106
|
-
def
|
|
110
|
+
def _runtime_metadata(
|
|
107
111
|
self,
|
|
108
112
|
ctx: ModelContext,
|
|
109
113
|
trace: Trace,
|
|
114
|
+
runtime: Runtime,
|
|
110
115
|
endpoint: str,
|
|
111
116
|
secret: str,
|
|
112
117
|
data: TaskData,
|
|
113
118
|
system_prompt: str | None,
|
|
114
|
-
) ->
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
"
|
|
119
|
+
) -> JsonObject:
|
|
120
|
+
payload = {
|
|
121
|
+
"session_id": trace.id,
|
|
122
|
+
"model": ctx.model,
|
|
123
|
+
"provider": {
|
|
124
|
+
"base_url": endpoint,
|
|
125
|
+
"api_key": secret,
|
|
126
|
+
},
|
|
127
|
+
"policy": {
|
|
128
|
+
"max_depth": self.config.max_depth,
|
|
129
|
+
"summarize_at_tokens": self.summarize_threshold(data.idx),
|
|
130
|
+
"max_concurrent_subagents": max(4, self.config.max_depth),
|
|
131
|
+
},
|
|
132
|
+
"system_prompt_path": None,
|
|
133
|
+
"append_to_system_prompt": system_prompt,
|
|
134
|
+
"skills": list(self.config.builtin_skills),
|
|
135
|
+
"kernel_env": runtime.env,
|
|
136
|
+
"search_api_key": self.config.resolved_env.get("SERPER_API_KEY"),
|
|
123
137
|
}
|
|
124
|
-
|
|
125
|
-
env["RLM_APPEND_TO_SYSTEM_PROMPT"] = system_prompt
|
|
126
|
-
if self.config.builtin_skills:
|
|
127
|
-
env["RLM_SKILLS"] = ",".join(self.config.builtin_skills)
|
|
128
|
-
return env
|
|
138
|
+
return {RLM_RUNTIME_METADATA_KEY: payload}
|
|
129
139
|
|
|
130
140
|
async def prepare_acp(
|
|
131
141
|
self,
|
|
@@ -139,29 +149,21 @@ class RLMHarness(ACPHarness[RLMHarnessConfig]):
|
|
|
139
149
|
) -> ACPConfig:
|
|
140
150
|
system_prompt, prompt = self.resolve_prompt(data)
|
|
141
151
|
return ACPConfig(
|
|
142
|
-
env=self.
|
|
152
|
+
env={**self.config.resolved_env, "RLM_HOME": self._home(trace)},
|
|
143
153
|
command=[RLM_BIN, "--acp"],
|
|
144
154
|
prompt=prompt,
|
|
155
|
+
session_meta=self._runtime_metadata(
|
|
156
|
+
ctx, trace, runtime, endpoint, secret, data, system_prompt
|
|
157
|
+
),
|
|
145
158
|
)
|
|
146
159
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if result.exit_code != 0 or not result.stdout.strip():
|
|
155
|
-
return {}
|
|
156
|
-
try:
|
|
157
|
-
meta = json.loads(result.stdout)
|
|
158
|
-
except json.JSONDecodeError:
|
|
159
|
-
return {}
|
|
160
|
-
return {
|
|
161
|
-
key: float(value)
|
|
162
|
-
for key, value in meta.get("metrics", {}).items()
|
|
163
|
-
if isinstance(value, (int, float)) and not isinstance(value, bool)
|
|
164
|
-
}
|
|
160
|
+
def acp_turn_result(self, trace: Trace, result: ACPTurnResult) -> None:
|
|
161
|
+
snapshot = _SessionSnapshot.model_validate(
|
|
162
|
+
result.response_metadata.get(RLM_SESSION_METADATA_KEY)
|
|
163
|
+
)
|
|
164
|
+
if snapshot.session_id != trace.id:
|
|
165
|
+
raise ValueError("RLM session snapshot does not match the rollout")
|
|
166
|
+
trace.record_metrics(snapshot.metrics)
|
|
165
167
|
|
|
166
168
|
async def cleanup(self, trace: Trace, runtime: Runtime) -> None:
|
|
167
169
|
await runtime.run(["rm", "-rf", f"{RLM_STATE_DIR}/{trace.id}"], {})
|
|
@@ -29,6 +29,7 @@ import time
|
|
|
29
29
|
import traceback
|
|
30
30
|
from collections.abc import AsyncIterator, Collection, Mapping
|
|
31
31
|
from contextlib import asynccontextmanager
|
|
32
|
+
from dataclasses import dataclass
|
|
32
33
|
from tempfile import SpooledTemporaryFile
|
|
33
34
|
from typing import Literal
|
|
34
35
|
|
|
@@ -58,7 +59,7 @@ from verifiers.v1.interception.tunnel import (
|
|
|
58
59
|
TunnelConfig,
|
|
59
60
|
make_tunnel,
|
|
60
61
|
)
|
|
61
|
-
from verifiers.v1.session import RolloutSession
|
|
62
|
+
from verifiers.v1.session import IdempotentRequest, ReplayResponse, RolloutSession
|
|
62
63
|
from verifiers.v1.trace import Error, ModelCall, PolicyEvent, TimeSpan
|
|
63
64
|
from verifiers.v1.types import FinishReason, Request, Response, Usage
|
|
64
65
|
|
|
@@ -80,6 +81,9 @@ HASH_INLINE_MAX = 1024**2 # 1 MiB
|
|
|
80
81
|
# Attempt counter the stainless-generated SDKs (OpenAI, Anthropic) send on every request:
|
|
81
82
|
# 0 on the first attempt, incremented on each retry of the same request.
|
|
82
83
|
RETRY_COUNT_HEADER = "x-stainless-retry-count"
|
|
84
|
+
IDEMPOTENCY_KEY_HEADER = "Idempotency-Key"
|
|
85
|
+
IDEMPOTENCY_CACHE_TTL_SECONDS = 600
|
|
86
|
+
IDEMPOTENCY_CACHE_MAX_COMPLETED = 64
|
|
83
87
|
|
|
84
88
|
|
|
85
89
|
def is_retried_request(headers: Mapping[str, str]) -> bool:
|
|
@@ -111,6 +115,87 @@ def _completion_response(completion: dict | None) -> web.Response:
|
|
|
111
115
|
return web.Response(body=body, content_type="application/json", charset="utf-8")
|
|
112
116
|
|
|
113
117
|
|
|
118
|
+
def _capture_response(response: web.Response) -> ReplayResponse:
|
|
119
|
+
body = response.body
|
|
120
|
+
if body is None:
|
|
121
|
+
data = b""
|
|
122
|
+
elif isinstance(body, bytes):
|
|
123
|
+
data = body
|
|
124
|
+
elif isinstance(body, bytearray):
|
|
125
|
+
data = bytes(body)
|
|
126
|
+
else:
|
|
127
|
+
raise TypeError("coalesced interception responses must have a byte body")
|
|
128
|
+
return ReplayResponse(status=response.status, body=data)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _replay_response(response: ReplayResponse) -> web.Response:
|
|
132
|
+
return web.Response(
|
|
133
|
+
body=response.body,
|
|
134
|
+
status=response.status,
|
|
135
|
+
content_type="application/json",
|
|
136
|
+
charset="utf-8",
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@dataclass(frozen=True)
|
|
141
|
+
class _IdempotentAttempt:
|
|
142
|
+
session: RolloutSession
|
|
143
|
+
key: str
|
|
144
|
+
request: IdempotentRequest
|
|
145
|
+
future: asyncio.Future[ReplayResponse | None]
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
_IDEMPOTENT_ATTEMPT = web.RequestKey("idempotent_attempt", _IdempotentAttempt)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _finish_idempotent_attempt(
|
|
152
|
+
request: web.Request, response: ReplayResponse | None
|
|
153
|
+
) -> None:
|
|
154
|
+
attempt = request.get(_IDEMPOTENT_ATTEMPT)
|
|
155
|
+
if attempt is None:
|
|
156
|
+
return
|
|
157
|
+
record = attempt.request
|
|
158
|
+
if record.inflight is attempt.future:
|
|
159
|
+
record.inflight = None
|
|
160
|
+
if (
|
|
161
|
+
record.response is None
|
|
162
|
+
and attempt.session.idempotent_requests.get(attempt.key) is record
|
|
163
|
+
):
|
|
164
|
+
attempt.session.idempotent_requests.pop(attempt.key)
|
|
165
|
+
if not attempt.future.done():
|
|
166
|
+
attempt.future.set_result(response)
|
|
167
|
+
if record.response is not None:
|
|
168
|
+
_prune_idempotent_requests(attempt.session, time.monotonic())
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _prune_idempotent_requests(session: RolloutSession, now: float) -> None:
|
|
172
|
+
"""Expire and cap completed replays; active attempts are never evicted."""
|
|
173
|
+
completed = [
|
|
174
|
+
(key, request)
|
|
175
|
+
for key, request in session.idempotent_requests.items()
|
|
176
|
+
if request.response is not None and request.inflight is None
|
|
177
|
+
]
|
|
178
|
+
for key, request in completed:
|
|
179
|
+
completed_at = request.completed_at or 0.0
|
|
180
|
+
if (
|
|
181
|
+
now - completed_at >= IDEMPOTENCY_CACHE_TTL_SECONDS
|
|
182
|
+
and session.idempotent_requests.get(key) is request
|
|
183
|
+
):
|
|
184
|
+
session.idempotent_requests.pop(key)
|
|
185
|
+
completed = [
|
|
186
|
+
(key, request)
|
|
187
|
+
for key, request in completed
|
|
188
|
+
if session.idempotent_requests.get(key) is request
|
|
189
|
+
]
|
|
190
|
+
excess = len(completed) - IDEMPOTENCY_CACHE_MAX_COMPLETED
|
|
191
|
+
if excess > 0:
|
|
192
|
+
for key, request in sorted(
|
|
193
|
+
completed, key=lambda item: item[1].completed_at or 0.0
|
|
194
|
+
)[:excess]:
|
|
195
|
+
if session.idempotent_requests.get(key) is request:
|
|
196
|
+
session.idempotent_requests.pop(key)
|
|
197
|
+
|
|
198
|
+
|
|
114
199
|
async def _queue_chunks(
|
|
115
200
|
chunks: AsyncIterator[bytes],
|
|
116
201
|
queue: asyncio.Queue[bytes | None],
|
|
@@ -214,7 +299,18 @@ class InterceptionServer(Interception):
|
|
|
214
299
|
selects the wire format (see `dialects.DIALECTS`)."""
|
|
215
300
|
|
|
216
301
|
async def handler(request: web.Request) -> web.StreamResponse:
|
|
217
|
-
|
|
302
|
+
try:
|
|
303
|
+
response = await self.handle_request(request, dialect)
|
|
304
|
+
except BaseException:
|
|
305
|
+
_finish_idempotent_attempt(request, None)
|
|
306
|
+
raise
|
|
307
|
+
replay = (
|
|
308
|
+
_capture_response(response)
|
|
309
|
+
if isinstance(response, web.Response)
|
|
310
|
+
else None
|
|
311
|
+
)
|
|
312
|
+
_finish_idempotent_attempt(request, replay)
|
|
313
|
+
return response
|
|
218
314
|
|
|
219
315
|
return handler
|
|
220
316
|
|
|
@@ -396,31 +492,57 @@ class InterceptionServer(Interception):
|
|
|
396
492
|
del raw
|
|
397
493
|
body = dialect.apply_overrides(body, session.ctx.model, session.ctx.sampling)
|
|
398
494
|
streaming = dialect.streaming(body)
|
|
495
|
+
upstream_headers = dict(request.headers)
|
|
399
496
|
logger.debug(
|
|
400
497
|
"intercept %s: id=%s stream=%s",
|
|
401
498
|
request.path,
|
|
402
499
|
session.trace.id,
|
|
403
500
|
streaming,
|
|
404
501
|
)
|
|
405
|
-
# Graph atomicity under retries:
|
|
406
|
-
#
|
|
407
|
-
#
|
|
408
|
-
#
|
|
409
|
-
# request), and a stale replay would loop the rollout.
|
|
502
|
+
# Graph atomicity under retries: one logical non-streaming call must commit at most
|
|
503
|
+
# one turn. An explicit key identifies that call directly; otherwise only the SDK's
|
|
504
|
+
# retry marker activates body-digest replay, since an unmarked repeated body can be a
|
|
505
|
+
# legitimate later turn.
|
|
410
506
|
retried = is_retried_request(request.headers)
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
507
|
+
idempotent: IdempotentRequest | None = None
|
|
508
|
+
idempotency_key = request.headers.get(IDEMPOTENCY_KEY_HEADER)
|
|
509
|
+
replay_key: str | None = None
|
|
510
|
+
binding = (request.path, req_hash)
|
|
511
|
+
if idempotency_key:
|
|
512
|
+
if streaming:
|
|
513
|
+
return web.json_response(
|
|
514
|
+
dialect.error_body(
|
|
515
|
+
"Idempotency-Key is not supported for streaming requests"
|
|
516
|
+
),
|
|
517
|
+
status=400,
|
|
518
|
+
)
|
|
519
|
+
replay_key = f"explicit:{idempotency_key}"
|
|
520
|
+
upstream_headers = {
|
|
521
|
+
name: value
|
|
522
|
+
for name, value in upstream_headers.items()
|
|
523
|
+
if name.lower() != IDEMPOTENCY_KEY_HEADER.lower()
|
|
524
|
+
}
|
|
525
|
+
elif not streaming:
|
|
526
|
+
replay_key = f"retry:{request.path}:{req_hash.hex()}"
|
|
527
|
+
|
|
528
|
+
if replay_key is not None:
|
|
529
|
+
now = time.monotonic()
|
|
530
|
+
_prune_idempotent_requests(session, now)
|
|
531
|
+
if idempotency_key or retried:
|
|
532
|
+
idempotent = session.idempotent_requests.get(replay_key)
|
|
533
|
+
if idempotent is not None and idempotent.binding != binding:
|
|
534
|
+
return web.json_response(
|
|
535
|
+
dialect.error_body(
|
|
536
|
+
"Idempotency-Key was reused with a different request"
|
|
537
|
+
),
|
|
538
|
+
status=400,
|
|
539
|
+
)
|
|
540
|
+
if idempotent is not None and idempotent.response is not None:
|
|
541
|
+
logger.debug(
|
|
542
|
+
"intercept replay: id=%s (idempotent request)", session.trace.id
|
|
543
|
+
)
|
|
544
|
+
idempotent.completed_at = now
|
|
545
|
+
return _replay_response(idempotent.response)
|
|
424
546
|
|
|
425
547
|
try:
|
|
426
548
|
model_request = dialect.parse_request(body)
|
|
@@ -435,37 +557,41 @@ class InterceptionServer(Interception):
|
|
|
435
557
|
dialect.error_body(f"rollout stopped: {session.trace.stop_condition}"),
|
|
436
558
|
status=400,
|
|
437
559
|
)
|
|
560
|
+
if replay_key is not None and idempotent is None:
|
|
561
|
+
idempotent = IdempotentRequest(binding=binding)
|
|
562
|
+
session.idempotent_requests[replay_key] = idempotent
|
|
438
563
|
|
|
439
|
-
async def coalesced(
|
|
564
|
+
async def coalesced(
|
|
565
|
+
inflight: "asyncio.Future[ReplayResponse | None]",
|
|
566
|
+
) -> web.Response:
|
|
440
567
|
logger.debug(
|
|
441
568
|
"intercept coalesce: id=%s (retry of in-flight turn)", session.trace.id
|
|
442
569
|
)
|
|
443
|
-
|
|
444
|
-
if
|
|
570
|
+
response = await asyncio.shield(inflight)
|
|
571
|
+
if response is None:
|
|
445
572
|
return web.json_response(
|
|
446
573
|
dialect.error_body("upstream attempt failed"), status=503
|
|
447
574
|
)
|
|
448
|
-
return
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
575
|
+
return _replay_response(response)
|
|
576
|
+
|
|
577
|
+
if idempotent is not None:
|
|
578
|
+
if idempotent.inflight is not None:
|
|
579
|
+
return await coalesced(idempotent.inflight)
|
|
580
|
+
assert replay_key is not None
|
|
581
|
+
future: asyncio.Future[ReplayResponse | None] = (
|
|
582
|
+
asyncio.get_running_loop().create_future()
|
|
583
|
+
)
|
|
584
|
+
idempotent.inflight = future
|
|
585
|
+
request[_IDEMPOTENT_ATTEMPT] = _IdempotentAttempt(
|
|
586
|
+
session=session,
|
|
587
|
+
key=replay_key,
|
|
588
|
+
request=idempotent,
|
|
589
|
+
future=future,
|
|
590
|
+
)
|
|
464
591
|
|
|
465
592
|
try:
|
|
466
593
|
refused = await session.refused()
|
|
467
594
|
if refused is not None:
|
|
468
|
-
finish_inflight()
|
|
469
595
|
return web.json_response(
|
|
470
596
|
dialect.error_body(f"rollout stopped: {refused}"), status=400
|
|
471
597
|
)
|
|
@@ -478,10 +604,8 @@ class InterceptionServer(Interception):
|
|
|
478
604
|
if stopped is None:
|
|
479
605
|
dialect.rewrite_request(body, original_request, model_request)
|
|
480
606
|
except RolloutError as error:
|
|
481
|
-
finish_inflight()
|
|
482
607
|
return self._fail(session, dialect, error)
|
|
483
608
|
except Exception as error: # noqa: BLE001 - surface task hook failures
|
|
484
|
-
finish_inflight()
|
|
485
609
|
return self._fail(
|
|
486
610
|
session,
|
|
487
611
|
dialect,
|
|
@@ -490,13 +614,11 @@ class InterceptionServer(Interception):
|
|
|
490
614
|
),
|
|
491
615
|
)
|
|
492
616
|
except BaseException:
|
|
493
|
-
finish_inflight()
|
|
494
617
|
raise
|
|
495
618
|
if stopped is not None:
|
|
496
619
|
turn = graph.prepare_turn(session.trace, model_request.messages)
|
|
497
620
|
turn.commit_prompt(model_request.tools)
|
|
498
621
|
session.trace.stop(stopped)
|
|
499
|
-
finish_inflight()
|
|
500
622
|
return web.json_response(
|
|
501
623
|
dialect.error_body(f"rollout stopped: {stopped}"),
|
|
502
624
|
status=400,
|
|
@@ -507,10 +629,8 @@ class InterceptionServer(Interception):
|
|
|
507
629
|
model_request = dialect.parse_request(body)
|
|
508
630
|
turn = graph.prepare_turn(session.trace, model_request.messages)
|
|
509
631
|
except ValueError as error:
|
|
510
|
-
finish_inflight()
|
|
511
632
|
return web.json_response(dialect.error_body(str(error)), status=400)
|
|
512
633
|
except RolloutError as error:
|
|
513
|
-
finish_inflight()
|
|
514
634
|
return self._fail(session, dialect, error)
|
|
515
635
|
|
|
516
636
|
inspect_response = bool(session.response_interceptors or session.response_stops)
|
|
@@ -527,16 +647,13 @@ class InterceptionServer(Interception):
|
|
|
527
647
|
)
|
|
528
648
|
|
|
529
649
|
def serve(response: Response) -> web.Response:
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
session.last_response = response.raw
|
|
536
|
-
finish_inflight(response.raw)
|
|
537
|
-
return _completion_response(response.raw)
|
|
650
|
+
served = _completion_response(response.raw)
|
|
651
|
+
if idempotent is not None:
|
|
652
|
+
idempotent.response = _capture_response(served)
|
|
653
|
+
idempotent.completed_at = time.monotonic()
|
|
654
|
+
return served
|
|
538
655
|
|
|
539
|
-
|
|
656
|
+
async def sample() -> web.Response:
|
|
540
657
|
session.error = None
|
|
541
658
|
call_response: Response | None = None
|
|
542
659
|
node: int | None = None
|
|
@@ -550,7 +667,7 @@ class InterceptionServer(Interception):
|
|
|
550
667
|
dialect,
|
|
551
668
|
body,
|
|
552
669
|
session.ctx.sampling,
|
|
553
|
-
headers=
|
|
670
|
+
headers=upstream_headers,
|
|
554
671
|
session_id=session.trace.id,
|
|
555
672
|
turn=turn,
|
|
556
673
|
)
|
|
@@ -654,10 +771,8 @@ class InterceptionServer(Interception):
|
|
|
654
771
|
policy_paths=policy_paths,
|
|
655
772
|
)
|
|
656
773
|
return serve(call_response)
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
# response" (an error/refuse return above), so the waiter surfaces a retryable error.
|
|
660
|
-
finish_inflight()
|
|
774
|
+
|
|
775
|
+
return await sample()
|
|
661
776
|
|
|
662
777
|
async def _stream(
|
|
663
778
|
self,
|
verifiers/v1/rollout.py
CHANGED
|
@@ -365,6 +365,8 @@ class Rollout:
|
|
|
365
365
|
return False
|
|
366
366
|
trace = self.trace
|
|
367
367
|
turns_before = trace.num_turns
|
|
368
|
+
root_reply_before = trace.root_reply
|
|
369
|
+
trace.root_reply = None
|
|
368
370
|
loop = asyncio.get_running_loop()
|
|
369
371
|
segment_start = loop.time()
|
|
370
372
|
self.deadline_at = (
|
|
@@ -410,6 +412,8 @@ class Rollout:
|
|
|
410
412
|
self.fail(e)
|
|
411
413
|
return False
|
|
412
414
|
finally:
|
|
415
|
+
if trace.num_turns == turns_before:
|
|
416
|
+
trace.root_reply = root_reply_before
|
|
413
417
|
if self._agent_time_remaining is not None:
|
|
414
418
|
self._agent_time_remaining = max(
|
|
415
419
|
0.0, self._agent_time_remaining - (loop.time() - segment_start)
|
verifiers/v1/session.py
CHANGED
|
@@ -94,6 +94,24 @@ class RolloutLimits:
|
|
|
94
94
|
return None
|
|
95
95
|
|
|
96
96
|
|
|
97
|
+
@dataclass
|
|
98
|
+
class IdempotentRequest:
|
|
99
|
+
"""One non-streaming model request shared by its original call and retries."""
|
|
100
|
+
|
|
101
|
+
binding: tuple[str, bytes]
|
|
102
|
+
response: "ReplayResponse | None" = None
|
|
103
|
+
completed_at: float | None = None
|
|
104
|
+
inflight: "asyncio.Future[ReplayResponse | None] | None" = None
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@dataclass(frozen=True)
|
|
108
|
+
class ReplayResponse:
|
|
109
|
+
"""The exact HTTP result handed to coalesced in-flight request attempts."""
|
|
110
|
+
|
|
111
|
+
status: int
|
|
112
|
+
body: bytes
|
|
113
|
+
|
|
114
|
+
|
|
97
115
|
@dataclass
|
|
98
116
|
class RolloutSession:
|
|
99
117
|
ctx: ModelContext
|
|
@@ -117,13 +135,8 @@ class RolloutSession:
|
|
|
117
135
|
(and may swallow it, or exit non-zero), so the rollout re-raises this original error once the
|
|
118
136
|
harness returns — recording the real `ProviderError` instead of a secondary `HarnessError`.
|
|
119
137
|
Reset before each model turn, so a successful retry clears it."""
|
|
120
|
-
|
|
121
|
-
"""
|
|
122
|
-
replays the common SDK retry of the latest completed exchange without re-sampling it."""
|
|
123
|
-
last_response: dict | None = None
|
|
124
|
-
"""The response returned for `last_request`, replayed verbatim on a retry."""
|
|
125
|
-
inflight: dict[bytes, "asyncio.Future[dict | None]"] = field(default_factory=dict)
|
|
126
|
-
"""Body digest -> the response currently computing, used to coalesce an in-flight retry."""
|
|
138
|
+
idempotent_requests: dict[str, IdempotentRequest] = field(default_factory=dict)
|
|
139
|
+
"""Explicit keys or marked SDK retries mapped to their replay state."""
|
|
127
140
|
released: bool = False
|
|
128
141
|
"""Set when the rollout unregisters the session: the trace is sealed (its conclusion is
|
|
129
142
|
what scored and persisted), so a handler still in flight must not commit turns, record
|
verifiers/v1/trace.py
CHANGED
|
@@ -406,6 +406,8 @@ class Trace(BaseModel, Generic[DataT, StateT, AgentConfigT]):
|
|
|
406
406
|
"""Unweighted, named metrics; `None` as in `rewards`."""
|
|
407
407
|
info: dict[str, Any] = Field(default_factory=dict)
|
|
408
408
|
"""Scratch space for task-specific metadata."""
|
|
409
|
+
root_reply: str | None = None
|
|
410
|
+
"""The root agent's response when a trace contains descendant branches."""
|
|
409
411
|
state: StateT = Field(default_factory=State, exclude=True)
|
|
410
412
|
"""Runtime (possibly, non-serializable) state shared across runtimes; excluded from serialization."""
|
|
411
413
|
|
|
@@ -543,7 +545,9 @@ class Trace(BaseModel, Generic[DataT, StateT, AgentConfigT]):
|
|
|
543
545
|
|
|
544
546
|
@property
|
|
545
547
|
def last_reply(self) -> str:
|
|
546
|
-
"""The
|
|
548
|
+
"""The root agent's response, falling back to the last assistant message."""
|
|
549
|
+
if self.root_reply is not None:
|
|
550
|
+
return self.root_reply.strip()
|
|
547
551
|
msgs = self.assistant_messages
|
|
548
552
|
return (msgs[-1].content or "").strip() if msgs else ""
|
|
549
553
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: verifiers
|
|
3
|
-
Version: 0.3.2.
|
|
3
|
+
Version: 0.3.2.dev3
|
|
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
|
|
@@ -168,23 +168,23 @@ verifiers/legacy/utils/threaded_sandbox_client.py,sha256=Vp4BJoHMIY0Tc52bQ4ngbTO
|
|
|
168
168
|
verifiers/legacy/utils/tool_utils.py,sha256=jkpFcuzdgNYa7hTOQrO3mqgqVDvDWZA8D3sIC6qsHRM,1027
|
|
169
169
|
verifiers/legacy/utils/usage_utils.py,sha256=P1KioJnOwijznTJu6Yb2KuFv4aWGf4jxUjEpaYmfkyg,3925
|
|
170
170
|
verifiers/legacy/utils/version_utils.py,sha256=aGPdNge6a3PU5RbIzWqApvT9oJZ5DIaDi4sFAbvr5-Y,2663
|
|
171
|
-
verifiers/v1/__init__.py,sha256=
|
|
172
|
-
verifiers/v1/agent.py,sha256=
|
|
171
|
+
verifiers/v1/__init__.py,sha256=AnXz2IG12salvxlOZvxFpG_3v9cvRc7B2DYuH_ORiD4,8090
|
|
172
|
+
verifiers/v1/agent.py,sha256=AfjyYmcGpVaOlZkElIz1JZeNRQuZsE_KMZ-LV3uLvzA,31644
|
|
173
173
|
verifiers/v1/env.py,sha256=CEhzjojhg5jqbOYruUnc5U7TtgDHDSx8NiiFA0qfbt8,18234
|
|
174
174
|
verifiers/v1/episode.py,sha256=uStvI4WqgJT50hmHIB55m5B-ASqqLz-fZ-ynBz9uzEY,5474
|
|
175
175
|
verifiers/v1/errors.py,sha256=kQeEPX06TwAIuiz7MlWFYirrpKbx5STi6A5b_dtQQoA,6885
|
|
176
176
|
verifiers/v1/graph.py,sha256=vjxIrE0e-IXeb8fIY0pRGfwrQlGsIAe9IjwHNZXqizk,30652
|
|
177
177
|
verifiers/v1/harness.py,sha256=ziECqEBWV34UWbLlxrkhY6MwkbVYkoXBOoaY7mZxwTs,14753
|
|
178
178
|
verifiers/v1/judge.py,sha256=Pvr0C41ah1qkNSZ0WXdkDvBMfv5YSfY1REHncwlJ8cg,9346
|
|
179
|
-
verifiers/v1/rollout.py,sha256=
|
|
180
|
-
verifiers/v1/session.py,sha256=
|
|
179
|
+
verifiers/v1/rollout.py,sha256=Eg6loXytL5ZaUiBZwQTrn74mo7waUIiauKQA650auJs,23974
|
|
180
|
+
verifiers/v1/session.py,sha256=GmwZoE-L4jzsUy7Fj9OUHu0yMLBe9lgSFKCbhLoZdjk,18706
|
|
181
181
|
verifiers/v1/state.py,sha256=EckF2bWp-vV4b1jYJ9sLI5xrfGuI5spIgYYwW926toI,595
|
|
182
182
|
verifiers/v1/task.py,sha256=ZiAE5uGxgHWqz8UF5YJHs80RgSKhxGMGQo4lJusSRus,11375
|
|
183
183
|
verifiers/v1/taskset.py,sha256=fp2E0IEhL_Ybj9cegZwljfTmW27p_30zTWHFKw_kXE4,4374
|
|
184
|
-
verifiers/v1/trace.py,sha256=
|
|
184
|
+
verifiers/v1/trace.py,sha256=XbV5KTSZSvkv0u544ei0bmPFRg6hcBNXUehEXJZ76d8,25125
|
|
185
185
|
verifiers/v1/types.py,sha256=a1wqL8T7KQg9WxkaDIZpmOyU6xT2VeSr1K4SWiW8ef4,9660
|
|
186
|
-
verifiers/v1/acp/__init__.py,sha256
|
|
187
|
-
verifiers/v1/acp/runner.py,sha256=
|
|
186
|
+
verifiers/v1/acp/__init__.py,sha256=t91yf1NmVvYiUbHCV-ApxcqFFT89JRNYpruu04k6Wco,11205
|
|
187
|
+
verifiers/v1/acp/runner.py,sha256=6Y7yTWP560IWrRijlnsB_t3lR79oRilrRoISXX4lXjc,10781
|
|
188
188
|
verifiers/v1/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
189
189
|
verifiers/v1/cli/debug.py,sha256=x3bqOwwbwwfwQQpxHrZeKdxsW3ZVtUT9cAn_r4aOro4,11631
|
|
190
190
|
verifiers/v1/cli/gepa.py,sha256=7YpppEMeuY2m1X5szGkybzTHztnIs83CvnSizhiEC-w,4210
|
|
@@ -277,14 +277,14 @@ verifiers/v1/harnesses/pi/harness.py,sha256=M0BRsfJxnBNP-KCrp0vT5gHlaJEDnyti5x_3
|
|
|
277
277
|
verifiers/v1/harnesses/pool/__init__.py,sha256=HTYsNiWGdiNEsSHj4xhPmshJSNb7SHjQ7d4yZQ4p3HM,127
|
|
278
278
|
verifiers/v1/harnesses/pool/harness.py,sha256=HKAogPbyLK5QpvPQ1teHOh_IyRQX-or2JF71nnZ_5Ps,3875
|
|
279
279
|
verifiers/v1/harnesses/rlm/__init__.py,sha256=hwx51xTdEWzzYgMj-p4ETNcptoub3IPMDbEdJ4uB8Ns,122
|
|
280
|
-
verifiers/v1/harnesses/rlm/harness.py,sha256=
|
|
280
|
+
verifiers/v1/harnesses/rlm/harness.py,sha256=XzPMrj-SlV8gNbRK0knFayoKqGnkduYkM3lNukZNPD8,6872
|
|
281
281
|
verifiers/v1/harnesses/terminus_2/__init__.py,sha256=l1pwfg1HyVDEqT9efdnFWcXqaZwtKwe7TrplkyxZSA0,166
|
|
282
282
|
verifiers/v1/harnesses/terminus_2/harness.py,sha256=kXKhi-aqqsoXGnvet0Tq_v7LYYpRYEzARyQL2MTEGWs,3101
|
|
283
283
|
verifiers/v1/harnesses/terminus_2/program.py,sha256=XWflwULPfVUyrwAldXLRVOoUWoWW9bYNsaygWef0Sfg,2668
|
|
284
284
|
verifiers/v1/interception/__init__.py,sha256=5Kvo7tcBUVaa65s9A1NiOH3CPpzw-P5btXwxB4Nbbvs,4251
|
|
285
285
|
verifiers/v1/interception/base.py,sha256=Mg16Y104lyZilF9shdivdqYoqz4OYp978i_myyrulu8,2529
|
|
286
286
|
verifiers/v1/interception/pool.py,sha256=sk_zcdTV8EVRuzqlYMXxon_42tSDAlFvwcyOO2EF7hw,6473
|
|
287
|
-
verifiers/v1/interception/server.py,sha256=
|
|
287
|
+
verifiers/v1/interception/server.py,sha256=Q1eS2uwjHMAlqwy78V15CMocq7Zglt3o5_bqiSodAA0,50709
|
|
288
288
|
verifiers/v1/interception/tool.py,sha256=ZyZPxLYM_HsGkz-ZbCREQVGtiKZK9lQLChBNF_bBuuc,259
|
|
289
289
|
verifiers/v1/interception/tunnel/__init__.py,sha256=eVNZJszj6myrKhx9jmJz7VRd9qlfj0AUvUZwI2bXEj8,893
|
|
290
290
|
verifiers/v1/interception/tunnel/base.py,sha256=DZB6uPLwM4Qy7n7m0vKeyg-Px87MhsmpYTpe2vpPEng,1998
|
|
@@ -348,8 +348,8 @@ verifiers/v1/utils/prime.py,sha256=UTYRjp9cbjNb6CVmBHda-1wWZAIIfxNOmTyNuT7_wL4,9
|
|
|
348
348
|
verifiers/v1/utils/retries.py,sha256=Y2ZgrAjn-qNkRKZP_RVNL_7EK0iaRcZeCa404lpGYi4,5417
|
|
349
349
|
verifiers/v1/utils/score.py,sha256=-R5Cog14r_tJ6Q_oOfGr5VPAm2CCUhofYZB6B9lm4wM,5787
|
|
350
350
|
verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
|
|
351
|
-
verifiers-0.3.2.
|
|
352
|
-
verifiers-0.3.2.
|
|
353
|
-
verifiers-0.3.2.
|
|
354
|
-
verifiers-0.3.2.
|
|
355
|
-
verifiers-0.3.2.
|
|
351
|
+
verifiers-0.3.2.dev3.dist-info/METADATA,sha256=I3EWX9LwsNFBnFFDm_MuaIbC9ICFRGE7OBjhpMqTYKU,4653
|
|
352
|
+
verifiers-0.3.2.dev3.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
353
|
+
verifiers-0.3.2.dev3.dist-info/entry_points.txt,sha256=hZ5wDc1T8y-EvOziw7kQqatBJ6PbdSu2ygP5rjANl7c,564
|
|
354
|
+
verifiers-0.3.2.dev3.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
|
|
355
|
+
verifiers-0.3.2.dev3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|