Files
trinity-rl/envs/nemotron_tool_calling/nemotron_tool_calling_v1/harness.py
T
carstenandClaude Opus 5.5 609e832572 Move to current prime-rl, verifiers and renderers; DeepSeek V4.1 support
Bump prime-rl to trinity-dsv41: upstream main, PR #4057 (DeepSeek V4.1
Flash) with the engram port onto the shared n-gram module, and renderers
tracking its trinity-dsv41 branch (v0.2.0 + the Hermes parser).

Port the envs to the current verifiers v1 API, rl.toml to the new config
schema (IPO loss kept as the new default), and bootstrap/launch/prepare
scripts to the new layout.

Decensor now runs DecensorEnv: the simulated user writes reviewed
follow-ups up to each row's target_turns and every assistant turn is
judged. Earlier runs trained on the first turn only.
tests/test_multiturn_env.py drives the full loop against a mock endpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 14:39:44 +00:00

59 lines
2.3 KiB
Python

"""One native next-action request, captured by verifiers without tool dispatch."""
from typing import Literal
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 NativeToolCallingHarnessConfig(vf.HarnessConfig):
dialect: Literal["chat_completions"] = "chat_completions"
"""The one request goes out as a chat completion with native `tools`."""
class NativeToolCallingHarness(vf.Harness[NativeToolCallingHarnessConfig]):
APPENDS_SYSTEM_PROMPT = True
EXECUTES_CODE = False
# The loop runs in-process and only talks to the interception endpoint, so it runs
# on the subprocess runtime like the bundled `null` harness.
NEEDS_CONTAINER = False
async def launch(
self,
ctx: ModelContext,
trace: vf.Trace,
runtime: Runtime,
endpoint: str,
secret: str,
mcp_urls: dict[str, str],
data: vf.TaskData,
) -> 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(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 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="")