verifiers 0.4.2.dev55__py3-none-any.whl → 0.4.2.dev57__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 +11 -1
- verifiers/v1/agent.py +25 -6
- verifiers/v1/clients/__init__.py +9 -1
- verifiers/v1/clients/client.py +95 -1
- verifiers/v1/interception/__init__.py +10 -8
- verifiers/v1/interception/server.py +13 -7
- verifiers/v1/mcp/launch.py +69 -125
- verifiers/v1/mcp/toolset.py +18 -4
- verifiers/v1/rollout.py +5 -5
- verifiers/v1/runtimes/private_network.py +4 -2
- verifiers/v1/session.py +21 -6
- verifiers/v1/tasksets/harbor/taskset.py +2 -2
- verifiers/v1/tasksets/harbor/toolset.py +17 -5
- {verifiers-0.4.2.dev55.dist-info → verifiers-0.4.2.dev57.dist-info}/METADATA +1 -1
- {verifiers-0.4.2.dev55.dist-info → verifiers-0.4.2.dev57.dist-info}/RECORD +18 -18
- {verifiers-0.4.2.dev55.dist-info → verifiers-0.4.2.dev57.dist-info}/WHEEL +0 -0
- {verifiers-0.4.2.dev55.dist-info → verifiers-0.4.2.dev57.dist-info}/entry_points.txt +0 -0
- {verifiers-0.4.2.dev55.dist-info → verifiers-0.4.2.dev57.dist-info}/licenses/LICENSE +0 -0
verifiers/v1/__init__.py
CHANGED
|
@@ -14,7 +14,13 @@ if TYPE_CHECKING:
|
|
|
14
14
|
|
|
15
15
|
from verifiers.v1.acp import ACPConfig, ACPHarness, ACPTurn
|
|
16
16
|
from verifiers.v1.agent import Agent, Agents, Interaction, Segment, make_agent
|
|
17
|
-
from verifiers.v1.clients import
|
|
17
|
+
from verifiers.v1.clients import (
|
|
18
|
+
Client,
|
|
19
|
+
ModelContext,
|
|
20
|
+
ModelRoute,
|
|
21
|
+
RouteRejected,
|
|
22
|
+
resolve_client,
|
|
23
|
+
)
|
|
18
24
|
from verifiers.v1.configs.agent import AgentConfig
|
|
19
25
|
from verifiers.v1.configs.cli.env import narrowed_env_annotation, resolve_env_field
|
|
20
26
|
from verifiers.v1.configs.client import (
|
|
@@ -253,6 +259,8 @@ _NAME_TO_MODULE = {
|
|
|
253
259
|
"Messages": "verifiers.v1.types",
|
|
254
260
|
"ModelCall": "verifiers.v1.trace",
|
|
255
261
|
"ModelContext": "verifiers.v1.clients",
|
|
262
|
+
"ModelRoute": "verifiers.v1.clients",
|
|
263
|
+
"RouteRejected": "verifiers.v1.clients",
|
|
256
264
|
"NetworkPolicyConfig": "verifiers.v1.configs.runtime",
|
|
257
265
|
"PATCH_CAP_BYTES": "verifiers.v1.utils.git",
|
|
258
266
|
"ParentLink": "verifiers.v1.semantic",
|
|
@@ -481,6 +489,8 @@ __all__ = [ # noqa: RUF022 - grouped by public API area
|
|
|
481
489
|
"ACPHarness",
|
|
482
490
|
"ACPTurn",
|
|
483
491
|
"ModelContext",
|
|
492
|
+
"ModelRoute",
|
|
493
|
+
"RouteRejected",
|
|
484
494
|
"Runtime",
|
|
485
495
|
"RuntimeProcess",
|
|
486
496
|
"RuntimeConfig",
|
verifiers/v1/agent.py
CHANGED
|
@@ -21,6 +21,7 @@ from typing_extensions import TypeVar
|
|
|
21
21
|
from verifiers.v1.clients import (
|
|
22
22
|
EvalClientConfig,
|
|
23
23
|
ModelContext,
|
|
24
|
+
ModelRoute,
|
|
24
25
|
)
|
|
25
26
|
from verifiers.v1.configs.agent import (
|
|
26
27
|
AgentConfig,
|
|
@@ -685,6 +686,7 @@ class Agent:
|
|
|
685
686
|
on_trace: Callable[[Trace], None] | None = None,
|
|
686
687
|
collect_artifacts: bool = False,
|
|
687
688
|
on_score: Callable[[Trace, Runtime], Awaitable[None]] | None = None,
|
|
689
|
+
route: ModelRoute | None = None,
|
|
688
690
|
) -> Trace:
|
|
689
691
|
"""Run this agent on `task` once and return the trace: one segment — the
|
|
690
692
|
program runs on the task's prompt until it exits (a multi-turn exchange
|
|
@@ -697,9 +699,13 @@ class Agent:
|
|
|
697
699
|
(`config.retries`) — never into a borrowed box; every attempt's trace keeps
|
|
698
700
|
the run's id with its own `attempt`, and the final trace keeps earlier
|
|
699
701
|
attempts' errors. `on_score(trace, runtime)` runs after task scoring in
|
|
700
|
-
the selected verifier workspace, inside its timeout and retry boundary.
|
|
702
|
+
the selected verifier workspace, inside its timeout and retry boundary.
|
|
703
|
+
`route` is where its model turns go, from the agent's model, client and
|
|
704
|
+
sampling unless given; the caller may change it while the rollout runs
|
|
705
|
+
(`ModelRoute.update`), and a retry takes it as it is then."""
|
|
701
706
|
if self._closed:
|
|
702
707
|
raise RuntimeError("Agent is closed; create a new agent")
|
|
708
|
+
route = route or ModelRoute(self.ctx)
|
|
703
709
|
retry = self.config.retries
|
|
704
710
|
retry_state = RetryState(retry)
|
|
705
711
|
history: list = []
|
|
@@ -713,6 +719,7 @@ class Agent:
|
|
|
713
719
|
on_trace,
|
|
714
720
|
collect_artifacts,
|
|
715
721
|
on_score,
|
|
722
|
+
route,
|
|
716
723
|
trace_id=trace_id,
|
|
717
724
|
attempt=attempt + 1,
|
|
718
725
|
)
|
|
@@ -752,11 +759,12 @@ class Agent:
|
|
|
752
759
|
on_trace: Callable[[Trace], None] | None,
|
|
753
760
|
collect_artifacts: bool,
|
|
754
761
|
on_score: Callable[[Trace, Runtime], Awaitable[None]] | None,
|
|
762
|
+
route: ModelRoute,
|
|
755
763
|
*,
|
|
756
764
|
trace_id: str,
|
|
757
765
|
attempt: int,
|
|
758
766
|
) -> Trace:
|
|
759
|
-
params = self._rollout_params(task, runtime, dict(shared_tools or {}))
|
|
767
|
+
params = self._rollout_params(task, runtime, dict(shared_tools or {}), route)
|
|
760
768
|
if collect_artifacts:
|
|
761
769
|
_check_artifact_runtime(params["runtime_config"])
|
|
762
770
|
run = Rollout(
|
|
@@ -791,6 +799,7 @@ class Agent:
|
|
|
791
799
|
tools: Mapping[str, SharedToolServer] | None = None,
|
|
792
800
|
on_trace: Callable[[Trace], None] | None = None,
|
|
793
801
|
collect_artifacts: bool = False,
|
|
802
|
+
route: ModelRoute | None = None,
|
|
794
803
|
) -> AsyncIterator[Interaction]:
|
|
795
804
|
"""Interact with this agent turn-by-turn: a full rollout of `task` where
|
|
796
805
|
the CALLER is the run's user — the one exchange surface. Yields an
|
|
@@ -817,13 +826,15 @@ class Agent:
|
|
|
817
826
|
included. A failure while opening the rollout raises before the context
|
|
818
827
|
is entered (the failed trace is still completed and reported through
|
|
819
828
|
`on_trace`). An exchange is caller-driven, so `config.retries` does not
|
|
820
|
-
apply here."""
|
|
829
|
+
apply here. `route` is where its model turns go, as for `run()`."""
|
|
821
830
|
if self._closed:
|
|
822
831
|
raise RuntimeError("Agent is closed; create a new agent")
|
|
823
832
|
self._check_resume_support()
|
|
824
833
|
trace_id = uuid.uuid4().hex
|
|
825
834
|
with scope(trace=short_id(trace_id), agent=self._log_name):
|
|
826
|
-
params = self._rollout_params(
|
|
835
|
+
params = self._rollout_params(
|
|
836
|
+
task, runtime, dict(tools or {}), route or ModelRoute(self.ctx)
|
|
837
|
+
)
|
|
827
838
|
if collect_artifacts:
|
|
828
839
|
_check_artifact_runtime(params["runtime_config"])
|
|
829
840
|
run = Rollout(
|
|
@@ -857,7 +868,11 @@ class Agent:
|
|
|
857
868
|
trace.agent.runtime.borrowed = runtime is not None
|
|
858
869
|
|
|
859
870
|
def _rollout_params(
|
|
860
|
-
self,
|
|
871
|
+
self,
|
|
872
|
+
task: Task,
|
|
873
|
+
runtime: Runtime | None,
|
|
874
|
+
shared_tools: dict,
|
|
875
|
+
route: ModelRoute,
|
|
861
876
|
) -> dict:
|
|
862
877
|
"""Resolve one run's runtime config, pairing checks, timeouts,
|
|
863
878
|
interception — shared by `run` and `interaction`."""
|
|
@@ -887,7 +902,7 @@ class Agent:
|
|
|
887
902
|
return {
|
|
888
903
|
"agent_config": self.config,
|
|
889
904
|
"harness": harness,
|
|
890
|
-
"
|
|
905
|
+
"route": route,
|
|
891
906
|
"runtime_config": runtime_config,
|
|
892
907
|
"timeouts": timeouts,
|
|
893
908
|
"limits": self.limits,
|
|
@@ -1018,6 +1033,7 @@ class _EpisodeAgent(Agent):
|
|
|
1018
1033
|
on_trace: Callable[[Trace], None] | None = None,
|
|
1019
1034
|
collect_artifacts: bool = False,
|
|
1020
1035
|
on_score: Callable[[Trace, Runtime], Awaitable[None]] | None = None,
|
|
1036
|
+
route: ModelRoute | None = None,
|
|
1021
1037
|
) -> Trace:
|
|
1022
1038
|
async with self._gate or nullcontext():
|
|
1023
1039
|
trace = await super().run(
|
|
@@ -1027,6 +1043,7 @@ class _EpisodeAgent(Agent):
|
|
|
1027
1043
|
on_trace=self._watch(on_trace),
|
|
1028
1044
|
collect_artifacts=collect_artifacts,
|
|
1029
1045
|
on_score=self._scoring_callback(on_score),
|
|
1046
|
+
route=route,
|
|
1030
1047
|
)
|
|
1031
1048
|
self._completed.append(trace)
|
|
1032
1049
|
return trace
|
|
@@ -1040,6 +1057,7 @@ class _EpisodeAgent(Agent):
|
|
|
1040
1057
|
tools: Mapping[str, SharedToolServer] | None = None,
|
|
1041
1058
|
on_trace: Callable[[Trace], None] | None = None,
|
|
1042
1059
|
collect_artifacts: bool = False,
|
|
1060
|
+
route: ModelRoute | None = None,
|
|
1043
1061
|
) -> AsyncIterator[Interaction]:
|
|
1044
1062
|
"""The agent's `interaction`, with every trace stamped with its standing
|
|
1045
1063
|
at mint and captured in `completed` at close — an interaction driven from
|
|
@@ -1062,6 +1080,7 @@ class _EpisodeAgent(Agent):
|
|
|
1062
1080
|
tools=tools if tools is not None else self._shared_for(task),
|
|
1063
1081
|
on_trace=self._watch(remember),
|
|
1064
1082
|
collect_artifacts=collect_artifacts,
|
|
1083
|
+
route=route,
|
|
1065
1084
|
) as interaction:
|
|
1066
1085
|
yield interaction
|
|
1067
1086
|
finally:
|
verifiers/v1/clients/__init__.py
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
from verifiers.v1.clients.client import
|
|
1
|
+
from verifiers.v1.clients.client import (
|
|
2
|
+
Client,
|
|
3
|
+
ModelContext,
|
|
4
|
+
ModelRoute,
|
|
5
|
+
RouteRejected,
|
|
6
|
+
resolve_client,
|
|
7
|
+
)
|
|
2
8
|
from verifiers.v1.clients.eval import EvalClient
|
|
3
9
|
from verifiers.v1.clients.train import TrainClient
|
|
4
10
|
from verifiers.v1.configs.client import (
|
|
@@ -15,6 +21,8 @@ __all__ = [
|
|
|
15
21
|
"EvalClient",
|
|
16
22
|
"EvalClientConfig",
|
|
17
23
|
"ModelContext",
|
|
24
|
+
"ModelRoute",
|
|
25
|
+
"RouteRejected",
|
|
18
26
|
"TrainClient",
|
|
19
27
|
"TrainClientConfig",
|
|
20
28
|
"resolve_client",
|
verifiers/v1/clients/client.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"""Client interfaces for model inference and relay."""
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
3
4
|
from abc import ABC, abstractmethod
|
|
4
5
|
from collections.abc import AsyncIterator, Awaitable, Callable, Mapping
|
|
5
|
-
from dataclasses import dataclass, field
|
|
6
|
+
from dataclasses import dataclass, field, replace
|
|
6
7
|
|
|
7
8
|
from verifiers.v1.configs.client import (
|
|
8
9
|
BaseClientConfig,
|
|
@@ -11,6 +12,7 @@ from verifiers.v1.configs.client import (
|
|
|
11
12
|
)
|
|
12
13
|
from verifiers.v1.configs.sampling import Sampling, SamplingConfig
|
|
13
14
|
from verifiers.v1.dialects import Dialect
|
|
15
|
+
from verifiers.v1.errors import ProviderError
|
|
14
16
|
from verifiers.v1.graph import PendingTurn
|
|
15
17
|
from verifiers.v1.types import Response
|
|
16
18
|
|
|
@@ -88,3 +90,95 @@ class ModelContext:
|
|
|
88
90
|
model: str
|
|
89
91
|
client: ClientConfig
|
|
90
92
|
sampling: Sampling = field(default_factory=Sampling)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class RouteRejected(Exception):
|
|
96
|
+
"""A route change the rollout can't take; its route is left as it was."""
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
PROBE_TOKENS = 16
|
|
100
|
+
"""Output tokens a route change's probe asks for (16 is the least Responses accepts)."""
|
|
101
|
+
PROBE_TIMEOUT = 60.0
|
|
102
|
+
"""Seconds a route change's probe may take, retries included, before the change is refused."""
|
|
103
|
+
PROBE_RETRY_DELAYS = (1.0, 4.0)
|
|
104
|
+
"""Waits before retrying a probe the endpoint failed transiently (429, 5xx, timeout)."""
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class ModelRoute:
|
|
108
|
+
"""Where one rollout's model turns go while it runs: its `ModelContext`, which the
|
|
109
|
+
caller may change mid-rollout with `update`. The interception server reads the
|
|
110
|
+
current context on every model request, so a change applies from the rollout's
|
|
111
|
+
next turn (and to any retry of it); a new client config gets the server's shared
|
|
112
|
+
client for it. A scheduler moving a running rollout to another endpoint, or a live
|
|
113
|
+
sampling change, is one `update`. The new endpoint starts without the rollout's
|
|
114
|
+
prompt cache, so the first turn after a move pays for its whole prompt. Model and
|
|
115
|
+
client changes are supported for eval clients only; training routes may update sampling."""
|
|
116
|
+
|
|
117
|
+
def __init__(self, ctx: ModelContext) -> None:
|
|
118
|
+
self.ctx = ctx
|
|
119
|
+
self._updating = asyncio.Lock()
|
|
120
|
+
self.dialect: Dialect | None = None
|
|
121
|
+
"""The wire format the rollout's harness speaks, set by the interception server
|
|
122
|
+
from its first model request; None until then."""
|
|
123
|
+
|
|
124
|
+
async def update(
|
|
125
|
+
self,
|
|
126
|
+
*,
|
|
127
|
+
model: str | None = None,
|
|
128
|
+
client: ClientConfig | None = None,
|
|
129
|
+
sampling: Sampling | None = None,
|
|
130
|
+
) -> None:
|
|
131
|
+
"""Change the model, client or sampling of the rollout's next turns; a value left
|
|
132
|
+
out stays as it is. Raises `RouteRejected`, leaving the route unchanged, when the
|
|
133
|
+
rollout can't take the change: a client of another type (eval and train clients
|
|
134
|
+
don't mix within a rollout), a model or client change on a training route, or an
|
|
135
|
+
eval endpoint that refuses a request in the dialect the harness speaks. That probe
|
|
136
|
+
is one short request, sent when the model or client changes once the harness has
|
|
137
|
+
made its first request."""
|
|
138
|
+
changes = {"model": model, "client": client, "sampling": sampling}
|
|
139
|
+
changes = {k: v for k, v in changes.items() if v is not None}
|
|
140
|
+
# One update at a time, each from the context as the last one left it, so a change
|
|
141
|
+
# made while another one's probe was in flight is never undone.
|
|
142
|
+
async with self._updating:
|
|
143
|
+
new = replace(self.ctx, **changes)
|
|
144
|
+
if type(new.client) is not type(self.ctx.client):
|
|
145
|
+
raise RouteRejected(
|
|
146
|
+
f"a rollout's client stays {self.ctx.client.type}: it can't move to a "
|
|
147
|
+
f"{new.client.type} client"
|
|
148
|
+
)
|
|
149
|
+
moved = (new.model, new.client) != (self.ctx.model, self.ctx.client)
|
|
150
|
+
if moved and isinstance(self.ctx.client, TrainClientConfig):
|
|
151
|
+
raise RouteRejected(
|
|
152
|
+
"training routes can't change model or client; only sampling may change"
|
|
153
|
+
)
|
|
154
|
+
if moved and self.dialect is not None:
|
|
155
|
+
await _probe(new, self.dialect)
|
|
156
|
+
self.ctx = new
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
async def _probe(ctx: ModelContext, dialect: Dialect) -> None:
|
|
160
|
+
"""Send `ctx`'s model one short request in `dialect`; RouteRejected if the endpoint refuses
|
|
161
|
+
it, or still fails transiently (429, 5xx) after a retry or two, or PROBE_TIMEOUT passes."""
|
|
162
|
+
message = [{"role": "user", "content": "Reply with OK."}]
|
|
163
|
+
body = {"input": message} if dialect.name == "responses" else {"messages": message}
|
|
164
|
+
sampling = SamplingConfig(max_tokens=PROBE_TOKENS)
|
|
165
|
+
request = dialect.apply_overrides(body, ctx.model, sampling)
|
|
166
|
+
client = resolve_client(ctx.client)
|
|
167
|
+
try:
|
|
168
|
+
async with asyncio.timeout(PROBE_TIMEOUT):
|
|
169
|
+
for delay in (*PROBE_RETRY_DELAYS, None):
|
|
170
|
+
try:
|
|
171
|
+
await client.get_response(dialect, request, sampling)
|
|
172
|
+
return
|
|
173
|
+
except ProviderError as e:
|
|
174
|
+
transient = e.status_code == 429 or e.status_code >= 500
|
|
175
|
+
if not transient or delay is None:
|
|
176
|
+
raise
|
|
177
|
+
await asyncio.sleep(delay)
|
|
178
|
+
except Exception as e:
|
|
179
|
+
reason = "no answer in time" if isinstance(e, TimeoutError) else str(e)
|
|
180
|
+
raise RouteRejected(
|
|
181
|
+
f"{ctx.model} at {ctx.client.base_url} failed a {dialect.name} request: {reason}"
|
|
182
|
+
) from e
|
|
183
|
+
finally:
|
|
184
|
+
await client.close()
|
|
@@ -32,20 +32,22 @@ def requires_tunnel(
|
|
|
32
32
|
"""Whether the interception must be exposed via a tunnel — some consumer is off the
|
|
33
33
|
host network: the harness itself, a live `shared` server in a remote runtime, or a
|
|
34
34
|
tool server config placing one there (each reaches the `/state` channel from
|
|
35
|
-
its own runtime).
|
|
36
|
-
|
|
35
|
+
its own runtime). Task-format adapters share the harness's locality. Skipped as
|
|
36
|
+
non-consumers: a config-`url` server (external —
|
|
37
37
|
it connects out), and an `external` shared server (outside the state machinery
|
|
38
38
|
entirely). False means every consumer reaches the server at localhost."""
|
|
39
|
+
from verifiers.v1.mcp.toolset import BaseToolsetConfig
|
|
40
|
+
|
|
39
41
|
if not harness_is_local:
|
|
40
42
|
return True
|
|
41
43
|
if any(not s.external and not s.local for s in shared):
|
|
42
44
|
return True
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
return any(
|
|
46
|
+
isinstance(config, BaseToolsetConfig)
|
|
47
|
+
and not config.url
|
|
48
|
+
and not runtime_is_local(config.runtime)
|
|
49
|
+
for config in server_configs
|
|
50
|
+
)
|
|
49
51
|
|
|
50
52
|
|
|
51
53
|
def make_interception(
|
|
@@ -758,11 +758,16 @@ class InterceptionServer(Interception):
|
|
|
758
758
|
body = from_json(raw)
|
|
759
759
|
except ValueError:
|
|
760
760
|
body = json.loads(raw)
|
|
761
|
-
|
|
761
|
+
# One context for the whole request: a route updated while it is in flight applies
|
|
762
|
+
# from the next request, never to half of this one.
|
|
763
|
+
ctx = session.ctx
|
|
764
|
+
session.route.dialect = dialect
|
|
765
|
+
session.client = client = self._client(ctx.client)
|
|
766
|
+
body = dialect.apply_overrides(body, ctx.model, ctx.sampling)
|
|
762
767
|
streaming = dialect.streaming(body)
|
|
763
768
|
# A streamed request is served whole once its turn commits: the eval client's
|
|
764
769
|
# provider stream is read to the end, and the train client generates the response.
|
|
765
|
-
relay = streaming and not isinstance(
|
|
770
|
+
relay = streaming and not isinstance(ctx.client, TrainClientConfig)
|
|
766
771
|
req_hash = await _request_digest(raw)
|
|
767
772
|
# Keep `read()` for aiohttp's size guard, then release its cache and our local
|
|
768
773
|
# alias after parsing so the wire body does not survive model inference.
|
|
@@ -951,7 +956,7 @@ class InterceptionServer(Interception):
|
|
|
951
956
|
# What actually goes upstream: the native body with the rollout's model +
|
|
952
957
|
# sampling imposed — recorded raw on the trace, per call.
|
|
953
958
|
if relay:
|
|
954
|
-
reply = await
|
|
959
|
+
reply = await client.relay(
|
|
955
960
|
dialect,
|
|
956
961
|
body,
|
|
957
962
|
headers=upstream_headers,
|
|
@@ -959,10 +964,10 @@ class InterceptionServer(Interception):
|
|
|
959
964
|
)
|
|
960
965
|
call_response, events = await _collect_stream(dialect, reply)
|
|
961
966
|
else:
|
|
962
|
-
call_response = await
|
|
967
|
+
call_response = await client.get_response(
|
|
963
968
|
dialect,
|
|
964
969
|
body,
|
|
965
|
-
|
|
970
|
+
ctx.sampling,
|
|
966
971
|
headers=upstream_headers,
|
|
967
972
|
session_id=upstream_session_id,
|
|
968
973
|
turn=turn,
|
|
@@ -1073,9 +1078,10 @@ class InterceptionServer(Interception):
|
|
|
1073
1078
|
logger.debug("Received %s request", route)
|
|
1074
1079
|
try:
|
|
1075
1080
|
body = await request.json()
|
|
1076
|
-
|
|
1081
|
+
ctx = session.ctx
|
|
1082
|
+
body["model"] = ctx.model
|
|
1077
1083
|
body = self.mediate_capabilities(session, dialect, body)[0]
|
|
1078
|
-
result = await
|
|
1084
|
+
result = await self._client(ctx.client).relay_aux(
|
|
1079
1085
|
dialect, route, body, headers=request.headers
|
|
1080
1086
|
)
|
|
1081
1087
|
except RolloutError as e:
|
verifiers/v1/mcp/launch.py
CHANGED
|
@@ -265,7 +265,7 @@ async def _install_in_sandbox(server: ServerBase, agent_runtime: Runtime) -> str
|
|
|
265
265
|
venv = str(PurePosixPath(workdir) / ".vf-venv")
|
|
266
266
|
python_dir = str(PurePosixPath(workdir) / ".vf-python")
|
|
267
267
|
root_q, temp_q, cache_q, venv_q = map(shlex.quote, (root, temp, cache, venv))
|
|
268
|
-
#
|
|
268
|
+
# Servers in the same service install into one physical environment.
|
|
269
269
|
# Serialize its mutations and only remember sources after a successful install.
|
|
270
270
|
async with runtime.backend.cache.mcp_lock:
|
|
271
271
|
sources = dict.fromkeys((_package_dir(ServerBase), _package_dir(type(server))))
|
|
@@ -353,9 +353,9 @@ async def serve_in_runtime(
|
|
|
353
353
|
) -> int:
|
|
354
354
|
"""Start a server and return its bound port.
|
|
355
355
|
|
|
356
|
-
Exposed
|
|
357
|
-
the OS
|
|
358
|
-
the current rollout task from the adjacent `/task` endpoint
|
|
356
|
+
Exposed servers use the runtime's forwarded port when one is configured. Otherwise,
|
|
357
|
+
the OS chooses a port and reports it through a file. With a state channel, the server
|
|
358
|
+
fetches the current rollout task from the adjacent `/task` endpoint.
|
|
359
359
|
"""
|
|
360
360
|
# A shared server has a private service secret but no fixed state URL. Set
|
|
361
361
|
# both controls explicitly so a subprocess cannot inherit stale host values.
|
|
@@ -435,21 +435,9 @@ async def reachable_url(
|
|
|
435
435
|
service_runtime: Runtime,
|
|
436
436
|
port: int,
|
|
437
437
|
*,
|
|
438
|
-
colocated: bool,
|
|
439
438
|
consumer_is_local: bool,
|
|
440
439
|
) -> AsyncIterator[str]:
|
|
441
|
-
"""
|
|
442
|
-
primitives: `Runtime.expose` (publish a port out of a sandbox) and a host `Tunnel` (reach
|
|
443
|
-
into the host from a remote runtime). `colocated` = the server shares the consumer's
|
|
444
|
-
runtime; `consumer_is_local` = the consumer can use a host-local URL without a tunnel.
|
|
445
|
-
|
|
446
|
-
- `colocated` -> localhost (same runtime, in-sandbox or host loopback);
|
|
447
|
-
- else the runtime publishes the port (`expose`): a remote sandbox's URL is reachable
|
|
448
|
-
anywhere, a host-local URL directly by a local consumer and through a host tunnel
|
|
449
|
-
by a remote one."""
|
|
450
|
-
if colocated:
|
|
451
|
-
yield f"http://127.0.0.1:{port}"
|
|
452
|
-
return
|
|
440
|
+
"""Publish a service port, tunneling host-local URLs for remote consumers."""
|
|
453
441
|
url = await service_runtime.expose(port)
|
|
454
442
|
if service_runtime.is_local and not consumer_is_local:
|
|
455
443
|
async with PrimeTunnel().expose(urlsplit(url).port or 80) as public:
|
|
@@ -478,34 +466,52 @@ async def _serve(
|
|
|
478
466
|
placements: Mapping[str, Runtime] | None = None,
|
|
479
467
|
):
|
|
480
468
|
cfg = server.config
|
|
481
|
-
colocated = getattr(cfg, "colocated", False)
|
|
482
469
|
service = getattr(cfg, "service", None)
|
|
483
470
|
own_vm = (placements or {}).get(server.server_name)
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
471
|
+
async with contextlib.AsyncExitStack() as stack:
|
|
472
|
+
host = None
|
|
473
|
+
if service is not None or own_vm is not None:
|
|
474
|
+
if own_vm is not None:
|
|
475
|
+
runtime = own_vm
|
|
476
|
+
host = (hosts or {})[server.server_name]
|
|
477
|
+
elif services is None or service not in services:
|
|
478
|
+
raise ToolsetError(
|
|
479
|
+
f"server {server.server_name!r} runs in service {service!r}, "
|
|
480
|
+
"which needs a task whose services define it"
|
|
481
|
+
)
|
|
482
|
+
else:
|
|
483
|
+
runtime = services[service]
|
|
484
|
+
host = (hosts or {}).get(service, service)
|
|
485
|
+
if runtime.is_local:
|
|
486
|
+
raise ToolsetError(
|
|
487
|
+
f"server {server.server_name!r} runs in service {service!r}, "
|
|
488
|
+
"which needs a native Prime service VM"
|
|
489
|
+
)
|
|
495
490
|
else:
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
491
|
+
if (
|
|
492
|
+
isinstance(cfg.runtime, NetworkPolicyConfig)
|
|
493
|
+
and cfg.runtime.network_restricted
|
|
494
|
+
):
|
|
495
|
+
raise ToolsetError(
|
|
496
|
+
f"server {server.server_name!r} restricts its runtime's network, "
|
|
497
|
+
"which needs a Prime runtime of its own beside a Prime workspace "
|
|
498
|
+
"without a task service spec (it then joins the rollout's "
|
|
499
|
+
"private network)"
|
|
500
|
+
)
|
|
501
|
+
if not backend_cls(cfg.runtime).SUPPORTS_PORT_EXPOSURE:
|
|
502
|
+
raise ToolsetError(
|
|
503
|
+
f"server {server.server_name!r} runs in its own runtime, but the "
|
|
504
|
+
f"{cfg.runtime.type} runtime cannot expose a port; "
|
|
505
|
+
"use a runtime that supports port exposure"
|
|
506
|
+
)
|
|
507
|
+
backend = await stack.enter_async_context(provision_backend(cfg.runtime))
|
|
508
|
+
runtime = backend.bind()
|
|
509
|
+
|
|
504
510
|
port = await serve_in_runtime(
|
|
505
511
|
server,
|
|
506
512
|
runtime,
|
|
507
|
-
exposed=
|
|
508
|
-
listen_all=
|
|
513
|
+
exposed=host is None,
|
|
514
|
+
listen_all=host is not None,
|
|
509
515
|
state_url=(
|
|
510
516
|
runtime.host_url(f"{state_base.rstrip('/')}/state")
|
|
511
517
|
if state_base
|
|
@@ -513,82 +519,27 @@ async def _serve(
|
|
|
513
519
|
),
|
|
514
520
|
state_secret=state_secret,
|
|
515
521
|
)
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
# server has neither that lifecycle nor a published port after isolation;
|
|
521
|
-
# reject it instead of silently leaving its requested policy unenforced.
|
|
522
|
-
if (
|
|
523
|
-
isinstance(cfg.runtime, NetworkPolicyConfig)
|
|
524
|
-
and cfg.runtime.network_restricted
|
|
525
|
-
and not (colocated and harness_runtime is not None)
|
|
526
|
-
):
|
|
527
|
-
raise ToolsetError(
|
|
528
|
-
f"server {server.server_name!r} restricts its runtime's network, which "
|
|
529
|
-
"needs the server colocated with the harness, or on a Prime runtime "
|
|
530
|
-
"of its own beside a Prime workspace without a task service spec (it then "
|
|
531
|
-
"joins the rollout's private network)"
|
|
532
|
-
)
|
|
533
|
-
if colocated and harness_runtime is not None:
|
|
534
|
-
runtime = harness_runtime
|
|
535
|
-
elif not backend_cls(cfg.runtime).SUPPORTS_PORT_EXPOSURE:
|
|
536
|
-
raise ToolsetError(
|
|
537
|
-
f"server {server.server_name!r} runs in its own runtime, but the "
|
|
538
|
-
f"{cfg.runtime.type} runtime cannot expose a port; colocate it with the "
|
|
539
|
-
"harness or use a supported runtime"
|
|
540
|
-
)
|
|
541
|
-
else:
|
|
542
|
-
backend = await stack.enter_async_context(provision_backend(cfg.runtime))
|
|
543
|
-
runtime = backend.bind()
|
|
544
|
-
# Only consumers outside the server runtime need its fixed published port. Colocated tools
|
|
545
|
-
# use independent OS-assigned ports, avoiding clashes on the runtime's service port.
|
|
546
|
-
exposed = runtime is not harness_runtime
|
|
547
|
-
# The shared-state channel: every server reaches the interception at the rollout's
|
|
548
|
-
# `state_base`, which is universally reachable (the interception is exposed via a tunnel
|
|
549
|
-
# whenever any consumer is remote). Eval-level shared servers get no per-rollout channel
|
|
550
|
-
# (`state_base` is None for them).
|
|
551
|
-
state_url = (
|
|
552
|
-
runtime.host_url(f"{state_base.rstrip('/')}/state") if state_base else None
|
|
553
|
-
)
|
|
554
|
-
port = await serve_in_runtime(
|
|
555
|
-
server,
|
|
556
|
-
runtime,
|
|
557
|
-
exposed=exposed,
|
|
558
|
-
state_url=state_url,
|
|
559
|
-
state_secret=state_secret,
|
|
560
|
-
)
|
|
561
|
-
# The harness consumes the server, and decides reachability: colocated when the
|
|
562
|
-
# server shares the harness's runtime, reached with the harness's locality (read
|
|
563
|
-
# off the harness runtime when there is one, else `harness_is_local` for an
|
|
564
|
-
# eval-level shared tool).
|
|
565
|
-
colocated = runtime is harness_runtime
|
|
522
|
+
if host is not None:
|
|
523
|
+
yield _ServedServer(f"http://{host}:{port}/mcp", runtime)
|
|
524
|
+
return
|
|
525
|
+
|
|
566
526
|
consumer_is_local = (
|
|
567
527
|
harness_runtime.is_local
|
|
568
528
|
if harness_runtime is not None
|
|
569
529
|
else harness_is_local
|
|
570
530
|
)
|
|
571
|
-
if
|
|
572
|
-
|
|
573
|
-
and runtime.
|
|
574
|
-
and not colocated
|
|
575
|
-
and not consumer_is_local
|
|
576
|
-
):
|
|
577
|
-
backend = await runtime.expose(port)
|
|
578
|
-
# Register after startup, and revoke/drain before releasing the runtime.
|
|
531
|
+
if proxy_mcp is not None and runtime.is_local and not consumer_is_local:
|
|
532
|
+
backend_url = await runtime.expose(port)
|
|
533
|
+
# Revoke and drain the proxy before releasing the runtime.
|
|
579
534
|
url = await stack.enter_async_context(
|
|
580
|
-
proxy_mcp(f"{
|
|
535
|
+
proxy_mcp(f"{backend_url.rstrip('/')}/mcp")
|
|
581
536
|
)
|
|
582
537
|
yield _ServedServer(url, runtime)
|
|
583
538
|
return
|
|
584
539
|
base = await stack.enter_async_context(
|
|
585
|
-
reachable_url(
|
|
586
|
-
runtime, port, colocated=colocated, consumer_is_local=consumer_is_local
|
|
587
|
-
)
|
|
540
|
+
reachable_url(runtime, port, consumer_is_local=consumer_is_local)
|
|
588
541
|
)
|
|
589
|
-
if
|
|
590
|
-
base = base.replace("127.0.0.1", "localhost", 1)
|
|
591
|
-
elif not colocated and harness_runtime is not None:
|
|
542
|
+
if harness_runtime is not None:
|
|
592
543
|
base = harness_runtime.host_url(base)
|
|
593
544
|
yield _ServedServer(f"{base.rstrip('/')}/mcp", runtime)
|
|
594
545
|
|
|
@@ -730,10 +681,9 @@ async def serve_tools(
|
|
|
730
681
|
placements: Mapping[str, Runtime] | None = None,
|
|
731
682
|
):
|
|
732
683
|
"""Bring up a rollout's tool servers and yield `{name: url}` the harness reaches: the
|
|
733
|
-
task-scoped `toolsets`
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
running eval-level (see `serve_shared`) — join under their per-rollout state tag.
|
|
684
|
+
task-scoped `toolsets` own their connections through `Toolset.serve`, and
|
|
685
|
+
taskset-scoped `shared` servers, already running eval-level (see `serve_shared`),
|
|
686
|
+
join under their per-rollout state tag.
|
|
737
687
|
`state_secret` is private to task-scoped servers; shared servers keep an
|
|
738
688
|
eval-level service secret and receive only signed `state_route` coordinates.
|
|
739
689
|
`state_base` is universally reachable from either placement."""
|
|
@@ -757,22 +707,16 @@ async def serve_tools(
|
|
|
757
707
|
f"tool server name '{name}' is declared both taskset-scoped (shared) "
|
|
758
708
|
f"and task-scoped — pick one scope, or give one a distinct TOOL_PREFIX"
|
|
759
709
|
)
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
state_secret=state_secret,
|
|
770
|
-
state_base=state_base,
|
|
771
|
-
proxy_mcp=proxy_mcp,
|
|
772
|
-
services=services,
|
|
773
|
-
hosts=hosts,
|
|
774
|
-
placements=placements,
|
|
775
|
-
)
|
|
710
|
+
urls[name] = await stack.enter_async_context(
|
|
711
|
+
toolset.serve(
|
|
712
|
+
harness_runtime,
|
|
713
|
+
state_secret=state_secret,
|
|
714
|
+
state_base=state_base,
|
|
715
|
+
proxy_mcp=proxy_mcp,
|
|
716
|
+
services=services,
|
|
717
|
+
hosts=hosts,
|
|
718
|
+
placements=placements,
|
|
776
719
|
)
|
|
777
|
-
|
|
720
|
+
)
|
|
721
|
+
logger.debug("Connected tool server %s", name)
|
|
778
722
|
yield urls
|
verifiers/v1/mcp/toolset.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from collections.abc import AsyncIterator
|
|
4
|
+
from contextlib import asynccontextmanager
|
|
3
5
|
from typing import TYPE_CHECKING
|
|
4
6
|
|
|
5
7
|
from pydantic import Field, model_validator
|
|
@@ -13,6 +15,8 @@ from verifiers.v1.utils.decorators import discover_decorated
|
|
|
13
15
|
if TYPE_CHECKING:
|
|
14
16
|
from mcp.server.mcpserver import MCPServer
|
|
15
17
|
|
|
18
|
+
from verifiers.v1.runtimes import Runtime
|
|
19
|
+
|
|
16
20
|
|
|
17
21
|
class ToolsetTimeoutConfig(BaseConfig):
|
|
18
22
|
"""Timeouts (in seconds) for a launched tool server; `None` waits indefinitely."""
|
|
@@ -22,7 +26,7 @@ class ToolsetTimeoutConfig(BaseConfig):
|
|
|
22
26
|
|
|
23
27
|
|
|
24
28
|
class BaseToolsetConfig(BaseConfig):
|
|
25
|
-
"""
|
|
29
|
+
"""Runtime and connection settings for per-task and shared tool servers."""
|
|
26
30
|
|
|
27
31
|
runtime: RuntimeConfig = SubprocessConfig()
|
|
28
32
|
"""Where the server runs: the evaluator by default."""
|
|
@@ -35,7 +39,6 @@ class ToolsetConfig(BaseToolsetConfig):
|
|
|
35
39
|
service spec is a VM of the server's own that joins the workspace over the rollout's
|
|
36
40
|
private network, under its own egress policy."""
|
|
37
41
|
|
|
38
|
-
colocated: bool = False
|
|
39
42
|
service: str | None = None
|
|
40
43
|
"""Run the server in a named native Prime service VM. The harness reaches it
|
|
41
44
|
over the deployment's private network, using its LAN hostname."""
|
|
@@ -44,9 +47,9 @@ class ToolsetConfig(BaseToolsetConfig):
|
|
|
44
47
|
def _one_placement(self):
|
|
45
48
|
if self.service is None:
|
|
46
49
|
return self
|
|
47
|
-
if self.
|
|
50
|
+
if self.url:
|
|
48
51
|
raise ValueError(
|
|
49
|
-
"a tool server placed in a service
|
|
52
|
+
"a tool server placed in a service cannot use a remote URL"
|
|
50
53
|
)
|
|
51
54
|
# The service is the server's runtime; another one, or its policy, would go unused.
|
|
52
55
|
if not isinstance(self.runtime, SubprocessConfig):
|
|
@@ -62,6 +65,17 @@ class SharedToolsetConfig(BaseToolsetConfig):
|
|
|
62
65
|
|
|
63
66
|
|
|
64
67
|
class Toolset(ServerBase[ConfigT, StateT]):
|
|
68
|
+
@asynccontextmanager
|
|
69
|
+
async def serve(self, runtime: Runtime, **kwargs) -> AsyncIterator[str]:
|
|
70
|
+
"""Connect a rollout to this server; task-format adapters own their transport."""
|
|
71
|
+
from verifiers.v1.mcp.launch import serve
|
|
72
|
+
|
|
73
|
+
if self.config.url:
|
|
74
|
+
yield runtime.host_url(self.config.url)
|
|
75
|
+
else:
|
|
76
|
+
async with serve(self, runtime, **kwargs) as url:
|
|
77
|
+
yield url
|
|
78
|
+
|
|
65
79
|
def register(self, mcp: MCPServer) -> None:
|
|
66
80
|
for fn in discover_decorated(self, "tool"):
|
|
67
81
|
mcp.add_tool(
|
verifiers/v1/rollout.py
CHANGED
|
@@ -9,7 +9,7 @@ from contextlib import AsyncExitStack
|
|
|
9
9
|
from dataclasses import dataclass
|
|
10
10
|
from urllib.parse import urlsplit
|
|
11
11
|
|
|
12
|
-
from verifiers.v1.clients import
|
|
12
|
+
from verifiers.v1.clients import ModelRoute
|
|
13
13
|
from verifiers.v1.configs.agent import AgentConfig
|
|
14
14
|
from verifiers.v1.configs.runtime import NetworkPolicyConfig
|
|
15
15
|
from verifiers.v1.configs.scoring import resolve_scoring
|
|
@@ -115,7 +115,7 @@ class Rollout:
|
|
|
115
115
|
task: Task,
|
|
116
116
|
agent_config: AgentConfig,
|
|
117
117
|
harness: Harness,
|
|
118
|
-
|
|
118
|
+
route: ModelRoute,
|
|
119
119
|
runtime_config: RuntimeConfig,
|
|
120
120
|
has_user: bool = False,
|
|
121
121
|
timeouts: RolloutTimeouts,
|
|
@@ -132,7 +132,7 @@ class Rollout:
|
|
|
132
132
|
self._on_score = on_score
|
|
133
133
|
self.task = task
|
|
134
134
|
self.harness = harness
|
|
135
|
-
self.
|
|
135
|
+
self.route = route
|
|
136
136
|
self.runtime_config = runtime_config
|
|
137
137
|
self._scoring_policy = resolve_scoring(task.scoring, agent_config.scoring)
|
|
138
138
|
self._grading_config = None
|
|
@@ -175,7 +175,7 @@ class Rollout:
|
|
|
175
175
|
}
|
|
176
176
|
execution_policy = runtime_config
|
|
177
177
|
self._session = RolloutSession(
|
|
178
|
-
|
|
178
|
+
route=route,
|
|
179
179
|
trace=self.trace,
|
|
180
180
|
network_policy=(
|
|
181
181
|
execution_policy
|
|
@@ -543,7 +543,7 @@ class Rollout:
|
|
|
543
543
|
else {}
|
|
544
544
|
)
|
|
545
545
|
self._harness_session = await self.harness.session(
|
|
546
|
-
self.ctx,
|
|
546
|
+
self.route.ctx,
|
|
547
547
|
self.trace,
|
|
548
548
|
self._agent_runtime,
|
|
549
549
|
self._endpoint,
|
|
@@ -37,13 +37,15 @@ def tool_vms(
|
|
|
37
37
|
network, by server name: those on Prime runtimes of their own beside a Prime
|
|
38
38
|
workspace of the rollout's own, without a task service spec. Any other server keeps its
|
|
39
39
|
runtime's published port, which takes no network policy."""
|
|
40
|
+
from verifiers.v1.mcp.toolset import ToolsetConfig
|
|
41
|
+
|
|
40
42
|
if composed or borrowed or not isinstance(workspace, PrimeConfig):
|
|
41
43
|
return {}
|
|
42
44
|
vms = {
|
|
43
45
|
toolset.server_name: toolset.config.runtime
|
|
44
46
|
for toolset in toolsets
|
|
45
|
-
if isinstance(toolset.config
|
|
46
|
-
and
|
|
47
|
+
if isinstance(toolset.config, ToolsetConfig)
|
|
48
|
+
and isinstance(toolset.config.runtime, PrimeConfig)
|
|
47
49
|
and not toolset.config.url
|
|
48
50
|
and toolset.config.service is None
|
|
49
51
|
}
|
verifiers/v1/session.py
CHANGED
|
@@ -21,14 +21,14 @@ import json
|
|
|
21
21
|
from collections import Counter
|
|
22
22
|
from collections.abc import Awaitable, Callable
|
|
23
23
|
from contextlib import AbstractAsyncContextManager
|
|
24
|
-
from dataclasses import dataclass, field
|
|
24
|
+
from dataclasses import dataclass, field, replace
|
|
25
25
|
from functools import cached_property
|
|
26
26
|
from typing import get_origin, get_type_hints
|
|
27
27
|
|
|
28
28
|
from pydantic import TypeAdapter
|
|
29
29
|
|
|
30
30
|
from verifiers.v1 import graph
|
|
31
|
-
from verifiers.v1.clients import Client, ModelContext
|
|
31
|
+
from verifiers.v1.clients import Client, ModelContext, ModelRoute
|
|
32
32
|
from verifiers.v1.configs.harness import DialectName
|
|
33
33
|
from verifiers.v1.configs.runtime import NetworkPolicyConfig
|
|
34
34
|
from verifiers.v1.errors import HarnessError, RolloutError, TaskError
|
|
@@ -160,7 +160,8 @@ class ReplayResponse:
|
|
|
160
160
|
|
|
161
161
|
@dataclass
|
|
162
162
|
class RolloutSession:
|
|
163
|
-
|
|
163
|
+
route: ModelRoute
|
|
164
|
+
"""Where its model turns go; `ctx` is the route's current context."""
|
|
164
165
|
trace: Trace
|
|
165
166
|
network_policy: NetworkPolicyConfig = field(default_factory=NetworkPolicyConfig)
|
|
166
167
|
"""The resolved execution policy, including task-level restrictions."""
|
|
@@ -181,9 +182,10 @@ class RolloutSession:
|
|
|
181
182
|
`Harness.SUPPORTS_TOOL_INTERCEPTION`). Without that gate a pre-execution rewrite
|
|
182
183
|
cannot be enforced, so it ends the rollout instead of letting the call run."""
|
|
183
184
|
client: Client | None = None
|
|
184
|
-
"""The model client serving this rollout's turns. The interception server
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
"""The model client serving this rollout's turns. The interception server gives it the
|
|
186
|
+
server-owned client for its route's endpoint config (one per distinct config) at
|
|
187
|
+
`register` and again when the route changes, so every rollout it multiplexes shares one
|
|
188
|
+
keepalive connection pool instead of opening its own."""
|
|
187
189
|
proxy_mcp: MCPProxy | None = field(default=None, repr=False)
|
|
188
190
|
"""Register a host MCP backend on this session's interception server while serving."""
|
|
189
191
|
error: "RolloutError | None" = None
|
|
@@ -220,6 +222,19 @@ class RolloutSession:
|
|
|
220
222
|
"""The last chat request's raw messages (copied: the server rewrites a body in place) and
|
|
221
223
|
their parse, which the next request's equal prefix reuses instead of parsing again."""
|
|
222
224
|
|
|
225
|
+
@property
|
|
226
|
+
def ctx(self) -> ModelContext:
|
|
227
|
+
"""The model, client config and sampling of its next model turn: the route's, with
|
|
228
|
+
`max_turn_tokens` capping its `max_tokens` whatever sampling the route was given."""
|
|
229
|
+
ctx = self.route.ctx
|
|
230
|
+
cap = self.limits.max_turn_tokens
|
|
231
|
+
max_tokens = ctx.sampling.max_tokens
|
|
232
|
+
if cap is None or (max_tokens is not None and max_tokens <= cap):
|
|
233
|
+
return ctx
|
|
234
|
+
return replace(
|
|
235
|
+
ctx, sampling=ctx.sampling.model_copy(update={"max_tokens": cap})
|
|
236
|
+
)
|
|
237
|
+
|
|
223
238
|
@property
|
|
224
239
|
def stopped(self) -> bool:
|
|
225
240
|
return self.trace.stop_condition is not None
|
|
@@ -208,10 +208,10 @@ class HarborTask(Task[HarborData, State, HarborTaskConfig]):
|
|
|
208
208
|
|
|
209
209
|
@classmethod
|
|
210
210
|
def toolsets(cls, config: HarborTaskConfig):
|
|
211
|
-
from .toolset import
|
|
211
|
+
from .toolset import HarborMCPAdapter, HarborMCPConfig
|
|
212
212
|
|
|
213
213
|
return super().toolsets(config) + [
|
|
214
|
-
|
|
214
|
+
HarborMCPAdapter(HarborMCPConfig(server=server))
|
|
215
215
|
for server in config.mcp_servers
|
|
216
216
|
]
|
|
217
217
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Adapt Harbor's task-declared MCP servers to the harness's HTTP transport."""
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
|
+
from collections.abc import AsyncIterator
|
|
5
|
+
from contextlib import asynccontextmanager
|
|
4
6
|
from typing import Any, cast
|
|
5
7
|
|
|
6
8
|
from mcp import Client
|
|
@@ -10,20 +12,30 @@ from mcp.client.streamable_http import streamable_http_client
|
|
|
10
12
|
from mcp.server.mcpserver import Context, MCPServer
|
|
11
13
|
from mcp.server.mcpserver.exceptions import ToolError
|
|
12
14
|
from mcp.types import CallToolResult, Tool
|
|
15
|
+
from pydantic_config import BaseConfig
|
|
13
16
|
|
|
14
|
-
from verifiers.v1.mcp import Toolset
|
|
17
|
+
from verifiers.v1.mcp import Toolset
|
|
18
|
+
from verifiers.v1.mcp.launch import serve_in_runtime
|
|
19
|
+
from verifiers.v1.runtimes import Runtime
|
|
15
20
|
|
|
16
21
|
|
|
17
|
-
class HarborMCPConfig(
|
|
22
|
+
class HarborMCPConfig(BaseConfig):
|
|
18
23
|
server: dict[str, Any]
|
|
19
24
|
"""One declaration already validated by Harbor's task parser."""
|
|
20
25
|
|
|
21
26
|
|
|
22
|
-
class
|
|
27
|
+
class HarborMCPAdapter(Toolset[HarborMCPConfig]):
|
|
23
28
|
@property
|
|
24
29
|
def server_name(self) -> str:
|
|
25
30
|
return self.config.server["name"]
|
|
26
31
|
|
|
32
|
+
@asynccontextmanager
|
|
33
|
+
async def serve(self, runtime: Runtime, **kwargs) -> AsyncIterator[str]:
|
|
34
|
+
# Harbor commands and task-local URLs belong to the task environment.
|
|
35
|
+
port = await serve_in_runtime(self, runtime, exposed=False)
|
|
36
|
+
host = "localhost" if runtime.network_restricted else "127.0.0.1"
|
|
37
|
+
yield f"http://{host}:{port}/mcp"
|
|
38
|
+
|
|
27
39
|
async def setup(self) -> None:
|
|
28
40
|
spec = self.config.server
|
|
29
41
|
match spec["transport"]:
|
|
@@ -88,4 +100,4 @@ class HarborMCPToolset(Toolset[HarborMCPConfig]):
|
|
|
88
100
|
|
|
89
101
|
|
|
90
102
|
if __name__ == "__main__":
|
|
91
|
-
|
|
103
|
+
HarborMCPAdapter.run()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: verifiers
|
|
3
|
-
Version: 0.4.2.
|
|
3
|
+
Version: 0.4.2.dev57
|
|
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=
|
|
3
|
-
verifiers/v1/agent.py,sha256=
|
|
2
|
+
verifiers/v1/__init__.py,sha256=uBxLATpzAgN-Wi_j2_4yoh1JOitrJFQun2y33emEPRk,18870
|
|
3
|
+
verifiers/v1/agent.py,sha256=Qf4P2wJCJsWRmKTHFvICXuHIBQ2zpxrzHzzBVQWaxi4,49723
|
|
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
|
|
@@ -9,9 +9,9 @@ verifiers/v1/grading.py,sha256=RV-j71EIeQNC1AeKIDQkS1Y_KTtjJg9x8zF7n2cWr_Y,10100
|
|
|
9
9
|
verifiers/v1/graph.py,sha256=ifZoODILT1Ek7vM55VZrxHiJErrTvvz-Ihg7oolMTig,48271
|
|
10
10
|
verifiers/v1/harness.py,sha256=b4FDauO87VF6DfEyr0VgO8UvZB0weHZt9zPfgPiCe_c,17150
|
|
11
11
|
verifiers/v1/judge.py,sha256=T-TyYVcLGIoyUADYKy_pCBj2CTLhERlct5pmmWqPpTA,10507
|
|
12
|
-
verifiers/v1/rollout.py,sha256=
|
|
12
|
+
verifiers/v1/rollout.py,sha256=4dBl8wue2S49w0dbGk9b4-WMUaE86Izn4fagMRq3cz4,49994
|
|
13
13
|
verifiers/v1/semantic.py,sha256=nqKPPUoPL5Oh8Es_XjtcbDiQiIMKTYayXEm-EPB-jAE,5129
|
|
14
|
-
verifiers/v1/session.py,sha256=
|
|
14
|
+
verifiers/v1/session.py,sha256=rxAiQpRtUqveKKyVPTVHPNOzAv4dZcEKzQutRbEkHKo,30873
|
|
15
15
|
verifiers/v1/state.py,sha256=EckF2bWp-vV4b1jYJ9sLI5xrfGuI5spIgYYwW926toI,595
|
|
16
16
|
verifiers/v1/submission.py,sha256=zgSRbGVz82Efwz4nX4tlJ-i02AmjtKyu_vHfwfLaByw,7989
|
|
17
17
|
verifiers/v1/task.py,sha256=zcWjBjhJrkGIL29JTnxxw6v2pbJoiek_tF5RVAVV2ZY,15919
|
|
@@ -27,9 +27,9 @@ verifiers/v1/cli/resolve.py,sha256=Q1EHM7wWQo0YkwJA898qtZbYLaIkjIVq3Q7kUp2YIxs,4
|
|
|
27
27
|
verifiers/v1/cli/resume.py,sha256=hqV5AxxqeIInJeEZQerQznuijhMNijFEFcHZIltfLdE,470
|
|
28
28
|
verifiers/v1/cli/run.py,sha256=fB3OyDGjj5leA0kCIuKiiMxJfhv_4afIUwT9_KDXXuE,4988
|
|
29
29
|
verifiers/v1/cli/validate.py,sha256=IXvY9Ey7snPc6pJCX9QlGO_t9KFYRwcIVj0G5TFDanU,21038
|
|
30
|
-
verifiers/v1/clients/__init__.py,sha256=
|
|
30
|
+
verifiers/v1/clients/__init__.py,sha256=3rXv205sRheGvG8yNDmFwpq8qK9dlt7S_ia1zGWhNk0,598
|
|
31
31
|
verifiers/v1/clients/base.py,sha256=C0G5lRm3nxt1xmPoA2cweBgCnN2KcLepmCYq1vdDrnU,1691
|
|
32
|
-
verifiers/v1/clients/client.py,sha256=
|
|
32
|
+
verifiers/v1/clients/client.py,sha256=STtNVV8h-ZOtBtr1JH-NxXfuiY7Fehiw-l8hFmUTnq4,7880
|
|
33
33
|
verifiers/v1/clients/eval.py,sha256=GgpHZGh4IW3gC-tOZiFPp62MCL4aHik0b4afz2g3-Qo,8729
|
|
34
34
|
verifiers/v1/clients/prompt_cache.py,sha256=shJhbTUwKwao6m3DsYDyHPWmhXSJJnXk3wYQhzXFsnY,11849
|
|
35
35
|
verifiers/v1/clients/train.py,sha256=L6XDRUbOxkhtN6nt3sGqeAiHTfqNYdXdQewY9tQ6f8k,21134
|
|
@@ -120,10 +120,10 @@ verifiers/v1/harnesses/utils/install.py,sha256=EESYSh_e9L4gj6N4GvAbQY2kb4ckven7t
|
|
|
120
120
|
verifiers/v1/harnesses/utils/launch.py,sha256=2KuLnNruUqH6vcW2Ru661P86ffRzaqslNs-kDMn7B6U,5670
|
|
121
121
|
verifiers/v1/harnesses/utils/mcp.py,sha256=EtDraHEqgsOB6xKvcF2z9C6HlQyKoST0ZDvmy47NWgM,7450
|
|
122
122
|
verifiers/v1/harnesses/utils/replay.py,sha256=RJMzD-3K0oz_Q0zhjSH4nhwxn95R8e9Q_CCN5sZp9RA,1720
|
|
123
|
-
verifiers/v1/interception/__init__.py,sha256=
|
|
123
|
+
verifiers/v1/interception/__init__.py,sha256=jQ9ZbUr4Nx9JFhdcx0rNcR_jkMFcdzBrTpeSFK84YF0,4020
|
|
124
124
|
verifiers/v1/interception/base.py,sha256=KlXpWgcpAs_vzJxXRTVArZ9ilSV_vNfsX6vlZ35Y7kc,2249
|
|
125
125
|
verifiers/v1/interception/pool.py,sha256=Ao3iFTOcPZDfTfPH_sApVzA23u-FIaX6-FPIKOWo3c8,6701
|
|
126
|
-
verifiers/v1/interception/server.py,sha256=
|
|
126
|
+
verifiers/v1/interception/server.py,sha256=m4NQTpx--TX35AWX7gR1kLOxNZiUpTCUyEVrGeBX5Ck,53496
|
|
127
127
|
verifiers/v1/interception/tunnel/__init__.py,sha256=4ZqR9F7cmLUg17qvk4sXtLpWAN4epdiMgA2l9jetMbU,721
|
|
128
128
|
verifiers/v1/interception/tunnel/base.py,sha256=UrHXwbpB_qdh4WHWZHpi2D-wEHcHgg06_0U66XFqm3M,2370
|
|
129
129
|
verifiers/v1/interception/tunnel/custom.py,sha256=SJ3F592zwmrLKrbNktWgkB_84Xfozf6tUWoGmWCitLk,817
|
|
@@ -135,9 +135,9 @@ verifiers/v1/judges/reference.txt,sha256=Ej35kGXiT2uJ0LcHIeez49rCS_9uHmCQKoVdn93
|
|
|
135
135
|
verifiers/v1/judges/rubric.py,sha256=yRaOnc6S6cqrLuySkMsgxsBFCRUA2bBjYSa5qOT-inQ,16158
|
|
136
136
|
verifiers/v1/judges/rubric.txt,sha256=3KA2ZeYYdcDweJhUGopxu9EFgARhu2aWft5S5cj8Bc8,323
|
|
137
137
|
verifiers/v1/mcp/__init__.py,sha256=zJw_R6n-rDqB80_Zs1VGCrYVCZGi8nS7qGaSUKFsB50,479
|
|
138
|
-
verifiers/v1/mcp/launch.py,sha256=
|
|
138
|
+
verifiers/v1/mcp/launch.py,sha256=tI4MGpqWVJxALD9RxajBPcQrIhQvxA5r1slU8nwCjNw,29151
|
|
139
139
|
verifiers/v1/mcp/server.py,sha256=9hH7rJm8yPYVitcKYMZmSt6_JQyysKAr3e6Xav6IsIk,14154
|
|
140
|
-
verifiers/v1/mcp/toolset.py,sha256=
|
|
140
|
+
verifiers/v1/mcp/toolset.py,sha256=52h0tyCk_Eiu54JZ5hlQMfOlu5Dou7PHKmFr09pYFJg,3129
|
|
141
141
|
verifiers/v1/runtimes/__init__.py,sha256=JrBktZBcRLSnnZh_Er9IuGOVBGYUybJSPHi1q_b-UrI,3386
|
|
142
142
|
verifiers/v1/runtimes/base.py,sha256=Xl5jxNGnNhuWnrgh3h-nDOeMA9UX9MysYLmSuJPZQL4,17215
|
|
143
143
|
verifiers/v1/runtimes/compose.py,sha256=Q_0auxhXaGhIOrlisFXI8QRYV9DmewVuXG4ZZtfnrKA,15974
|
|
@@ -145,7 +145,7 @@ verifiers/v1/runtimes/deployment.py,sha256=De6N15Vfe7JKn5VOqFwG22SU_lh0f09bJ57hq
|
|
|
145
145
|
verifiers/v1/runtimes/egress.py,sha256=4zsNS3Z2A2HyoCcbgaLizA30uJabYrbgYAYUfvyzeBk,23703
|
|
146
146
|
verifiers/v1/runtimes/limiters.py,sha256=RWR4HdYoa72yeWF_lM7YRLflm10euE3_gPfNG0BuaOc,2742
|
|
147
147
|
verifiers/v1/runtimes/native_compose.py,sha256=8WBqWqyYWtohcrE_iq8SuuxsDFgK4Ncos8DxQS7FL_A,42335
|
|
148
|
-
verifiers/v1/runtimes/private_network.py,sha256=
|
|
148
|
+
verifiers/v1/runtimes/private_network.py,sha256=69ad7-FuGOK9irTO0Iut4JQ23YQMiVzQVYbCVRmF1IM,6717
|
|
149
149
|
verifiers/v1/runtimes/runtime.py,sha256=U_0G8DkeTPoyxQRN6Qmjll6FZ0bDwlijW4cC11wMbw4,10669
|
|
150
150
|
verifiers/v1/runtimes/strategies.py,sha256=WtIrIpKmvjvqpUfwLUwDNJcgRLE8d-2sx7reks2S2PA,8765
|
|
151
151
|
verifiers/v1/runtimes/backends/custom.py,sha256=Iz1Brd4dBTpO1zYVc2KA0u5sxz5ZUROY_Cdme5W33hM,2875
|
|
@@ -154,8 +154,8 @@ verifiers/v1/runtimes/backends/prime.py,sha256=-AAPG0aUvyK8G-7Y6xII5Uwwod537HfL_
|
|
|
154
154
|
verifiers/v1/runtimes/backends/subprocess.py,sha256=naOWJGmcaOlu2ZdRbUwhJicJdxASDRAUhDT0jzDff3w,8591
|
|
155
155
|
verifiers/v1/tasksets/__init__.py,sha256=2ijE3qIlLoUA02g6iysOwWQylyBBQL1GhSpjv8_bp0w,521
|
|
156
156
|
verifiers/v1/tasksets/harbor/__init__.py,sha256=FjW4tM3rgGALMK-8p7ux26G4-d4ZFVmaAmO6Fni6e_g,214
|
|
157
|
-
verifiers/v1/tasksets/harbor/taskset.py,sha256=
|
|
158
|
-
verifiers/v1/tasksets/harbor/toolset.py,sha256=
|
|
157
|
+
verifiers/v1/tasksets/harbor/taskset.py,sha256=ddUoeAPFDMg5injOeSYTVIE0lStUyjV6KauxEFIiTXQ,43670
|
|
158
|
+
verifiers/v1/tasksets/harbor/toolset.py,sha256=l-h1GATE9HLnEjb844CzBAiVLkPmE-XarjBlQ2ec5gM,3969
|
|
159
159
|
verifiers/v1/tasksets/nemo_gym/__init__.py,sha256=654gAvG3Wd_Z_nh6mypeKn4s_IIQ0Ge6vcZvxTHC2_E,306
|
|
160
160
|
verifiers/v1/tasksets/nemo_gym/response.py,sha256=EhrsquEP8g0bjzAThGfE6Ypgy86_nVX235NiFYtVDVM,4463
|
|
161
161
|
verifiers/v1/tasksets/nemo_gym/server.py,sha256=33C-VDZxPtMV2TFxJVIKijmtBLNlVeRs92ctPE3qAsM,2036
|
|
@@ -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.
|
|
192
|
-
verifiers-0.4.2.
|
|
193
|
-
verifiers-0.4.2.
|
|
194
|
-
verifiers-0.4.2.
|
|
195
|
-
verifiers-0.4.2.
|
|
191
|
+
verifiers-0.4.2.dev57.dist-info/METADATA,sha256=2gLhXMX0xp_XbaXDtQtLNDdQLhFCLqu4SULkPXoQG3g,5116
|
|
192
|
+
verifiers-0.4.2.dev57.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
193
|
+
verifiers-0.4.2.dev57.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
|
|
194
|
+
verifiers-0.4.2.dev57.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
|
|
195
|
+
verifiers-0.4.2.dev57.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|