### Quick Start Training Process (Bash) Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/on-distill-agent/CLAUDE.md This snippet provides a quick start guide for the project, covering dataset conversion and initiating the training process. It assumes the environment is already set up and dependencies are installed. ```bash # 1. Convert the dataset (605 samples) python convert_dataset.py # 2. Run training rnow run ``` -------------------------------- ### Full RL Configuration Example (YAML) Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md An exhaustive example of an RL configuration file, covering project identification, data, model (including QLoRA options), RL algorithm specifics, rollout parameters, trainer settings, and optional run-dependent evaluations. ```yaml # Project identification (auto-filled on first run) project_id: "" project_name: "My RL Project" dataset_type: rl organization_id: "" description: "Training description" # Data configuration data: train_file: train.jsonl # Path to training data batch_size: 16 # 1-32, prompts per batch group_size: 4 # 1-64, rollouts per prompt (RL only) # NOTE: batch_size * group_size <= 2048 # Model configuration model: path: Qwen/Qwen3-8B # Model name or finetuned model UUID qlora_rank: 32 # LoRA rank (model-specific max) qlora_alpha: 64 # LoRA alpha (default: rank * 2) name: "custom-model-name" # Optional output name description: "Model desc" # Optional description # RL algorithm (RL only) algorithm: loss_fn: ppo # 'ppo' or 'importance_sampling' adv_estimator: grpo # 'grpo', 'gae', or 'reinforce' kl_penalty_coef: 0.01 # KL divergence penalty # Rollout configuration (RL and Distillation) rollout: max_turns: 1 # Max conversation turns max_context_window: 32768 # Max context window in tokens (tool results auto-truncated) termination_policy: last_tool # 'last_tool' or 'max_turns' reasoning_mode: null # null, 'disabled', 'low', 'medium', 'high' mcp_url: null # MCP server URL(s) tool_timeout: 60 # Tool execution timeout (seconds) reward_timeout: 60 # Reward execution timeout (seconds) max_tool_response: null # Max tokens for tool responses (null = no limit) include_thinking: false # Include in history rollout_timeout: null # Hard wall-clock deadline per rollout (null = 1hr safety net) # Training configuration trainer: num_epochs: 30 # Number of epochs learning_rate: 0.0001 # Learning rate save_step: -1 # -1 = end only, N = every N steps max_billing: 10.0 # Optional: max dollars for this run # Run-dependent evals (optional, top-level) evals: - eval_id: your_eval_id # From standalone eval step: 100 # Run every 100 steps name: "MATH" # Display name in graphs (optional) ``` -------------------------------- ### Quick Start CLI Commands Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/project8/CLAUDE.md Provides a quick start guide for training a model using the reinforcement learning CLI. It includes steps for preparing data, testing locally, and initiating the training process. ```bash # 1. Prepare train.jsonl and rewards.py # 2. Test locally rnow test -n 3 --verbose # 3. Train rnow run ``` -------------------------------- ### Quick Start CLI Commands for RL Training Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/rl-tools/CLAUDE.md These bash commands outline the quick start process for training an RL agent with tools. It covers preparing necessary files, testing the setup locally, and initiating the training process. ```bash # 1. Prepare train.jsonl, rewards.py, and tools.py # 2. Test locally rnow test -n 3 --verbose # 3. Train rnow run ``` -------------------------------- ### Setup Environment Configuration Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/kernel/CLAUDE.md Initializes the environment variables required for the Kernel and OpenAI API keys. Users must copy the example environment file and populate it with valid credentials. ```bash cp example.env .env # Add KERNEL_API_KEY and OPENAI_API_KEY ``` -------------------------------- ### Setup and Run ReinforceNow CLI Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/first-rl/CLAUDE.md Commands to install project dependencies using the uv package manager and execute the ReinforceNow CLI for testing and training workflows. ```bash # Install dependencies uv pip install -r requirements.txt # Run rnow commands uv run rnow test -n 3 --verbose uv run rnow run ``` -------------------------------- ### Setup Python Environment and Install Dependencies (Bash) Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/on-distill-agent/CLAUDE.md This snippet outlines the steps to set up a Python 3.11+ virtual environment using `uv` and install the `datasets` library for data conversion. It ensures the correct Python version and necessary packages are available for subsequent data processing. ```bash # 1. Create venv with Python 3.11+ using uv uv venv --python 3.11 # 2. Activate the venv source .venv/bin/activate # 3. Install dependencies for dataset conversion uv pip install datasets ``` -------------------------------- ### Install ReinforceNow CLI and Dependencies Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/README.md Commands to install the uv package manager, set up a virtual environment, and install the rnow CLI package. ```bash # macOS/Linux: curl -LsSf https://astral.sh/uv/install.sh | sh # Windows: powershell -c "irm https://astral.sh/uv/install.ps1 | iex" ``` ```bash uv init && uv venv --python 3.11 source .venv/bin/activate # Windows: .\.venv\Scripts\Activate.ps1 uv pip install rnow ``` -------------------------------- ### Install ReinforceNow CLI Source: https://context7.com/reinforcenow/reinforcenow-cli/llms.txt Installation instructions for the ReinforceNow package using either uv or pip package managers. ```bash # Install with uv (recommended) uv init && uv venv --python 3.11 source .venv/bin/activate uv pip install rnow # Or with pip pip install rnow ``` -------------------------------- ### ReinforceNow CLI Testing Commands Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md Shell commands demonstrating how to use the ReinforceNow CLI for testing configurations. Includes examples for validating and testing locally, testing specific entries, and overriding the model for testing purposes. ```bash # Validate and test locally rnow test -n 3 --verbose # Test specific entries rnow test --entry 0,1,2 # Override model for testing rnow test --model gpt-5-nano ``` -------------------------------- ### Minimal Distillation Configuration (YAML) Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md Configures a basic setup for on-policy distillation training. Specifies project name, dataset type, data parameters, student and teacher model paths, and trainer settings. No rewards.py is needed as the teacher provides supervision. ```yaml project_name: "My Distillation Project" dataset_type: distill data: train_file: train.jsonl batch_size: 8 group_size: 4 model: path: Qwen/Qwen3-8B # Student model teacher: path: Qwen/Qwen3-32B # Teacher model (larger) rollout: max_context_window: 8192 trainer: num_epochs: 3 learning_rate: 0.0001 ``` -------------------------------- ### Implementing Basic and Sandbox Tools Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/tutorial-tool/CLAUDE.md Examples of standard tool implementation versus sandbox-isolated tools. Sandbox tools require specific Docker configuration in the training data. ```python @tool def calculator(expression: str) -> float: """Evaluate a math expression.""" return eval(expression) @tool(sandbox=True) def run_python(code: str) -> str: """Run Python code in sandbox.""" exec(code) return "Success" ``` -------------------------------- ### Convert Datasets to train.jsonl Format Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md Python scripts to transform HuggingFace datasets into the train.jsonl format required by ReinforceNow. Includes examples for SFT (Supervised Fine-Tuning) with standard, Alpaca-style, and multi-turn formats, as well as RL (Reinforcement Learning) data preparation. ```python from datasets import load_dataset import json # SFT Conversion dataset = load_dataset("your-dataset-name", split="train") with open("train.jsonl", "w") as f: for row in dataset: entry = { "messages": [ {"role": "user", "content": row["question"]}, {"role": "assistant", "content": row["answer"]} ] } f.write(json.dumps(entry) + "\n") ``` ```python from datasets import load_dataset import json # Alpaca-style Conversion dataset = load_dataset("tatsu-lab/alpaca", split="train") with open("train.jsonl", "w") as f: for row in dataset: user_content = f"{row['instruction']}\n\nInput: {row['input']}" if row.get("input") else row["instruction"] entry = { "messages": [ {"role": "user", "content": user_content}, {"role": "assistant", "content": row["output"]} ] } f.write(json.dumps(entry) + "\n") ``` ```python # Multi-turn Conversion messages = [] for turn in row["conversations"]: role = "user" if turn["from"] == "human" else "assistant" messages.append({"role": role, "content": turn["value"]}) entry = {"messages": messages} ``` ```python from datasets import load_dataset import json # RL Conversion dataset = load_dataset("your-math-dataset", split="train") with open("train.jsonl", "w") as f: for row in dataset: entry = { "messages": [{"role": "user", "content": row["question"]}], "rewards": ["accuracy"], "metadata": {"expected_answer": row["answer"]} } f.write(json.dumps(entry) + "\n") ``` -------------------------------- ### SFT for Instruction Following Configuration Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md This YAML configuration is for Supervised Fine-Tuning (SFT) of a model for instruction following. It sets up the dataset, model path with QLoRA rank, and trainer parameters for a standard SFT process. ```yaml project_name: "Instruction Tuning" dataset_type: sft data: train_file: train.jsonl batch_size: 8 val_split: 0.1 model: path: Qwen/Qwen3-8B qlora_rank: 32 trainer: num_epochs: 3 learning_rate: 0.00005 ``` -------------------------------- ### Example Training Data Format (train.jsonl) Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/project8/CLAUDE.md Illustrates the expected format for the `train.jsonl` file, which contains training prompts and their associated reward assignments. This format is crucial for the reinforcement learning training process. ```json {"messages": [{"role": "user", "content": "What is 2+2?"}], "rewards": ["accuracy"], "metadata": {"answer": "4"}} ``` -------------------------------- ### Configure Tool Calls and Sandbox Environments Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-train-jsonl/SKILL.md Examples demonstrating how to integrate tool calls into training data and configure Docker containers for sandbox execution. These configurations are essential for agentic distillation and isolated code execution tasks. ```json { "messages": [ {"role": "user", "content": "Find the weather in Paris"}, {"role": "assistant", "content": "", "tool_calls": [{"id": "call_1", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\": \"Paris\"}"}}]}, {"role": "tool", "tool_call_id": "call_1", "content": "72°F, sunny"}, {"role": "assistant", "content": "The weather in Paris is 72°F and sunny."} ] } ``` ```json { "messages": [{"role": "user", "content": "Write and run a Python script"}], "rewards": ["code_runs", "output_correct"], "tools": ["execute_python"], "docker": "python:3.11-slim" } ``` -------------------------------- ### Install Dependencies Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/project8/README.md Required package for mathematical verification within the ReinforceNow training pipeline. ```text math-verify==0.5.0 ``` -------------------------------- ### Minimal RL Configuration (YAML) Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md Sets up a basic configuration for Reinforcement Learning training. Requires project name, dataset type, training file path, batch size, model path, and trainer epochs/learning rate. ```yaml project_name: "My RL Project" dataset_type: rl data: train_file: train.jsonl batch_size: 4 group_size: 8 model: path: Qwen/Qwen3-8B trainer: num_epochs: 10 learning_rate: 0.0001 ``` -------------------------------- ### Training Configuration Example (YAML) Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/on-distill-agent/CLAUDE.md This YAML snippet illustrates key configuration options for the distillation training process. It includes settings for dataset type, teacher model path, KL penalty coefficient, and maximum turns for agentic behavior. ```yaml dataset_type: distill # Enables distillation mode teacher: path: Qwen/Qwen3-32B # Teacher model (use HuggingFace ID) algorithm: kl_penalty_coef: 0.1 # β - KL penalty weight rollout: max_turns: 4 # Allow multiple browse iterations ``` -------------------------------- ### Math Reasoning Configuration Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md A YAML configuration file for setting up a Reinforcement Learning project focused on Math Reasoning. It specifies dataset paths, model details (including QLoRA rank), PPO algorithm settings, and rollout parameters optimized for complex reasoning tasks. ```yaml project_name: "Math Reasoning" dataset_type: rl data: train_file: train.jsonl batch_size: 8 group_size: 8 model: path: Qwen/Qwen3-8B qlora_rank: 64 algorithm: loss_fn: ppo adv_estimator: grpo kl_penalty_coef: 0.01 rollout: max_turns: 1 max_context_window: 8192 # High for reasoning reasoning_mode: medium trainer: num_epochs: 20 learning_rate: 0.0001 ``` -------------------------------- ### Install ReinforceNow CLI Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-cli/SKILL.md Installs the ReinforceNow CLI package using pip. ```bash pip install rnow ``` -------------------------------- ### Implement /terminate.sh Cleanup Script Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/dockerfile/SKILL.md Examples for implementing the /terminate.sh script to handle resource cleanup before container termination. Includes specific implementations for Kernel browser sessions, database connections, and generic cleanup tasks. ```bash # Generic cleanup example #!/bin/bash # /terminate.sh - generic cleanup echo "Running cleanup..." # Kill any background processes pkill -f "my-server" || true # Remove temp files rm -rf /tmp/session_* || true # Notify external service curl --max-time 5 -X POST "https://api.example.com/cleanup" \ -d '{"container_id": "'$HOSTNAME'"}' || true echo "Cleanup complete" ``` ```bash # Kernel browser session cleanup #!/bin/bash if [ -f /tmp/kernel_session_id ]; then SESSION_ID=$(cat /tmp/kernel_session_id) curl -sS --max-time 10 -X DELETE \ "https://api.onkernel.com/browsers/$SESSION_ID" \ -H "Authorization: Bearer $KERNEL_API_KEY" || true fi ``` -------------------------------- ### Configure Teacher Model for Distillation Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md Sets up a teacher model to provide supervision via reverse KL divergence. Enabling agentic mode allows for multi-turn tool support during the distillation process. ```yaml teacher: path: Qwen/Qwen3-32B # 32B teacher distilling to 8B student agentic: true # Enable if using tools.py ``` -------------------------------- ### Configure Multi-Model Training Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md Demonstrates how to define multiple target models in a single configuration file. The CLI will automatically trigger separate training runs for each specified model path. ```yaml model: path: - Qwen/Qwen3-4B-Instruct-2507 - Qwen/Qwen3-8B - Qwen/Qwen3-30B-A3B qlora_rank: 32 ``` -------------------------------- ### Minimal SFT Configuration (YAML) Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md Defines a minimal configuration for Supervised Fine-Tuning (SFT) training. Includes project name, dataset type, training file, batch size, validation split, model path, and trainer settings. ```yaml project_name: "My SFT Project" dataset_type: sft data: train_file: train.jsonl batch_size: 4 val_split: 0.2 model: path: Qwen/Qwen3-8B trainer: num_epochs: 10 learning_rate: 0.0001 ``` -------------------------------- ### Distillation for Reasoning Configuration Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md A YAML configuration for distilling reasoning capabilities from a larger teacher model to a smaller student model. It includes settings for both student and teacher models, dataset, and trainer parameters, emphasizing on-policy distillation. ```yaml project_name: "Distilled Reasoning Model" dataset_type: distill data: train_file: train.jsonl batch_size: 8 group_size: 4 model: path: Qwen/Qwen3-8B # Student qlora_rank: 32 teacher: path: Qwen/Qwen3-32B # Teacher rollout: max_context_window: 8192 # Enough for reasoning trainer: num_epochs: 3 learning_rate: 0.0001 save_step: 20 ``` -------------------------------- ### Quick Start Commands for ReinforceNow CLI Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/rl-browser/CLAUDE.md These commands initiate testing and full training of the RL browser agent using the ReinforceNow CLI. The `-n` flag controls the number of samples for testing, and `--verbose` provides detailed output. ```bash # Test locally with a few samples rnow test -n 3 --verbose # Run full training rnow run ``` -------------------------------- ### Verify mathematical expressions using math-verify Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-rewards/SKILL.md Uses the math-verify library to perform deterministic LaTeX-aware mathematical equivalence checks. Requires math-verify to be installed in the environment. ```python from math_verify import LatexExtractionConfig, parse, verify from rnow.core import RewardArgs, get_response, reward @reward def accuracy(args: RewardArgs, messages: list) -> float: gold = parse(args.metadata["expected_answer"]) pred = parse( get_response(messages), extraction_config=[LatexExtractionConfig(boxed_match_priority=0)] ) if not pred: return 0.0 return 1.0 if verify(gold, pred) else 0.0 ``` -------------------------------- ### Execute ReinforceNow CLI Commands Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/posttrain/CLAUDE.md Use these commands to validate your training data locally and initiate the training process. The 'test' command verifies the data format, while the 'run' command starts the full training job. ```bash # Test locally (validates data format) uv run rnow test -n 1 --verbose # Start training uv run rnow run ``` -------------------------------- ### Configure MCP Servers for Rollout Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md Configures external Model Context Protocol (MCP) servers for tool access during rollouts. Supports single endpoints, multiple server lists, or local sandbox connections. ```yaml # Single server rollout: mcp_url: "https://mcp.tavily.com/mcp/?tavilyApiKey=YOUR_KEY" # Multiple servers rollout: mcp_url: - "https://mcp.tavily.com/mcp/?tavilyApiKey=..." - "https://mcp.exa.ai/mcp/?apiKey=..." # In-sandbox MCP (requires docker in train.jsonl) rollout: mcp_url: localhost:8931 ``` -------------------------------- ### Example Training Data Format (train.jsonl) Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/rl-tools/CLAUDE.md This JSON snippet shows the expected format for the `train.jsonl` file, which contains training prompts, associated rewards, and available tools. The `tools` field is optional and filters which tools can be used during training. ```json {"messages": [{"role": "user", "content": "Search for AI news"}], "rewards": ["relevance"], "tools": ["web_search"]} ``` -------------------------------- ### Agent with Tools Configuration Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md This YAML configuration defines parameters for an RL agent designed to use tools. It includes settings for dataset loading, model path, and rollout parameters like maximum turns, context window size, and tool termination policy, suitable for agents interacting with external tools. ```yaml project_name: "Search Agent" dataset_type: rl data: train_file: train.jsonl batch_size: 4 group_size: 4 model: path: Qwen/Qwen3-8B rollout: max_turns: 5 max_context_window: 32768 termination_policy: last_tool tool_timeout: 30 trainer: num_epochs: 15 learning_rate: 0.0001 ``` -------------------------------- ### Initialize and Run ReinforceNow Projects Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/README.md Commands to authenticate the CLI, initialize a new project from a template, and execute a training run. ```bash rnow login rnow init --template sft rnow run ``` -------------------------------- ### Initialize Projects Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-cli/SKILL.md Creates a new training project from a predefined template. Supports specifying the template type and project name. ```bash rnow init --template sft --name "my-sft-project" rnow init --template rl-tools rnow init --template tutorial-reward ``` -------------------------------- ### Stateless Tool Function Example in Python Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-tools/SKILL.md Provides an example of a stateless tool function, `calculator`, designed for operations that do not modify state, such as performing mathematical calculations. It evaluates a given mathematical expression and returns the result or an error message. ```python from rnow.core.tool import tool @tool def calculator(expression: str) -> dict: """Evaluate a mathematical expression. Args: expression: Math expression like "2 + 3 * 4" """ try: allowed = set("0123456789+-*/.() ") if not all(c in allowed for c in expression): return {"error": "Invalid characters"} return {"result": eval(expression)} except Exception as e: return {"error": str(e)} ``` -------------------------------- ### Tool Function Definition Example (tools.py) Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/rl-tools/CLAUDE.md This Python code demonstrates how to define a tool function using the `@tool` decorator from `rnow.core`. The example shows a `web_search` function that takes a query and returns a string, simulating a web search result. ```python from rnow.core import tool @tool def web_search(query: str) -> str: """Search the web for information.""" # Implementation return "Search results..." ``` -------------------------------- ### Execute Off-Policy Distillation Workflow Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/off-distill-agent/CLAUDE.md Executes the full pipeline for distillation, starting from dataset preparation to model training via the rnow CLI. ```bash # Workflow 1: HuggingFace Dataset python convert_hf_dataset.py --max-samples 1000 rnow run # Workflow 2: Teacher Rollouts rnow test -n 100 --model gpt-5.2 python convert_rollouts.py rnow run ``` -------------------------------- ### Precondition Reward Function (Python) Source: https://context7.com/reinforcenow/reinforcenow-cli/llms.txt A precondition reward function that acts as a gate. If it returns 0, the total reward is 0. This example checks if at least one tool was used. ```python @reward(precondition=True) async def used_tools(args: RewardArgs, messages: list) -> float: """Gate: must use at least one tool to get any reward.""" for msg in messages: if msg.get("role") == "assistant" and msg.get("tool_calls"): return 1.0 return 0.0 ``` -------------------------------- ### Standard Sandbox Dockerfile Template Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/dockerfile/SKILL.md A template demonstrating the required /start.sh and /terminate.sh scripts to ensure services initialize correctly and the container remains alive via sleep infinity. ```dockerfile FROM some-image:latest EXPOSE 8931 USER root # /start.sh: Called at container startup with "sleep infinity" as args RUN echo '#!/bin/bash' > /start.sh && \ echo 'set -e' >> /start.sh && \ echo 'your-server-command --port 8931 &' >> /start.sh && \ echo 'sleep 3' >> /start.sh && \ echo 'exec "$@"' >> /start.sh && \ chmod +x /start.sh # /terminate.sh: Called automatically before sandbox termination RUN echo '#!/bin/bash' > /terminate.sh && \ echo 'echo "Cleaning up..."' >> /terminate.sh && \ echo '# YOUR CLEANUP CODE HERE' >> /terminate.sh && \ chmod +x /terminate.sh ENTRYPOINT ["/start.sh"] CMD ["sleep", "infinity"] ``` -------------------------------- ### Sandbox Reward Function (Python) Source: https://context7.com/reinforcenow/reinforcenow-cli/llms.txt A reward function that runs inside a Docker container, allowing it to access files created during tool execution. This example tests generated Python code using pytest. ```python @reward(sandbox=True, timeout=120) async def test_code(args: RewardArgs, messages: list) -> float: """Run pytest on code generated by the model.""" import subprocess result = subprocess.run( ["pytest", "-q", "/workspace/solution.py"], capture_output=True, timeout=60 ) return 1.0 if result.returncode == 0 else 0.0 ``` -------------------------------- ### Validate and Clamp Reward Values Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-rewards/SKILL.md Examples of common implementation mistakes and the correct approach to ensuring reward values remain within the required 0.0 to 1.0 range. ```python @reward async def safe_score(args: RewardArgs, messages: list) -> float: score = calculate_score() # Might return any float return max(0.0, min(1.0, score)) # Clamp to 0-1 ``` -------------------------------- ### Build Docker Images for Sandbox Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-train-jsonl/SKILL.md Commands to build and push Docker images compatible with Modal's x86_64 architecture. Using the --platform flag is critical for ensuring compatibility during sandbox execution. ```bash docker build --platform linux/amd64 -t myorg/image:latest . docker push myorg/image:latest ``` -------------------------------- ### MCP Server Dockerfile Configuration Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/dockerfile/SKILL.md Example of configuring an MCP server (Playwright) to bind to 0.0.0.0 and allow external hosts to prevent 403 Forbidden errors in cloud tunnels. ```dockerfile FROM mcp/playwright EXPOSE 8931 USER root RUN echo '#!/bin/bash' > /start.sh && \ echo 'node cli.js --headless --browser chromium --no-sandbox --port 8931 --host 0.0.0.0 --allowed-hosts "*" &' >> /start.sh && \ echo 'sleep 5' >> /start.sh && \ echo 'exec "$@"' >> /start.sh && \ chmod +x /start.sh ENTRYPOINT ["/start.sh"] ``` -------------------------------- ### Initialize Kernel Browser Session Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/dockerfile/SKILL.md Creates a Kernel browser session and initiates replay recording during container startup. This script is intended to be executed within a Dockerfile to prepare the environment. ```bash RUN echo '#!/bin/bash' > /start.sh && \ echo 'set -e' >> /start.sh && \ echo 'RESP=$(curl -sS --max-time 60 -X POST "https://api.onkernel.com/browsers" -H "Authorization: Bearer $KERNEL_API_KEY" -H "Content-Type: application/json" -d "{\"timeout_seconds\": 300, \"headless\": false, \"viewport\": {\"width\": 1024, \"height\": 768}}")' >> /start.sh && \ echo 'SESSION_ID=$(echo "$RESP" | jq -r ".session_id")' >> /start.sh && \ echo 'echo "$SESSION_ID" > /tmp/kernel_session_id' >> /start.sh && \ echo 'curl -sS -X POST "https://api.onkernel.com/browsers/$SESSION_ID/replays" -H "Authorization: Bearer $KERNEL_API_KEY" -H "Content-Type: application/json" -d "{}" || true' >> /start.sh && \ echo 'exec "$@"' >> /start.sh && \ chmod +x /start.sh ``` -------------------------------- ### Evaluate models with ReinforceNow CLI Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-cli/SKILL.md Demonstrates how to run model evaluations using the 'rnow eval' command. Includes examples for specifying reasoning modes, overriding model parameters, and limiting sample sizes. ```bash # Eval finetuned model on existing eval rnow eval --eval-id cmle8ma5h000004l44thj3t3a \ --model 37e6f995-0efd-4fc6-beaa-badb7af94054 --pass1 # Eval with reasoning mode rnow eval --eval-id cmle8ma5h000004l44thj3t3a \ --model gpt-5.2 --reasoning-mode high --pass1 --pass8 # Eval from project directory with overrides rnow eval --model Qwen/Qwen3-8B --pass1 --pass8 \ --max-turns 5 --temperature 0.8 # Limit to first 50 samples rnow eval --eval-id cmxyz123 --model gpt-5-nano \ --pass1 --max-samples 50 ``` -------------------------------- ### Configure Run-Dependent Evaluations in YAML Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md Defines how to reference standalone evaluations within the training configuration. It specifies the eval ID, the frequency of execution in training steps, and optional display names for metrics. ```yaml evals: - eval_id: cmla1l13e000004jwxu39jrpy step: 100 name: "MATH" evals: - eval_id: abc123... step: 50 name: "MATH" - eval_id: xyz789... step: 100 name: "GSM8K" ``` -------------------------------- ### Background Service with Health Check Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/dockerfile/SKILL.md Demonstrates initializing a background service and waiting for a successful health check before allowing the container to proceed. ```dockerfile FROM some-image:latest USER root RUN echo '#!/bin/bash' > /start.sh && \ echo 'some-service &' >> /start.sh && \ echo 'for i in {1..30}; do curl -s http://localhost:PORT/health && break; sleep 1; done' >> /start.sh && \ echo 'exec "$@"' >> /start.sh && \ chmod +x /start.sh USER original-user ENTRYPOINT ["/start.sh"] ``` -------------------------------- ### Implement LLM Judge Reward Functions Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-rewards/SKILL.md Demonstrates how to use the llm_judge utility to evaluate model responses. Includes examples for simple numeric scoring and structured evaluation using custom JSON schemas. ```python from rnow.core import llm_judge @reward async def quality_score(args: RewardArgs, messages: list) -> float: """Use GPT to evaluate response quality.""" response = messages[-1]["content"] question = args.metadata["question"] prompt = f"""Rate this response on a scale of 0-1. Question: {question} Response: {response} Return only a number between 0 and 1.""" return llm_judge(prompt, secrets=args.secrets) ``` ```python @reward async def detailed_evaluation(args: RewardArgs, messages: list) -> float: """Detailed evaluation with custom schema.""" response = messages[-1]["content"] custom_schema = { "type": "object", "properties": { "accuracy": {"type": "integer", "minimum": 0, "maximum": 10}, "clarity": {"type": "integer", "minimum": 0, "maximum": 10}, "completeness": {"type": "integer", "minimum": 0, "maximum": 10} }, "required": ["accuracy", "clarity", "completeness"] } prompt = f"""Evaluate this response: {response} Rate accuracy, clarity, and completeness from 0-10.""" result = llm_judge( prompt, secrets=args.secrets, schema=custom_schema, model="gpt-5.2-nano" ) return result / 10.0 ``` -------------------------------- ### Retrieve supported base models Source: https://context7.com/reinforcenow/reinforcenow-cli/llms.txt A reference list of supported LLMs including Qwen, OpenAI, DeepSeek, Meta Llama, and Moonshot models available for training within the ReinforceNow environment. ```python # Qwen models "Qwen/Qwen3-235B-A22B-Instruct-2507" "Qwen/Qwen3-30B-A3B-Instruct-2507" "Qwen/Qwen3-30B-A3B" "Qwen/Qwen3-32B" "Qwen/Qwen3-8B" "Qwen/Qwen3-8B-Base" "Qwen/Qwen3-4B-Instruct-2507" # Vision-Language models "Qwen/Qwen3-VL-235B-A22B-Instruct" "Qwen/Qwen3-VL-30B-A3B-Instruct" # OpenAI reasoning models "openai/gpt-oss-120b" "openai/gpt-oss-20b" # DeepSeek models "deepseek-ai/DeepSeek-V3.1" "deepseek-ai/DeepSeek-V3.1-Base" # Meta Llama models "meta-llama/Llama-3.3-70B-Instruct" "meta-llama/Llama-3.1-8B-Instruct" "meta-llama/Llama-3.1-70B" "meta-llama/Llama-3.1-8B" "meta-llama/Llama-3.2-3B" "meta-llama/Llama-3.2-1B" # Moonshot models "moonshotai/Kimi-K2-Thinking" ``` -------------------------------- ### Define Agent Tools with @tool Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/README.md Shows how to register custom functions as tools that an agent can invoke during the training process. ```python from rnow.core import tool @tool def search(query: str, max_results: int = 5) -> dict: """Search the web for information.""" # Your implementation here return {"results": [...]} ``` -------------------------------- ### Agentic Training with Tools (JSON) Source: https://context7.com/reinforcenow/reinforcenow-cli/llms.txt Training entry for agentic models that can use tools. Specifies available tools, Docker sandbox configuration, and environment variables. ```json { "messages": [ {"role": "system", "content": "You are a research assistant with web access."}, {"role": "user", "content": "Find the capital of France."} ], "rewards": ["accuracy"], "tools": ["internet_search"], "docker": "local/researcher", "docker_env": {"API_KEY": "${SEARCH_API_KEY}"}, "metadata": {"expected_answer": "Paris"} } ``` -------------------------------- ### Reward Function Definition (rewards.py) Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/project8/CLAUDE.md Demonstrates how to define a custom reward function using Python in the `rewards.py` file. This example shows an 'accuracy' reward function that checks if the expected answer is present in the model's response. ```python from rnow.core import reward, RewardArgs @reward def accuracy(args: RewardArgs, messages: list) -> float: response = messages[-1]["content"] expected = args.metadata["answer"] return 1.0 if expected in response else 0.0 ``` -------------------------------- ### Code Execution Configuration Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-config/SKILL.md A YAML configuration for an RL agent focused on code execution tasks. It specifies the dataset, model, and rollout parameters, including a longer tool timeout to accommodate complex code execution environments. ```yaml project_name: "Code Agent" dataset_type: rl data: train_file: train.jsonl batch_size: 2 group_size: 4 model: path: Qwen/Qwen3-8B rollout: max_turns: 3 max_context_window: 32768 tool_timeout: 120 # Longer for code execution trainer: num_epochs: 10 learning_rate: 0.0001 ``` -------------------------------- ### Test Rewards Locally Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/skills/rnow-rewards/SKILL.md Command to execute local rollouts and view reward breakdowns for debugging purposes. ```bash rnow test -n 3 --verbose ``` -------------------------------- ### CLI Commands for Testing and Training Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/tutorial-tool/CLAUDE.md Commands to verify tool functionality with the model and initiate the training process. ```bash rnow test -n 3 --verbose rnow run ``` -------------------------------- ### Define Model Tools Source: https://context7.com/reinforcenow/reinforcenow-cli/llms.txt Demonstrates various tool implementations including basic math evaluation, external API integration (Wikipedia), sandboxed code execution, and browser automation for vision-language models. ```python from rnow.core import tool @tool def calculator(expression: str) -> dict: """Evaluate a mathematical expression and return the result.""" try: result = eval(expression, {"__builtins__": {}}, {}) return {"result": result, "success": True} except Exception as e: return {"error": str(e), "success": False} @tool def internet_search(query: str, max_results: int = 5) -> list: """Search Wikipedia and return results with title, link, and snippet.""" resp = requests.get( "https://en.wikipedia.org/w/api.php", params={ "action": "query", "list": "search", "srsearch": query, "format": "json", "srlimit": max_results, }, timeout=10, ) resp.raise_for_status() results = [] for item in resp.json().get("query", {}).get("search", []): results.append({ "title": item.get("title", ""), "link": f"https://en.wikipedia.org/wiki/{item['title'].replace(' ', '_')}", "snippet": item.get("snippet", "")[:200] }) return results @tool(sandbox=True, timeout=60) def run_python(code: str) -> str: """Execute Python code in isolated sandbox and return output.""" import subprocess import tempfile with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f: f.write(code) f.flush() result = subprocess.run( ["python", f.name], capture_output=True, text=True, timeout=30 ) if result.returncode == 0: return result.stdout return f"Error: {result.stderr}" @tool(sandbox=True) def click(coordinate: list[int]) -> dict: """Click at [x, y] coordinate (0-1000 scale).""" x = int(coordinate[0] / 1000 * 1024) y = int(coordinate[1] / 1000 * 768) execute_browser(f"await page.mouse.click({x}, {y})") screenshot_b64 = take_screenshot() return {"__vlm_image__": {"data": screenshot_b64, "format": "png"}} ``` -------------------------------- ### ReinforceNow Reward Function using math-verify for Accuracy Source: https://github.com/reinforcenow/reinforcenow-cli/blob/main/rnow/templates/tutorial-reward/CLAUDE.md An example of a reward function that uses the math-verify library to check the accuracy of a predicted mathematical answer against a gold standard answer. It parses both answers and uses the verify function. ```python from math_verify import parse, verify from rnow.core import reward, RewardArgs @reward def accuracy(args: RewardArgs, messages: list) -> float: gold = parse(args.metadata["answer"]) pred = parse(messages[-1]["content"]) return 1.0 if pred and verify(gold, pred) else 0.0 ``` -------------------------------- ### Utilize Context Data Models Source: https://context7.com/reinforcenow/reinforcenow-cli/llms.txt Shows how to access metadata and secrets within reward and tool functions using the RewardArgs and ToolArgs context objects. ```python from rnow.models import RewardArgs, ToolArgs @reward async def my_reward(args: RewardArgs, messages: list) -> float: expected = args.metadata.get("expected_answer") api_key = args.secrets.get("OPENAI_API_KEY") return 1.0 @tool def sql_query(args: ToolArgs, query: str) -> str: """Execute SQL query against the database specified in metadata.""" db_id = args.metadata.get("db_id") return execute_sql(db_id, query) ```