Skip to main content
Tool environments extend multi-turn interaction by giving models access to external functions. They’re essential for agents that need to search, calculate, execute code, or interact with APIs.

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:
Key components:
  • Function name → tool name
  • Type hints → parameter types
  • Docstring → tool description
  • Args section → parameter descriptions
Always use async def for tools to avoid blocking the event loop, even if the function doesn’t await anything internally.

Creating a Tool Environment

Let’s examine the wiki-search environment:
environments/wiki_search/wiki_search.py
Key features:
  • 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

The environment automatically:
  • 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:
The model sees: 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

Both SandboxEnv and PythonEnv accept detailed configuration:

Tool Error Handling

Control how tool errors are handled:
When a tool error occurs:
  • If error type is in stop_errors → rollout stops immediately
  • Otherwise → error message returned to model (chance to recover)
Error hierarchy:

Tool Metrics

Tool environments automatically track:
  • total_tool_calls — Total number of tool invocations
  • {tool_name}_calls — Per-tool call counts
Example output:

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