Migrated from the rl-toolkit snapshot deployed for the 2026-09-15 production run (toolkit e191cf1 plus uncommitted changes). PRIME-RL is now a submodule on dphn/prime-rl@trinity; the v0 envs, parity tests, OPD experiment, and old configs are not carried over.
51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
"""One native next-action request, captured by verifiers without tool dispatch."""
|
|
|
|
import verifiers.v1 as vf
|
|
from openai import AsyncOpenAI
|
|
from verifiers.v1.clients import ModelContext
|
|
from verifiers.v1.dialects.chat import message_to_wire
|
|
from verifiers.v1.runtimes import ProgramResult, Runtime
|
|
|
|
|
|
class NativeToolCallingHarness(vf.Harness[vf.HarnessConfig]):
|
|
APPENDS_SYSTEM_PROMPT = True
|
|
SUPPORTS_MESSAGE_PROMPT = True
|
|
EXECUTES_CODE = False
|
|
|
|
async def launch(
|
|
self,
|
|
ctx: ModelContext,
|
|
trace: vf.Trace,
|
|
runtime: Runtime,
|
|
endpoint: str,
|
|
secret: str,
|
|
mcp_urls: dict[str, str],
|
|
) -> ProgramResult:
|
|
if mcp_urls or self.config.disabled_tools:
|
|
raise ValueError(
|
|
"Next-action tasks require the complete recorded tool schema, without MCP dispatch"
|
|
)
|
|
system, prompt = self.resolve_prompt(trace.task.data)
|
|
messages = [{"role": "system", "content": system}] if system else []
|
|
if isinstance(prompt, str):
|
|
messages.append({"role": "user", "content": prompt})
|
|
else:
|
|
messages.extend(message_to_wire(message) for message in prompt or [])
|
|
tools = [
|
|
{"type": "function", "function": tool} for tool in trace.task.data.tool_defs
|
|
]
|
|
if not tools:
|
|
raise ValueError(
|
|
"Native tool-calling tasks must advertise at least one tool"
|
|
)
|
|
# This is the interception endpoint, not a direct provider request. A normal
|
|
# return ends the action with agent_completed, not a truncating max_turns stop.
|
|
async with AsyncOpenAI(base_url=endpoint, api_key=secret) as client:
|
|
await client.chat.completions.create(
|
|
model=ctx.model,
|
|
messages=messages,
|
|
tools=tools,
|
|
tool_choice="auto",
|
|
)
|
|
return ProgramResult(exit_code=0, stdout="", stderr="")
|