Overview
Verifiers provides three tool environment types:ToolEnv: Stateless Tools
ToolEnv is designed for simple, stateless tools where each call is independent. Tools are Python functions with type hints and docstrings.
Defining Tools
Tools are extracted from function signatures:- Function name → tool name
- Type hints → parameter types
- Docstring → tool description
- Args section → parameter descriptions
Creating a Tool Environment
Real Example: Wiki Search
Let’s examine thewiki-search environment:
environments/wiki_search/wiki_search.py
- Vector search with ChromaDB embeddings
- Async tool execution for performance
- LLM-as-judge for evaluation
- Modular tool design (search → read)
MCPEnv: MCP Server Tools
MCPEnv integrates with Model Context Protocol (MCP) servers, allowing you to use any MCP-compatible tool server.
Basic MCP Setup
- Starts MCP server processes
- Connects via stdio
- Discovers available tools
- Handles tool calls
- Manages server lifecycle
MCP Server Configuration
StatefulToolEnv: Persistent State
StatefulToolEnv is for tools that need per-rollout state (e.g., sandbox containers, database sessions, game state).
Concept: Hidden Arguments
Some tool parameters should be injected by the environment but hidden from the model:run_code(code: str)The environment calls:
run_code(code=user_input, sandbox_id=state["sandbox_id"])
Built-in Stateful Environments
Verifiers includes production-ready stateful environments:PythonEnv provides a persistent Python REPL with:
- Package installation via
pip_install_packages - Sandboxed execution via Prime Sandboxes
- Automatic resource cleanup
Sandbox Configuration
BothSandboxEnv and PythonEnv accept detailed configuration:
Tool Error Handling
Control how tool errors are handled:- If error type is in
stop_errors→ rollout stops immediately - Otherwise → error message returned to model (chance to recover)
Tool Metrics
Tool environments automatically track:total_tool_calls— Total number of tool invocations{tool_name}_calls— Per-tool call counts
Advanced Patterns
Dynamic Tool Registration
Add tools after initialization:Tool Return Types
Tools can return various types:Combining Multiple Tool Sets
Common Patterns
Rate Limiting
Caching Tool Results
Tool Chaining
Testing Tool Environments
Next Steps
- Custom multi-turn logic: Advanced patterns beyond tools → Custom Environments Guide
- Training: Use tool environments for RL training → Training Guide
- Evaluation: Comprehensive evaluation strategies → Evaluation Guide