verifiers 0.3.2.dev23__py3-none-any.whl → 0.3.2.dev25__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 +12 -0
- verifiers/v1/acp/__init__.py +36 -5
- verifiers/v1/acp/runner.py +11 -4
- verifiers/v1/clients/eval.py +35 -31
- verifiers/v1/graph.py +135 -8
- verifiers/v1/harnesses/rlm/harness.py +33 -14
- verifiers/v1/interception/server.py +20 -4
- verifiers/v1/semantic.py +132 -0
- verifiers/v1/trace.py +75 -2
- {verifiers-0.3.2.dev23.dist-info → verifiers-0.3.2.dev25.dist-info}/METADATA +2 -2
- {verifiers-0.3.2.dev23.dist-info → verifiers-0.3.2.dev25.dist-info}/RECORD +14 -13
- {verifiers-0.3.2.dev23.dist-info → verifiers-0.3.2.dev25.dist-info}/WHEEL +0 -0
- {verifiers-0.3.2.dev23.dist-info → verifiers-0.3.2.dev25.dist-info}/entry_points.txt +0 -0
- {verifiers-0.3.2.dev23.dist-info → verifiers-0.3.2.dev25.dist-info}/licenses/LICENSE +0 -0
verifiers/v1/__init__.py
CHANGED
|
@@ -82,6 +82,13 @@ from verifiers.v1.runtimes import (
|
|
|
82
82
|
RuntimeProcess,
|
|
83
83
|
SubprocessConfig,
|
|
84
84
|
)
|
|
85
|
+
from verifiers.v1.semantic import (
|
|
86
|
+
ACP_SEMANTIC_EDGES_METADATA_KEY,
|
|
87
|
+
ACPInfo,
|
|
88
|
+
ParentLink,
|
|
89
|
+
SemanticEdge,
|
|
90
|
+
SemanticEdgeSet,
|
|
91
|
+
)
|
|
85
92
|
from verifiers.v1.state import State, StateT
|
|
86
93
|
from verifiers.v1.task import Task, TaskData, TaskResources, TaskTimeout, WireTaskData
|
|
87
94
|
from verifiers.v1.taskset import Taskset
|
|
@@ -226,6 +233,11 @@ __all__ = [ # noqa: RUF022 - grouped by public API area
|
|
|
226
233
|
"EvalRunInfo",
|
|
227
234
|
"EvalWorkInfo",
|
|
228
235
|
"ModelCall",
|
|
236
|
+
"ACPInfo",
|
|
237
|
+
"ACP_SEMANTIC_EDGES_METADATA_KEY",
|
|
238
|
+
"ParentLink",
|
|
239
|
+
"SemanticEdge",
|
|
240
|
+
"SemanticEdgeSet",
|
|
229
241
|
"PolicyEvent",
|
|
230
242
|
"TrainRunInfo",
|
|
231
243
|
"TrainWorkInfo",
|
verifiers/v1/acp/__init__.py
CHANGED
|
@@ -16,6 +16,10 @@ from verifiers.v1.configs.harness import HarnessConfig
|
|
|
16
16
|
from verifiers.v1.errors import HarnessError
|
|
17
17
|
from verifiers.v1.harness import Harness, HarnessSession
|
|
18
18
|
from verifiers.v1.runtimes import ProgramResult, Runtime, RuntimeProcess
|
|
19
|
+
from verifiers.v1.semantic import (
|
|
20
|
+
ACP_SEMANTIC_EDGES_METADATA_KEY,
|
|
21
|
+
SemanticEdgeSet,
|
|
22
|
+
)
|
|
19
23
|
from verifiers.v1.task import TaskData
|
|
20
24
|
from verifiers.v1.trace import Trace
|
|
21
25
|
from verifiers.v1.types import Messages
|
|
@@ -67,6 +71,20 @@ class ACPHarness(Harness[ConfigT]):
|
|
|
67
71
|
def acp_turn_result(self, trace: Trace, result: ACPTurn) -> None:
|
|
68
72
|
"""Consume the typed result of one ACP prompt."""
|
|
69
73
|
|
|
74
|
+
def acp_close_result(self, trace: Trace, response_metadata: dict[str, Any]) -> None:
|
|
75
|
+
"""Consume extension metadata returned by `session/close`, when supported."""
|
|
76
|
+
|
|
77
|
+
def _consume_protocol_metadata(
|
|
78
|
+
self, trace: Trace, response_metadata: dict[str, Any]
|
|
79
|
+
) -> None:
|
|
80
|
+
"""Attach optional protocol extensions understood by every ACP harness."""
|
|
81
|
+
if ACP_SEMANTIC_EDGES_METADATA_KEY not in response_metadata:
|
|
82
|
+
return
|
|
83
|
+
edge_set = SemanticEdgeSet.model_validate(
|
|
84
|
+
response_metadata[ACP_SEMANTIC_EDGES_METADATA_KEY]
|
|
85
|
+
)
|
|
86
|
+
trace.add_semantic_edges(edge_set)
|
|
87
|
+
|
|
70
88
|
@abstractmethod
|
|
71
89
|
async def prepare_acp(
|
|
72
90
|
self,
|
|
@@ -274,22 +292,30 @@ class ACPHarnessSession(HarnessSession):
|
|
|
274
292
|
if stderr := self._stderr():
|
|
275
293
|
detail = f"{detail}\n\nACP process stderr:\n{stderr}"
|
|
276
294
|
raise RuntimeError(detail)
|
|
277
|
-
cast(ACPHarness, self.harness)
|
|
295
|
+
harness = cast(ACPHarness, self.harness)
|
|
296
|
+
harness._consume_protocol_metadata(self.trace, turn.response_metadata)
|
|
297
|
+
harness.acp_turn_result(self.trace, turn)
|
|
278
298
|
result = ProgramResult(exit_code=0, stdout=turn.reply, stderr="")
|
|
279
299
|
_require_model_turn(self.trace, calls_before, result)
|
|
280
300
|
return result
|
|
281
301
|
|
|
282
|
-
async def _stop(self, *, graceful: bool) ->
|
|
302
|
+
async def _stop(self, *, graceful: bool) -> dict[str, Any]:
|
|
283
303
|
process, self._process = self._process, None
|
|
284
304
|
reader, self._reader = self._reader, None
|
|
285
305
|
stderr_task, self._stderr_task = self._stderr_task, None
|
|
286
306
|
if process is None:
|
|
287
|
-
return
|
|
307
|
+
return {}
|
|
308
|
+
response_metadata: dict[str, Any] = {}
|
|
288
309
|
try:
|
|
289
310
|
if graceful and reader is not None:
|
|
290
311
|
with contextlib.suppress(BaseException):
|
|
291
312
|
await process.write(_packet({"operation": "shutdown"}))
|
|
292
|
-
await asyncio.wait_for(reader.read(), timeout=10)
|
|
313
|
+
response = await asyncio.wait_for(reader.read(), timeout=10)
|
|
314
|
+
result = response.get("result")
|
|
315
|
+
if response.get("ok") and isinstance(result, dict):
|
|
316
|
+
metadata = result.get("response_metadata")
|
|
317
|
+
if isinstance(metadata, dict):
|
|
318
|
+
response_metadata = metadata
|
|
293
319
|
for timeout, stop in (
|
|
294
320
|
(10 if graceful else 0.1, None),
|
|
295
321
|
(5, process.terminate),
|
|
@@ -309,6 +335,7 @@ class ACPHarnessSession(HarnessSession):
|
|
|
309
335
|
stderr_task.cancel()
|
|
310
336
|
with contextlib.suppress(BaseException):
|
|
311
337
|
await stderr_task
|
|
338
|
+
return response_metadata
|
|
312
339
|
|
|
313
340
|
async def close(self) -> None:
|
|
314
341
|
if self._closed:
|
|
@@ -320,6 +347,10 @@ class ACPHarnessSession(HarnessSession):
|
|
|
320
347
|
|
|
321
348
|
async def close_process() -> None:
|
|
322
349
|
async with self._lock:
|
|
323
|
-
await self._stop(graceful=True)
|
|
350
|
+
response_metadata = await self._stop(graceful=True)
|
|
351
|
+
if response_metadata:
|
|
352
|
+
harness = cast(ACPHarness, self.harness)
|
|
353
|
+
harness._consume_protocol_metadata(self.trace, response_metadata)
|
|
354
|
+
harness.acp_close_result(self.trace, response_metadata)
|
|
324
355
|
|
|
325
356
|
await run_shielded(close_process())
|
verifiers/v1/acp/runner.py
CHANGED
|
@@ -225,7 +225,8 @@ class ACPSession:
|
|
|
225
225
|
self.is_new = False
|
|
226
226
|
return result
|
|
227
227
|
|
|
228
|
-
async def close(self) ->
|
|
228
|
+
async def close(self) -> dict[str, Any]:
|
|
229
|
+
response_metadata: dict[str, Any] = {}
|
|
229
230
|
try:
|
|
230
231
|
if self.connection is not None and self.session_id is not None:
|
|
231
232
|
session_capabilities = (
|
|
@@ -233,12 +234,16 @@ class ACPSession:
|
|
|
233
234
|
)
|
|
234
235
|
if session_capabilities and session_capabilities.close is not None:
|
|
235
236
|
with suppress(Exception):
|
|
236
|
-
await self.connection.close_session(
|
|
237
|
+
response = await self.connection.close_session(
|
|
238
|
+
session_id=self.session_id
|
|
239
|
+
)
|
|
240
|
+
response_metadata = dict(response.field_meta or {})
|
|
237
241
|
finally:
|
|
238
242
|
try:
|
|
239
243
|
await self.stack.aclose()
|
|
240
244
|
finally:
|
|
241
245
|
self._reset()
|
|
246
|
+
return response_metadata
|
|
242
247
|
|
|
243
248
|
|
|
244
249
|
async def read_packet(stream: asyncio.StreamReader) -> dict | None:
|
|
@@ -285,8 +290,10 @@ async def serve_stream() -> None:
|
|
|
285
290
|
}
|
|
286
291
|
elif operation == "shutdown":
|
|
287
292
|
stop = True
|
|
288
|
-
|
|
289
|
-
|
|
293
|
+
response = {
|
|
294
|
+
"ok": True,
|
|
295
|
+
"result": {"response_metadata": await session.close()},
|
|
296
|
+
}
|
|
290
297
|
else:
|
|
291
298
|
raise ValueError(f"unknown ACP session operation: {operation!r}")
|
|
292
299
|
except Exception as error: # noqa: BLE001 - serialize protocol failures
|
verifiers/v1/clients/eval.py
CHANGED
|
@@ -13,41 +13,45 @@ from verifiers.v1.configs.client import BaseClientConfig, resolve_api_key
|
|
|
13
13
|
from verifiers.v1.dialects import Dialect
|
|
14
14
|
from verifiers.v1.errors import model_error
|
|
15
15
|
from verifiers.v1.graph import PendingTurn
|
|
16
|
+
from verifiers.v1.semantic import ACP_EXTENSION_HEADERS
|
|
16
17
|
from verifiers.v1.types import Response, SamplingConfig
|
|
17
18
|
|
|
18
19
|
# These fields describe the localhost request, its original bytes, or its connection. HTTPX
|
|
19
20
|
# rebuilds the provider request from JSON; endpoint configuration and provider auth apply last.
|
|
20
|
-
_BLOCKED_REQUEST_HEADERS =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
21
|
+
_BLOCKED_REQUEST_HEADERS = (
|
|
22
|
+
frozenset(
|
|
23
|
+
{
|
|
24
|
+
# The harness uses this rollout secret to authenticate with the localhost server.
|
|
25
|
+
# The dialect adds the actual provider authorization after filtering.
|
|
26
|
+
"authorization",
|
|
27
|
+
# HTTPX recalculates these for the provider URL, JSON bytes, and supported decoders.
|
|
28
|
+
"accept-encoding",
|
|
29
|
+
"content-encoding",
|
|
30
|
+
"content-length",
|
|
31
|
+
"content-type",
|
|
32
|
+
"host",
|
|
33
|
+
"transfer-encoding",
|
|
34
|
+
# These control only the localhost HTTP exchange.
|
|
35
|
+
"expect",
|
|
36
|
+
"keep-alive",
|
|
37
|
+
"proxy-authorization",
|
|
38
|
+
"proxy-connection",
|
|
39
|
+
"te",
|
|
40
|
+
"trailer",
|
|
41
|
+
"upgrade",
|
|
42
|
+
# Provider affinity must not compete with the rollout-wide session header below.
|
|
43
|
+
"session_id",
|
|
44
|
+
# The eval owns the model and sampling settings, so it changes those JSON fields before
|
|
45
|
+
# sending upstream. Hashes and signatures calculated from the intercepted body are stale.
|
|
46
|
+
"content-digest",
|
|
47
|
+
"content-md5",
|
|
48
|
+
"digest",
|
|
49
|
+
"repr-digest",
|
|
50
|
+
"signature",
|
|
51
|
+
"signature-input",
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
| ACP_EXTENSION_HEADERS
|
|
51
55
|
)
|
|
52
56
|
|
|
53
57
|
|
verifiers/v1/graph.py
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"""Message-graph trajectory: store each message once, recover branches by walking.
|
|
2
2
|
|
|
3
3
|
A rollout is a graph of `MessageNode`s — one per distinct message, each linked to its
|
|
4
|
-
predecessor.
|
|
5
|
-
subagents
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
predecessor. A conversation is a path from a root to a leaf; prompt divergence from
|
|
5
|
+
compaction, subagents, or other history rewrites produces multiple leaves, so branching
|
|
6
|
+
falls out of the walk. A branch often corresponds to one harness context window, but it is
|
|
7
|
+
a physical, exact-prefix training view rather than a semantic context identity: a prefix
|
|
8
|
+
break can split one context and prefix reuse can preserve an ancestral path. Each node
|
|
9
|
+
stores only the tokens it *adds* to the cumulative sequence, keeping size linear in turns
|
|
10
|
+
and making a branch's training sample a cheap concat of node
|
|
11
|
+
`token_ids`/`mask`/`logprobs` along its path.
|
|
9
12
|
|
|
10
13
|
Token attribution (renderer client): the renderer reports, per prompt, each message's token
|
|
11
14
|
span (`RenderedTokens.message_token_spans()`, carried on `TurnTokens.message_spans`). A new
|
|
@@ -29,6 +32,7 @@ from pydantic import BaseModel, ConfigDict, Field, field_serializer, field_valid
|
|
|
29
32
|
from pydantic.json_schema import SkipJsonSchema
|
|
30
33
|
from renderers.base import MultiModalData, PlaceholderRange, RenderedTokens
|
|
31
34
|
|
|
35
|
+
from verifiers.v1.semantic import ParentLink
|
|
32
36
|
from verifiers.v1.types import (
|
|
33
37
|
AssistantMessage,
|
|
34
38
|
KeptTokens,
|
|
@@ -68,6 +72,14 @@ class MessageNode(BaseModel):
|
|
|
68
72
|
|
|
69
73
|
parent: int | None = None
|
|
70
74
|
"""Index into `Trace.nodes` of the predecessor message; None for a root."""
|
|
75
|
+
semantic_parents: list[ParentLink] = Field(default_factory=list)
|
|
76
|
+
"""Additional harness-declared parents in the semantic execution graph.
|
|
77
|
+
|
|
78
|
+
Unlike ``parent``, these links do not imply an exact token prefix and therefore do
|
|
79
|
+
not affect physical branch construction. A list permits multiple parents of the same
|
|
80
|
+
type, supports incremental appends, and preserves their advertised wire order; edge
|
|
81
|
+
application prevents duplicate ``(node, type)`` links.
|
|
82
|
+
"""
|
|
71
83
|
message: Message
|
|
72
84
|
"""The message this node carries (system / user / assistant / tool)."""
|
|
73
85
|
sampled: bool = False
|
|
@@ -312,13 +324,85 @@ def _head_index(trace: Trace) -> dict[tuple[int | None, str], int]:
|
|
|
312
324
|
return trace._head_index
|
|
313
325
|
|
|
314
326
|
|
|
327
|
+
def _matching_node(
|
|
328
|
+
trace: Trace,
|
|
329
|
+
parent: int | None,
|
|
330
|
+
message: Message,
|
|
331
|
+
token_ids: list[int] | None = None,
|
|
332
|
+
) -> int | None:
|
|
333
|
+
"""Find an existing child, optionally requiring its exact physical token span.
|
|
334
|
+
|
|
335
|
+
The head index deliberately points at only the latest content-equivalent child. Token-level
|
|
336
|
+
prefix breaks can leave older physical variants under the same key, so a token mismatch falls
|
|
337
|
+
back to a reverse scan rather than materializing a duplicate of an already-existing variant.
|
|
338
|
+
"""
|
|
339
|
+
key = (parent, message_hash(message))
|
|
340
|
+
indexed = _head_index(trace).get(key)
|
|
341
|
+
if indexed is not None and (
|
|
342
|
+
token_ids is None or trace.nodes[indexed].token_ids == token_ids
|
|
343
|
+
):
|
|
344
|
+
return indexed
|
|
345
|
+
if token_ids is None:
|
|
346
|
+
return indexed
|
|
347
|
+
for node_id in range(len(trace.nodes) - 1, -1, -1):
|
|
348
|
+
if node_id == indexed:
|
|
349
|
+
continue
|
|
350
|
+
node = trace.nodes[node_id]
|
|
351
|
+
if (
|
|
352
|
+
node.parent == parent
|
|
353
|
+
and node.token_ids == token_ids
|
|
354
|
+
and message_hash(node.message) == key[1]
|
|
355
|
+
):
|
|
356
|
+
return node_id
|
|
357
|
+
return None
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def _matching_prefix_node(
|
|
361
|
+
trace: Trace,
|
|
362
|
+
parent: int | None,
|
|
363
|
+
message: Message,
|
|
364
|
+
prompt_ids: list[int],
|
|
365
|
+
start: int,
|
|
366
|
+
stop: int,
|
|
367
|
+
) -> int | None:
|
|
368
|
+
"""Find the longest content-equivalent child matching inside `[start, stop]`.
|
|
369
|
+
|
|
370
|
+
Renderers may leave a prompt-supplied assistant unattributed (`message_spans[i] is None`).
|
|
371
|
+
Its existing sampled node still owns physical tokens, so use those tokens to recover the
|
|
372
|
+
otherwise-missing message boundary. The next attributed message's start bounds the match:
|
|
373
|
+
a sampled variant must never consume tokens that the renderer assigned to that message.
|
|
374
|
+
"""
|
|
375
|
+
key = (parent, message_hash(message))
|
|
376
|
+
indexed = _head_index(trace).get(key)
|
|
377
|
+
candidates: list[int] = []
|
|
378
|
+
if indexed is not None:
|
|
379
|
+
candidates.append(indexed)
|
|
380
|
+
candidates.extend(
|
|
381
|
+
node_id
|
|
382
|
+
for node_id in range(len(trace.nodes) - 1, -1, -1)
|
|
383
|
+
if node_id != indexed
|
|
384
|
+
and trace.nodes[node_id].parent == parent
|
|
385
|
+
and message_hash(trace.nodes[node_id].message) == key[1]
|
|
386
|
+
)
|
|
387
|
+
matches = [
|
|
388
|
+
node_id
|
|
389
|
+
for node_id in candidates
|
|
390
|
+
if start + len(trace.nodes[node_id].token_ids) <= stop
|
|
391
|
+
and prompt_ids[start : start + len(trace.nodes[node_id].token_ids)]
|
|
392
|
+
== trace.nodes[node_id].token_ids
|
|
393
|
+
]
|
|
394
|
+
return max(
|
|
395
|
+
matches, key=lambda node_id: len(trace.nodes[node_id].token_ids), default=None
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
|
|
315
399
|
@dataclass(frozen=True)
|
|
316
400
|
class PendingTurn:
|
|
317
401
|
"""A resolved prompt waiting on model inference.
|
|
318
402
|
|
|
319
|
-
`prepare_turn`
|
|
320
|
-
|
|
321
|
-
inference
|
|
403
|
+
`prepare_turn` resolves the graph prefix used for renderer bridging before inference. `commit`
|
|
404
|
+
preserves that inference-producing prefix, extends it with any matching nodes committed while
|
|
405
|
+
inference was in flight, then adds only the remaining prompt tail and sampled response.
|
|
322
406
|
"""
|
|
323
407
|
|
|
324
408
|
trace: Trace
|
|
@@ -390,6 +474,10 @@ class PendingTurn:
|
|
|
390
474
|
parent = self.prefix_node_ids[-1] if self.prefix_node_ids else None
|
|
391
475
|
index = _head_index(self.trace)
|
|
392
476
|
for message in self.tail:
|
|
477
|
+
existing = _matching_node(self.trace, parent, message)
|
|
478
|
+
if existing is not None:
|
|
479
|
+
parent = existing
|
|
480
|
+
continue
|
|
393
481
|
previous = parent
|
|
394
482
|
self.trace.nodes.append(MessageNode(parent=parent, message=message))
|
|
395
483
|
parent = len(self.trace.nodes) - 1
|
|
@@ -575,6 +663,45 @@ def _commit_turn(turn: PendingTurn, response: Response) -> int:
|
|
|
575
663
|
keep += 1
|
|
576
664
|
prefix = prefix[:keep]
|
|
577
665
|
path_len = off
|
|
666
|
+
|
|
667
|
+
# A parallel request may have committed more of this prompt after `prepare_turn` resolved
|
|
668
|
+
# the inference prefix. Reconcile that still-uncommitted tail now, one whole message at a
|
|
669
|
+
# time. Exact token-span equality preserves intentional renderer-level forks; tokenless relay
|
|
670
|
+
# turns use message identity. Because commit is synchronous, once this loop stops the rest of
|
|
671
|
+
# the tail can be appended without another request interleaving.
|
|
672
|
+
prefix = list(prefix)
|
|
673
|
+
while len(prefix) < len(prompt):
|
|
674
|
+
i = len(prefix)
|
|
675
|
+
span = spans[i] if spans and i < len(spans) else None
|
|
676
|
+
end = span[1] if span else path_len
|
|
677
|
+
parent = prefix[-1] if prefix else None
|
|
678
|
+
if tokens is not None and span is None:
|
|
679
|
+
next_start = next(
|
|
680
|
+
(
|
|
681
|
+
later_span[0]
|
|
682
|
+
for later_span in (spans[i + 1 :] if spans else [])
|
|
683
|
+
if later_span is not None
|
|
684
|
+
),
|
|
685
|
+
len(prompt_ids),
|
|
686
|
+
)
|
|
687
|
+
existing = _matching_prefix_node(
|
|
688
|
+
trace, parent, prompt[i], prompt_ids, path_len, next_start
|
|
689
|
+
)
|
|
690
|
+
if existing is not None:
|
|
691
|
+
end += len(trace.nodes[existing].token_ids)
|
|
692
|
+
else:
|
|
693
|
+
node_tokens = prompt_ids[path_len:end]
|
|
694
|
+
existing = _matching_node(
|
|
695
|
+
trace,
|
|
696
|
+
parent,
|
|
697
|
+
prompt[i],
|
|
698
|
+
node_tokens if tokens is not None else None,
|
|
699
|
+
)
|
|
700
|
+
if existing is None:
|
|
701
|
+
break
|
|
702
|
+
prefix.append(existing)
|
|
703
|
+
path_len = end
|
|
704
|
+
|
|
578
705
|
num_reused = len(prefix)
|
|
579
706
|
parent = prefix[-1] if prefix else None
|
|
580
707
|
# cursor: in prompt_ids, the end of the previous *new* message's tokens
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"""RLM over ACP, with MCP tools exposed as pre-imported IPython skills."""
|
|
2
2
|
|
|
3
|
+
import hashlib
|
|
3
4
|
import logging
|
|
4
5
|
import random
|
|
5
6
|
import shlex
|
|
6
|
-
from typing import Literal
|
|
7
|
+
from typing import Any, Literal
|
|
7
8
|
|
|
8
9
|
from pydantic import BaseModel, ConfigDict, Field, PositiveInt, model_validator
|
|
9
10
|
|
|
@@ -19,8 +20,7 @@ logger = logging.getLogger(__name__)
|
|
|
19
20
|
BuiltinSkill = Literal["edit", "search"]
|
|
20
21
|
|
|
21
22
|
RLM_REPO = "github.com/PrimeIntellect-ai/nano-rlm.git"
|
|
22
|
-
|
|
23
|
-
RLM_BIN = f"{RLM_DIR}/bin/rlm"
|
|
23
|
+
RLM_CACHE_DIR = "/tmp/vf-rlm"
|
|
24
24
|
SKILLS_DIR = "/task/rlm-skills"
|
|
25
25
|
RLM_STATE_DIR = ".vf-rlm"
|
|
26
26
|
RLM_RUNTIME_METADATA_KEY = "ai.prime.rlm/runtime-v1"
|
|
@@ -36,7 +36,7 @@ class _SessionSnapshot(BaseModel):
|
|
|
36
36
|
|
|
37
37
|
class RLMHarnessConfig(HarnessConfig):
|
|
38
38
|
version: str = Field(
|
|
39
|
-
default="
|
|
39
|
+
default="4a6369611c06d3943ac40681f374a464feb706b9", min_length=1
|
|
40
40
|
)
|
|
41
41
|
"""Git ref (branch, tag, or commit) of nano-rlm to install."""
|
|
42
42
|
max_depth: int = 0
|
|
@@ -77,18 +77,26 @@ class RLMHarness(ACPHarness[RLMHarnessConfig]):
|
|
|
77
77
|
async def setup(self, runtime: Runtime) -> None:
|
|
78
78
|
# Before the installer: install.sh packages the skills it finds.
|
|
79
79
|
await self.install_skills(runtime, SKILLS_DIR)
|
|
80
|
+
directory = self._install_dir()
|
|
81
|
+
binary = f"{directory}/bin/rlm"
|
|
82
|
+
checkout = f"{directory}/checkout"
|
|
83
|
+
ready = f"{directory}/.ready"
|
|
80
84
|
# install.sh fetches curl/uv itself; add git only when the image lacks it.
|
|
81
85
|
install = (
|
|
82
|
-
"
|
|
86
|
+
f"rm -f {ready} && "
|
|
87
|
+
"(command -v git >/dev/null 2>&1 || "
|
|
83
88
|
"{ apt-get update -qq && apt-get install -y -qq git; } && "
|
|
84
|
-
f"rm -rf
|
|
85
|
-
f"git -C
|
|
86
|
-
f"UV_INSTALL_DIR={
|
|
87
|
-
f"RLM_CHECKOUT_PATH
|
|
89
|
+
f"rm -rf {checkout} && git clone https://{RLM_REPO} {checkout} && "
|
|
90
|
+
f"git -C {checkout} checkout {shlex.quote(self.config.version)} && "
|
|
91
|
+
f"UV_INSTALL_DIR={directory}/bin UV_TOOL_BIN_DIR={directory}/bin "
|
|
92
|
+
f"RLM_CHECKOUT_PATH={checkout} bash {checkout}/install.sh && "
|
|
93
|
+
f"touch {ready})"
|
|
88
94
|
)
|
|
89
95
|
logger.info("rlm: ensuring rlm is installed (version=%s)", self.config.version)
|
|
90
|
-
ensure = shlex.quote(f"[ -x {
|
|
91
|
-
guarded =
|
|
96
|
+
ensure = shlex.quote(f"[ -f {ready} ] && [ -x {binary} ] || ({install})")
|
|
97
|
+
guarded = (
|
|
98
|
+
f"mkdir -p {directory} && flock {directory}/install.lock sh -c {ensure}"
|
|
99
|
+
)
|
|
92
100
|
env = self.config.resolved_env.copy()
|
|
93
101
|
extra_uv_args = env.get("RLM_EXTRA_UV_ARGS", "")
|
|
94
102
|
env["RLM_EXTRA_UV_ARGS"] = f"{extra_uv_args} --with mcp~=1.28".strip()
|
|
@@ -150,24 +158,35 @@ class RLMHarness(ACPHarness[RLMHarnessConfig]):
|
|
|
150
158
|
system_prompt, prompt = self.resolve_prompt(data)
|
|
151
159
|
return ACPConfig(
|
|
152
160
|
env={**self.config.resolved_env, "RLM_HOME": self._home(trace)},
|
|
153
|
-
command=[
|
|
161
|
+
command=[f"{self._install_dir()}/bin/rlm", "--acp"],
|
|
154
162
|
prompt=prompt,
|
|
155
163
|
session_meta=self._runtime_metadata(
|
|
156
164
|
ctx, trace, runtime, endpoint, secret, data, system_prompt
|
|
157
165
|
),
|
|
158
166
|
)
|
|
159
167
|
|
|
160
|
-
def
|
|
168
|
+
def _consume_snapshot(self, trace: Trace, metadata: dict[str, Any]) -> None:
|
|
161
169
|
snapshot = _SessionSnapshot.model_validate(
|
|
162
|
-
|
|
170
|
+
metadata.get(RLM_SESSION_METADATA_KEY)
|
|
163
171
|
)
|
|
164
172
|
if snapshot.session_id != trace.id:
|
|
165
173
|
raise ValueError("RLM session snapshot does not match the rollout")
|
|
166
174
|
trace.record_metrics(snapshot.metrics)
|
|
167
175
|
|
|
176
|
+
def acp_turn_result(self, trace: Trace, result: ACPTurn) -> None:
|
|
177
|
+
self._consume_snapshot(trace, result.response_metadata)
|
|
178
|
+
|
|
179
|
+
def acp_close_result(self, trace: Trace, response_metadata: dict[str, Any]) -> None:
|
|
180
|
+
if RLM_SESSION_METADATA_KEY in response_metadata:
|
|
181
|
+
self._consume_snapshot(trace, response_metadata)
|
|
182
|
+
|
|
168
183
|
async def cleanup(self, trace: Trace, runtime: Runtime) -> None:
|
|
169
184
|
await runtime.run(["rm", "-rf", f"{RLM_STATE_DIR}/{trace.id}"], {})
|
|
170
185
|
|
|
171
186
|
@staticmethod
|
|
172
187
|
def _home(trace: Trace) -> str:
|
|
173
188
|
return f"{RLM_STATE_DIR}/{trace.id}/home"
|
|
189
|
+
|
|
190
|
+
def _install_dir(self) -> str:
|
|
191
|
+
cache_key = hashlib.sha256(self.config.version.encode()).hexdigest()
|
|
192
|
+
return f"{RLM_CACHE_DIR}-{cache_key}"
|
|
@@ -58,6 +58,7 @@ from verifiers.v1.interception.tunnel import (
|
|
|
58
58
|
TunnelConfig,
|
|
59
59
|
make_tunnel,
|
|
60
60
|
)
|
|
61
|
+
from verifiers.v1.semantic import ACPInfo, extract_acp_info
|
|
61
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
|
|
@@ -421,6 +422,7 @@ class InterceptionServer(Interception):
|
|
|
421
422
|
usage: "Usage | None" = None,
|
|
422
423
|
error: BaseException | None = None,
|
|
423
424
|
policy_paths: list[str] | None = None,
|
|
425
|
+
acp: ACPInfo | None = None,
|
|
424
426
|
) -> None:
|
|
425
427
|
"""Append one provider exchange to the trace's per-call records (`Trace.calls`):
|
|
426
428
|
the model + effective settings that went upstream, timing, and — when the call
|
|
@@ -468,6 +470,7 @@ class InterceptionServer(Interception):
|
|
|
468
470
|
)
|
|
469
471
|
if policy_paths
|
|
470
472
|
else None,
|
|
473
|
+
acp=acp,
|
|
471
474
|
)
|
|
472
475
|
)
|
|
473
476
|
|
|
@@ -491,7 +494,10 @@ class InterceptionServer(Interception):
|
|
|
491
494
|
del raw
|
|
492
495
|
body = dialect.apply_overrides(body, session.ctx.model, session.ctx.sampling)
|
|
493
496
|
streaming = dialect.streaming(body)
|
|
494
|
-
|
|
497
|
+
try:
|
|
498
|
+
acp, upstream_headers = extract_acp_info(request.headers)
|
|
499
|
+
except ValueError as error:
|
|
500
|
+
return web.json_response(dialect.error_body(str(error)), status=400)
|
|
495
501
|
logger.debug(
|
|
496
502
|
"intercept %s: id=%s stream=%s",
|
|
497
503
|
request.path,
|
|
@@ -508,14 +514,18 @@ class InterceptionServer(Interception):
|
|
|
508
514
|
replay_key: str | None = None
|
|
509
515
|
binding = (request.path, req_hash)
|
|
510
516
|
if idempotency_key:
|
|
511
|
-
if streaming:
|
|
517
|
+
if streaming and acp is None:
|
|
512
518
|
return web.json_response(
|
|
513
519
|
dialect.error_body(
|
|
514
520
|
"Idempotency-Key is not supported for streaming requests"
|
|
515
521
|
),
|
|
516
522
|
status=400,
|
|
517
523
|
)
|
|
518
|
-
|
|
524
|
+
if not streaming:
|
|
525
|
+
replay_key = f"explicit:{idempotency_key}"
|
|
526
|
+
# This key identifies the harness-to-interception hop. The server owns its
|
|
527
|
+
# replay semantics, and the body has since been rewritten with rollout model
|
|
528
|
+
# and sampling overrides, so never expose the local key to the provider.
|
|
519
529
|
upstream_headers = {
|
|
520
530
|
name: value
|
|
521
531
|
for name, value in upstream_headers.items()
|
|
@@ -643,6 +653,8 @@ class InterceptionServer(Interception):
|
|
|
643
653
|
turn=turn,
|
|
644
654
|
inspect_response=inspect_response,
|
|
645
655
|
policy_paths=policy_paths,
|
|
656
|
+
acp=acp,
|
|
657
|
+
upstream_headers=upstream_headers,
|
|
646
658
|
)
|
|
647
659
|
|
|
648
660
|
def serve(response: Response) -> web.Response:
|
|
@@ -757,6 +769,7 @@ class InterceptionServer(Interception):
|
|
|
757
769
|
usage=call_response.usage if call_response else None,
|
|
758
770
|
error=error,
|
|
759
771
|
policy_paths=policy_paths,
|
|
772
|
+
acp=acp,
|
|
760
773
|
)
|
|
761
774
|
return serve(call_response)
|
|
762
775
|
|
|
@@ -773,6 +786,8 @@ class InterceptionServer(Interception):
|
|
|
773
786
|
turn: graph.PendingTurn,
|
|
774
787
|
inspect_response: bool,
|
|
775
788
|
policy_paths: list[str] | None = None,
|
|
789
|
+
acp: ACPInfo | None = None,
|
|
790
|
+
upstream_headers: Mapping[str, str] | None = None,
|
|
776
791
|
) -> web.StreamResponse:
|
|
777
792
|
"""A streamed (SSE) model turn: relay the provider's stream through to the program,
|
|
778
793
|
incrementally assembling the response to record on the trace (the only client that
|
|
@@ -788,7 +803,7 @@ class InterceptionServer(Interception):
|
|
|
788
803
|
reply = await session.client.relay(
|
|
789
804
|
dialect,
|
|
790
805
|
body,
|
|
791
|
-
headers=
|
|
806
|
+
headers=upstream_headers,
|
|
792
807
|
session_id=session.trace.id,
|
|
793
808
|
)
|
|
794
809
|
except RolloutError as e:
|
|
@@ -1017,6 +1032,7 @@ class InterceptionServer(Interception):
|
|
|
1017
1032
|
usage=response.usage if response is not None else None,
|
|
1018
1033
|
error=error,
|
|
1019
1034
|
policy_paths=policy_paths,
|
|
1035
|
+
acp=acp,
|
|
1020
1036
|
)
|
|
1021
1037
|
|
|
1022
1038
|
async def handle_aux(
|
verifiers/v1/semantic.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""ACP semantic edges carried beside the physical training-message graph."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from collections.abc import Mapping
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
9
|
+
|
|
10
|
+
ACP_REQUEST_ID_PATTERN = r"^[A-Za-z0-9._:-]{1,128}$"
|
|
11
|
+
EDGE_TYPE_PATTERN = r"^[A-Za-z][A-Za-z0-9._:-]{0,127}$"
|
|
12
|
+
"""Semantic label syntax, for example ``subagent_return`` or ``vendor:review``."""
|
|
13
|
+
|
|
14
|
+
ACP_SEMANTIC_EDGES_METADATA_KEY = "ai.prime.acp/semantic-edges-v1"
|
|
15
|
+
ACP_MODEL_REQUEST_ID_HEADER = "X-ACP-Model-Request-ID"
|
|
16
|
+
|
|
17
|
+
ACP_EXTENSION_HEADERS = frozenset({ACP_MODEL_REQUEST_ID_HEADER.lower()})
|
|
18
|
+
"""Private ACP extension headers consumed at interception and never sent upstream."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ACPInfo(BaseModel):
|
|
22
|
+
"""Metadata advertised by an ACP harness for one intercepted model request."""
|
|
23
|
+
|
|
24
|
+
model_config = ConfigDict(extra="forbid", strict=True)
|
|
25
|
+
|
|
26
|
+
request_id: str = Field(pattern=ACP_REQUEST_ID_PATTERN)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class SemanticEdge(BaseModel):
|
|
30
|
+
"""A harness-declared relationship between two logical model requests.
|
|
31
|
+
|
|
32
|
+
Request IDs are wire-level correlation handles. They let a harness describe the
|
|
33
|
+
relationship before it can know Verifiers-local message-node indexes.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
model_config = ConfigDict(extra="forbid", strict=True)
|
|
37
|
+
|
|
38
|
+
source_request_id: str = Field(pattern=ACP_REQUEST_ID_PATTERN)
|
|
39
|
+
target_request_id: str = Field(pattern=ACP_REQUEST_ID_PATTERN)
|
|
40
|
+
type: str = Field(pattern=EDGE_TYPE_PATTERN)
|
|
41
|
+
|
|
42
|
+
@model_validator(mode="after")
|
|
43
|
+
def reject_self_edge(self) -> SemanticEdge:
|
|
44
|
+
if self.source_request_id == self.target_request_id:
|
|
45
|
+
raise ValueError("semantic edge cannot link a request to itself")
|
|
46
|
+
return self
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ParentLink(BaseModel):
|
|
50
|
+
"""One semantic parent of a ``MessageNode``.
|
|
51
|
+
|
|
52
|
+
``node`` is an index into the containing ``Trace.nodes``. The child is the
|
|
53
|
+
``MessageNode`` carrying this link.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
model_config = ConfigDict(extra="forbid", strict=True)
|
|
57
|
+
|
|
58
|
+
node: int = Field(ge=0)
|
|
59
|
+
type: str = Field(pattern=EDGE_TYPE_PATTERN)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class SemanticEdgeSet(BaseModel):
|
|
63
|
+
"""A harness-published set of semantic edges over logical request IDs.
|
|
64
|
+
|
|
65
|
+
Edge labels are intentionally extensible. Initial harnesses use ``continuation``,
|
|
66
|
+
``compaction``, ``subagent_call``, and ``subagent_return``; consumers must preserve
|
|
67
|
+
unknown labels.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
model_config = ConfigDict(extra="forbid", strict=True)
|
|
71
|
+
|
|
72
|
+
edges: list[SemanticEdge]
|
|
73
|
+
|
|
74
|
+
@model_validator(mode="after")
|
|
75
|
+
def validate_edges(self) -> SemanticEdgeSet:
|
|
76
|
+
identities: set[tuple[str, str, str]] = set()
|
|
77
|
+
children: dict[str, list[str]] = {}
|
|
78
|
+
nodes: set[str] = set()
|
|
79
|
+
for edge in self.edges:
|
|
80
|
+
identity = (
|
|
81
|
+
edge.source_request_id,
|
|
82
|
+
edge.target_request_id,
|
|
83
|
+
edge.type,
|
|
84
|
+
)
|
|
85
|
+
if identity in identities:
|
|
86
|
+
raise ValueError(f"duplicate semantic edge: {identity!r}")
|
|
87
|
+
identities.add(identity)
|
|
88
|
+
children.setdefault(edge.source_request_id, []).append(
|
|
89
|
+
edge.target_request_id
|
|
90
|
+
)
|
|
91
|
+
nodes.update((edge.source_request_id, edge.target_request_id))
|
|
92
|
+
|
|
93
|
+
indegree = dict.fromkeys(nodes, 0)
|
|
94
|
+
for targets in children.values():
|
|
95
|
+
for target in targets:
|
|
96
|
+
indegree[target] += 1
|
|
97
|
+
|
|
98
|
+
stack = [node for node, degree in indegree.items() if degree == 0]
|
|
99
|
+
visited = 0
|
|
100
|
+
while stack:
|
|
101
|
+
node = stack.pop()
|
|
102
|
+
visited += 1
|
|
103
|
+
for child in children.get(node, ()):
|
|
104
|
+
indegree[child] -= 1
|
|
105
|
+
if indegree[child] == 0:
|
|
106
|
+
stack.append(child)
|
|
107
|
+
if visited != len(nodes):
|
|
108
|
+
raise ValueError("semantic edge cycle detected")
|
|
109
|
+
return self
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def extract_acp_info(
|
|
113
|
+
headers: Mapping[str, str],
|
|
114
|
+
) -> tuple[ACPInfo | None, dict[str, str]]:
|
|
115
|
+
"""Parse ACP request metadata and remove its private transport header.
|
|
116
|
+
|
|
117
|
+
The semantic edge set arrives independently in ACP metadata. Ordinary requests
|
|
118
|
+
without the private correlation header remain unchanged.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
forwarded = {
|
|
122
|
+
name: value
|
|
123
|
+
for name, value in headers.items()
|
|
124
|
+
if name.lower() not in ACP_EXTENSION_HEADERS
|
|
125
|
+
}
|
|
126
|
+
normalized = {name.lower(): value for name, value in headers.items()}
|
|
127
|
+
request_id = normalized.get(ACP_MODEL_REQUEST_ID_HEADER.lower())
|
|
128
|
+
if request_id is None:
|
|
129
|
+
return None, forwarded
|
|
130
|
+
if re.fullmatch(ACP_REQUEST_ID_PATTERN, request_id) is None:
|
|
131
|
+
raise ValueError(f"{ACP_MODEL_REQUEST_ID_HEADER} is not a valid ACP request ID")
|
|
132
|
+
return ACPInfo(request_id=request_id), forwarded
|
verifiers/v1/trace.py
CHANGED
|
@@ -19,6 +19,11 @@ from verifiers.v1.configs.agent import AgentConfig, WireAgentConfig
|
|
|
19
19
|
from verifiers.v1.errors import ProviderError
|
|
20
20
|
from verifiers.v1.graph import MessageNode
|
|
21
21
|
from verifiers.v1.runtimes import RuntimeInfo
|
|
22
|
+
from verifiers.v1.semantic import (
|
|
23
|
+
ACPInfo,
|
|
24
|
+
ParentLink,
|
|
25
|
+
SemanticEdgeSet,
|
|
26
|
+
)
|
|
22
27
|
from verifiers.v1.state import State, StateT
|
|
23
28
|
from verifiers.v1.task import DataT, WireTaskData
|
|
24
29
|
from verifiers.v1.types import (
|
|
@@ -171,6 +176,8 @@ class ModelCall(BaseModel):
|
|
|
171
176
|
"""The failure that ended this call, coupled to the exchange that caused it."""
|
|
172
177
|
policy: PolicyEvent | None = None
|
|
173
178
|
"""Policy mediation applied to the request before this call."""
|
|
179
|
+
acp: ACPInfo | None = None
|
|
180
|
+
"""Metadata advertised by the ACP harness for this model request."""
|
|
174
181
|
|
|
175
182
|
|
|
176
183
|
def min_new_input_tokens(calls: Iterable[ModelCall]) -> Iterator[tuple[ModelCall, int]]:
|
|
@@ -188,7 +195,7 @@ def min_new_input_tokens(calls: Iterable[ModelCall]) -> Iterator[tuple[ModelCall
|
|
|
188
195
|
|
|
189
196
|
|
|
190
197
|
class Branch(BaseModel):
|
|
191
|
-
"""A root-to-leaf graph path; each branch becomes one training sample."""
|
|
198
|
+
"""A root-to-leaf message-graph path; each branch becomes one training sample."""
|
|
192
199
|
|
|
193
200
|
index: int
|
|
194
201
|
nodes: list[MessageNode]
|
|
@@ -387,7 +394,7 @@ class Trace(BaseModel, Generic[DataT, StateT, AgentConfigT]):
|
|
|
387
394
|
"""The tools advertised to the agent, automatically recorded from last intercepted turn."""
|
|
388
395
|
|
|
389
396
|
nodes: list[MessageNode] = Field(default_factory=list)
|
|
390
|
-
"""The message graph
|
|
397
|
+
"""The message graph, including physical and semantic parent links."""
|
|
391
398
|
calls: list[ModelCall] = Field(default_factory=list)
|
|
392
399
|
"""Every model call; automatically recorded at intercept time + linked into `nodes`."""
|
|
393
400
|
mm_token_type_id_map: dict[int, int] = Field(default_factory=dict)
|
|
@@ -493,6 +500,72 @@ class Trace(BaseModel, Generic[DataT, StateT, AgentConfigT]):
|
|
|
493
500
|
)
|
|
494
501
|
return branches
|
|
495
502
|
|
|
503
|
+
def add_semantic_edges(self, edge_set: SemanticEdgeSet) -> None:
|
|
504
|
+
"""Add newly advertised ACP edges; cumulative replays are idempotent."""
|
|
505
|
+
node_by_request: dict[str, int] = {}
|
|
506
|
+
for call in self.calls:
|
|
507
|
+
if call.acp is None or call.node is None:
|
|
508
|
+
continue
|
|
509
|
+
if not 0 <= call.node < len(self.nodes):
|
|
510
|
+
raise ValueError(f"model call has invalid message node {call.node}")
|
|
511
|
+
if not self.nodes[call.node].sampled:
|
|
512
|
+
raise ValueError(f"model call node {call.node} is not sampled")
|
|
513
|
+
# SDK retries are sequential. If more than one attempt commits, the last
|
|
514
|
+
# sampled response is the logical request result consumed by the harness.
|
|
515
|
+
node_by_request[call.acp.request_id] = call.node
|
|
516
|
+
|
|
517
|
+
resolved_identities: set[tuple[int, int, str]] = set()
|
|
518
|
+
additions: list[tuple[int, ParentLink]] = []
|
|
519
|
+
pending_parents: dict[int, list[ParentLink]] = {}
|
|
520
|
+
for edge in edge_set.edges:
|
|
521
|
+
endpoints: list[int] = []
|
|
522
|
+
for request_id in (
|
|
523
|
+
edge.source_request_id,
|
|
524
|
+
edge.target_request_id,
|
|
525
|
+
):
|
|
526
|
+
node = node_by_request.get(request_id)
|
|
527
|
+
if node is None:
|
|
528
|
+
raise ValueError(
|
|
529
|
+
f"semantic edge request {request_id!r} has no committed message node"
|
|
530
|
+
)
|
|
531
|
+
endpoints.append(node)
|
|
532
|
+
source, target = endpoints
|
|
533
|
+
if source == target:
|
|
534
|
+
raise ValueError("semantic edge resolves to the same message node")
|
|
535
|
+
identity = (source, target, edge.type)
|
|
536
|
+
if identity in resolved_identities:
|
|
537
|
+
raise ValueError(f"duplicate resolved semantic edge: {identity!r}")
|
|
538
|
+
resolved_identities.add(identity)
|
|
539
|
+
link = ParentLink(node=source, type=edge.type)
|
|
540
|
+
if link in self.nodes[target].semantic_parents:
|
|
541
|
+
continue
|
|
542
|
+
|
|
543
|
+
# Adding source -> target creates a cycle exactly when target is already an
|
|
544
|
+
# ancestor of source. Walk parent links directly so existing nodes and links
|
|
545
|
+
# are never rebuilt as cumulative ACP edge sets arrive.
|
|
546
|
+
stack = [source]
|
|
547
|
+
visited: set[int] = set()
|
|
548
|
+
while stack:
|
|
549
|
+
node_id = stack.pop()
|
|
550
|
+
if node_id == target:
|
|
551
|
+
raise ValueError(
|
|
552
|
+
"semantic edges create a cycle in the message graph"
|
|
553
|
+
)
|
|
554
|
+
if node_id in visited:
|
|
555
|
+
continue
|
|
556
|
+
visited.add(node_id)
|
|
557
|
+
node = self.nodes[node_id]
|
|
558
|
+
if node.parent is not None:
|
|
559
|
+
stack.append(node.parent)
|
|
560
|
+
stack.extend(parent.node for parent in node.semantic_parents)
|
|
561
|
+
stack.extend(parent.node for parent in pending_parents.get(node_id, ()))
|
|
562
|
+
|
|
563
|
+
additions.append((target, link))
|
|
564
|
+
pending_parents.setdefault(target, []).append(link)
|
|
565
|
+
|
|
566
|
+
for target, link in additions:
|
|
567
|
+
self.nodes[target].semantic_parents.append(link)
|
|
568
|
+
|
|
496
569
|
@property
|
|
497
570
|
def messages(self) -> Messages:
|
|
498
571
|
"""Messages on the final branch."""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: verifiers
|
|
3
|
-
Version: 0.3.2.
|
|
3
|
+
Version: 0.3.2.dev25
|
|
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
|
|
@@ -21,7 +21,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
21
21
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
22
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
23
|
Requires-Python: <3.14,>=3.11
|
|
24
|
-
Requires-Dist: aiohttp>=3.14.
|
|
24
|
+
Requires-Dist: aiohttp>=3.14.1
|
|
25
25
|
Requires-Dist: anthropic>=0.78.0
|
|
26
26
|
Requires-Dist: datasets<6.0.0,>=3.3.0
|
|
27
27
|
Requires-Dist: gepa>=0.0.6
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
verifiers/__init__.py,sha256=yDYsckVQbUkwoh9mU_hBeCLGvS_aWgAxuoNm5LxQpDI,517
|
|
2
|
-
verifiers/v1/__init__.py,sha256=
|
|
2
|
+
verifiers/v1/__init__.py,sha256=AYjjpOBfpSlWZRN51V1KaxMYMBWSZhBEIOzvNk23pxg,8348
|
|
3
3
|
verifiers/v1/agent.py,sha256=AfjyYmcGpVaOlZkElIz1JZeNRQuZsE_KMZ-LV3uLvzA,31644
|
|
4
4
|
verifiers/v1/env.py,sha256=CEhzjojhg5jqbOYruUnc5U7TtgDHDSx8NiiFA0qfbt8,18234
|
|
5
5
|
verifiers/v1/episode.py,sha256=uStvI4WqgJT50hmHIB55m5B-ASqqLz-fZ-ynBz9uzEY,5474
|
|
6
6
|
verifiers/v1/errors.py,sha256=uQySmCUrjDYFkBIii1vBFPiEcPFPQZ9EGpas_6HvcQI,5279
|
|
7
|
-
verifiers/v1/graph.py,sha256=
|
|
7
|
+
verifiers/v1/graph.py,sha256=09uysIuX7kHCt9XRndpACkQtWocgVbtiLewcEmnzmD4,35787
|
|
8
8
|
verifiers/v1/harness.py,sha256=ziECqEBWV34UWbLlxrkhY6MwkbVYkoXBOoaY7mZxwTs,14753
|
|
9
9
|
verifiers/v1/judge.py,sha256=Pvr0C41ah1qkNSZ0WXdkDvBMfv5YSfY1REHncwlJ8cg,9346
|
|
10
10
|
verifiers/v1/rollout.py,sha256=EnF3RuBfMyKNjJIs0LZaImkSvfe9LYLXc8dYP-1a2Ew,23628
|
|
11
|
+
verifiers/v1/semantic.py,sha256=wssvBSEpY_tgzpFUADG9-N4HkDXgCZvNQ1pdf6qAsS0,4680
|
|
11
12
|
verifiers/v1/session.py,sha256=xM7JJJVJACk0JfH9RAN1Ts8gJJKr2tGGRiIgQTrdieY,18692
|
|
12
13
|
verifiers/v1/state.py,sha256=EckF2bWp-vV4b1jYJ9sLI5xrfGuI5spIgYYwW926toI,595
|
|
13
14
|
verifiers/v1/task.py,sha256=vaVkBu00riiNU1Ke4NeeY2NQTXxOguz9d6NLe55hO_Q,11468
|
|
14
15
|
verifiers/v1/taskset.py,sha256=fp2E0IEhL_Ybj9cegZwljfTmW27p_30zTWHFKw_kXE4,4374
|
|
15
|
-
verifiers/v1/trace.py,sha256=
|
|
16
|
+
verifiers/v1/trace.py,sha256=ABAr9hxpLiAwVOb4h6djAom9DJbOy4BuDqvx0wJDUDY,28439
|
|
16
17
|
verifiers/v1/types.py,sha256=a1wqL8T7KQg9WxkaDIZpmOyU6xT2VeSr1K4SWiW8ef4,9660
|
|
17
|
-
verifiers/v1/acp/__init__.py,sha256=
|
|
18
|
-
verifiers/v1/acp/runner.py,sha256=
|
|
18
|
+
verifiers/v1/acp/__init__.py,sha256=wUPZVYBFjJuOnIIoYONBFuA04A1DJf_dOyKY3QwK37Q,12722
|
|
19
|
+
verifiers/v1/acp/runner.py,sha256=gMXFmsVg2qD0Zhrx7kvC6Me2Z-wsfBamRIO0i45UW8g,11097
|
|
19
20
|
verifiers/v1/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
21
|
verifiers/v1/cli/debug.py,sha256=x3bqOwwbwwfwQQpxHrZeKdxsW3ZVtUT9cAn_r4aOro4,11631
|
|
21
22
|
verifiers/v1/cli/gepa.py,sha256=7YpppEMeuY2m1X5szGkybzTHztnIs83CvnSizhiEC-w,4210
|
|
@@ -37,7 +38,7 @@ verifiers/v1/cli/eval/runner.py,sha256=tZDPWzd6U7-5N43HGRlV7p-RnUiDleYwMUBVHzWH7
|
|
|
37
38
|
verifiers/v1/clients/__init__.py,sha256=Ysig0tE_0E4Jsfgfes1XHN-fK1s_RCXdqZD6E7lK4PU,507
|
|
38
39
|
verifiers/v1/clients/base.py,sha256=PoDw4GMqrfuPTFVK6n2jDmlD0_lJ5zTrYcNio5yq6K8,1691
|
|
39
40
|
verifiers/v1/clients/client.py,sha256=zqC_AkiD9pl0kxxIbupNiehbS-YnVdp3EMZ0LOHTd8U,3125
|
|
40
|
-
verifiers/v1/clients/eval.py,sha256
|
|
41
|
+
verifiers/v1/clients/eval.py,sha256=cJucyUFsbF1JlG8nF0Tlw2EBMSoAF0YMklgYiOSoNpg,8322
|
|
41
42
|
verifiers/v1/clients/train.py,sha256=ZNbEU8WPZ6xI1hho7MiIjleZOswt2lOUGkIUQqpe8gM,18803
|
|
42
43
|
verifiers/v1/configs/__init__.py,sha256=X7u6X7B3ieD1HZl79Tv1kg-yPHbT0QLvAebaGqxVtvA,317
|
|
43
44
|
verifiers/v1/configs/agent.py,sha256=L5P6ombAi4U5wwsspMHAuM8111sB9AVdm8q6B5iV1lw,3251
|
|
@@ -111,14 +112,14 @@ verifiers/v1/harnesses/pool/harness.py,sha256=HKAogPbyLK5QpvPQ1teHOh_IyRQX-or2JF
|
|
|
111
112
|
verifiers/v1/harnesses/prime_agent/__init__.py,sha256=xfPC4RrlnyYWaf38tPAOZq4YL6M55lMpj5BoRLmaK8I,171
|
|
112
113
|
verifiers/v1/harnesses/prime_agent/harness.py,sha256=byplbbIOFACCn2BvVZAxBSHdaPKBGERYz_hA1rgBj0E,11205
|
|
113
114
|
verifiers/v1/harnesses/rlm/__init__.py,sha256=hwx51xTdEWzzYgMj-p4ETNcptoub3IPMDbEdJ4uB8Ns,122
|
|
114
|
-
verifiers/v1/harnesses/rlm/harness.py,sha256=
|
|
115
|
+
verifiers/v1/harnesses/rlm/harness.py,sha256=OpbPCObGg9BQnNw9njI5iLELRGwoMySMrsE9WbhFWHA,7666
|
|
115
116
|
verifiers/v1/harnesses/terminus_2/__init__.py,sha256=l1pwfg1HyVDEqT9efdnFWcXqaZwtKwe7TrplkyxZSA0,166
|
|
116
117
|
verifiers/v1/harnesses/terminus_2/harness.py,sha256=kXKhi-aqqsoXGnvet0Tq_v7LYYpRYEzARyQL2MTEGWs,3101
|
|
117
118
|
verifiers/v1/harnesses/terminus_2/program.py,sha256=X8MZdyItU3gbXGXnGOlJ9LWcUTnqIDaxlhkZvoRiqKY,2703
|
|
118
119
|
verifiers/v1/interception/__init__.py,sha256=5Kvo7tcBUVaa65s9A1NiOH3CPpzw-P5btXwxB4Nbbvs,4251
|
|
119
120
|
verifiers/v1/interception/base.py,sha256=Mg16Y104lyZilF9shdivdqYoqz4OYp978i_myyrulu8,2529
|
|
120
121
|
verifiers/v1/interception/pool.py,sha256=sk_zcdTV8EVRuzqlYMXxon_42tSDAlFvwcyOO2EF7hw,6473
|
|
121
|
-
verifiers/v1/interception/server.py,sha256=
|
|
122
|
+
verifiers/v1/interception/server.py,sha256=7n8MCDs2wP3ZxNmUuGLcw7MU4SPiHcpq-qhmHnCP1R8,50129
|
|
122
123
|
verifiers/v1/interception/tool.py,sha256=ZyZPxLYM_HsGkz-ZbCREQVGtiKZK9lQLChBNF_bBuuc,259
|
|
123
124
|
verifiers/v1/interception/tunnel/__init__.py,sha256=eVNZJszj6myrKhx9jmJz7VRd9qlfj0AUvUZwI2bXEj8,893
|
|
124
125
|
verifiers/v1/interception/tunnel/base.py,sha256=DZB6uPLwM4Qy7n7m0vKeyg-Px87MhsmpYTpe2vpPEng,1998
|
|
@@ -183,8 +184,8 @@ verifiers/v1/utils/prime.py,sha256=UTYRjp9cbjNb6CVmBHda-1wWZAIIfxNOmTyNuT7_wL4,9
|
|
|
183
184
|
verifiers/v1/utils/retries.py,sha256=Y2ZgrAjn-qNkRKZP_RVNL_7EK0iaRcZeCa404lpGYi4,5417
|
|
184
185
|
verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
|
|
185
186
|
verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
|
|
186
|
-
verifiers-0.3.2.
|
|
187
|
-
verifiers-0.3.2.
|
|
188
|
-
verifiers-0.3.2.
|
|
189
|
-
verifiers-0.3.2.
|
|
190
|
-
verifiers-0.3.2.
|
|
187
|
+
verifiers-0.3.2.dev25.dist-info/METADATA,sha256=yA1Vt6lq7xX48fj30Kp60fUgWwV1eGWS-BMhVIvTI6Y,4144
|
|
188
|
+
verifiers-0.3.2.dev25.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
189
|
+
verifiers-0.3.2.dev25.dist-info/entry_points.txt,sha256=uqQje0TMsr7k6nXlWxlPs13Si0evb3pVCEDF6c-YL80,241
|
|
190
|
+
verifiers-0.3.2.dev25.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
|
|
191
|
+
verifiers-0.3.2.dev25.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|