{"data":{"kind":"file","path":"README.md","version_id":"n2vohnzd1zqzkfjn8am7novy","entry":{"name":"README.md","path":"README.md","is_directory":false,"size":2051,"modified_at":"2026-03-03T23:23:17.746000","content_hash":"e9c603d5bc706e339838a6dda7f49afc9ba795eea4d61056cd92db646faf19c5"},"entries":[],"content":"# Tool Use (ToolEnv — 4 stateless tools)\n\nA `vf.ToolEnv` environment that teaches a model to call stateless utility tools.  \nFour tools cover calculation, string manipulation, and unit conversion — all with fully deterministic answers.\n\n## Tools\n\n| Tool | Description | Example |\n|------|-------------|---------|\n| `calculate(expression)` | Evaluate arithmetic (+, -, *, /) | `\"(3 + 4) * 2\"` → `\"14\"` |\n| `count_words(text)` | Count space-separated words | `\"hello world\"` → `2` |\n| `reverse_string(text)` | Reverse characters | `\"hello\"` → `\"olleh\"` |\n| `convert_units(value, from_unit, to_unit)` | Unit conversion | `5.0, \"km\", \"miles\"` → `\"3.1069 miles\"` |\n\n## Setup\n\n```bash\npip install verifiers>=0.1.10\n```\n\n## Quick eval\n\n```python\nfrom lab_cookbook.recipes.tool_use.tool_use import load_environment\nimport verifiers as vf\n\nenv = load_environment(num_examples=50)\nvf.evaluate(env, model=\"gpt-4.1-mini\", rollouts_per_example=4)\n```\n\n## Training run\n\n```bash\nprime rl run config.toml\n```\n\n## Expected metrics\n\n| Model | Starting reward | After 50 steps |\n|-------|----------------|----------------|\n| GPT-4.1-mini | ~0.85 | ~0.97 |\n| Llama-3.2-1B | ~0.25 | ~0.65 |\n| Llama-3.2-3B | ~0.45 | ~0.80 |\n\n## Key patterns demonstrated\n\n- **`vf.ToolEnv`** — automatic JSON schema extraction from Python function signatures\n- **Stateless tools** — no shared state; safe to call in any order, any number of times\n- **`vf.Rubric`** with a custom async reward function\n- Final-answer extraction: reward function reads the **last non-empty line** as the prediction\n\n## Adapting to new domains\n\nTo add a custom tool, just add a Python function with a docstring and type annotations.\n`vf.ToolEnv` extracts the JSON schema automatically:\n\n```python\ndef lookup_population(city: str) -> str:\n    \"\"\"Return the approximate population of a city.\n    Args:\n        city: City name.\n    Returns:\n        Population as a string, e.g. \"8.3 million\".\n    \"\"\"\n    ...  # implement lookup\n```\n\nThen add it to the `tools=[...]` list in `load_environment()`.\n","encoding":"utf-8","truncated":false,"total_bytes":2051},"status":null}