ReinforceNowReinforceNow

tools.py

Tools allow your model to call external functions during training. Define them in tools.py using the @tool decorator.

Usage

from rnow.core.tool import tool

@tool
def search(query: str) -> dict:
    """Search for information."""
    return {"results": ["result1", "result2"]}

Requirements

docstring: Required, describes what the tool does

type hints: All parameters and return type must be typed

return: Must be JSON-serializable (str, int, float, bool, list, dict)

Supported Types

str, int, float, bool, list, dict

Examples

Calculator

from rnow.core.tool import tool

@tool
def calculator(expression: str) -> float:
    """Evaluate a math expression."""
    return eval(expression)
import requests
from rnow.core.tool import tool

@tool
def web_search(query: str) -> dict:
    """Search the web."""
    resp = requests.get("https://api.example.com/search", params={"q": query})
    return resp.json()

Sandbox Tools

Use @tool(sandbox=True) for tools that need isolated execution (code execution, file operations):

@tool(sandbox=True)
def run_python(code: str) -> str:
    """Execute Python code in isolated environment."""
    exec(code)
    return "Success"

Entries using sandbox=True tools must have a docker field in train.jsonl specifying the container image.

Custom Docker images must be built for linux/amd64. Sandboxes run on x86_64 Linux servers:

docker build --platform linux/amd64 -t myorg/myimage:latest .

Configuration

Enable multi-turn in config.yml:

rollout:
  max_turns: 5
  termination_policy: last_tool

last_tool: Episode ends when model responds without a tool call

max_turns: Episode ends when max_turns is exhausted