Skip to main content
Telescope supports training models that use tools during rollouts via environment-level tool calling using the ToolEnvironment base class.

ToolEnvironment

ToolEnvironment extends MultiTurnEnvironment with built-in tool calling support. You define tools as Python functions, and the class handles schema generation, prompt injection, tool call parsing, execution, and result formatting.

Defining tools

Tools are regular Python functions with type hints and docstrings:
Pass them to the constructor:
Telescope automatically converts each function to an OpenAI-compatible tool schema using func_to_tool_schema(). The type hints map to JSON Schema types (floatnumber, strstring, intinteger, boolboolean), and the docstring becomes the tool description.

How tool calls are processed

Each turn follows this cycle:
  1. Parse — The model’s completion is scanned for tool calls. By default, XML format is used with a JSON object inside the tags:
  2. Execute — Each parsed ToolCall is executed by calling the corresponding Python function with the parsed arguments.
  3. Format — Results are formatted as tool response messages and appended to the conversation.
  4. Checkis_final_answer() determines if the model is providing a final answer (no tool calls) or wants to continue using tools.

Building a ToolEnvironment

The minimal subclass needs load_dataset and compute_reward:

Override points

Tool metrics

get_tool_metrics(state) returns a dict with usage stats from the trajectory:
These are useful both for reward computation (e.g., penalizing excessive tool use) and for monitoring via sample_metrics. See Metrics for details on how sample metrics are tracked and displayed in the UI.

Sandbox execution

For environments that need to execute code (not just call Python functions), Telescope provides a pluggable sandbox system.

SandboxConfig

Supported providers

Telescope is agnostic to which sandbox provider is used — any provider that implements the SandboxProvider interface (create, execute, upload_bytes, upload_file, destroy) will work. For convenience, the following providers come pre-configured: All providers validate credentials at startup and fail fast if the required SDK package is missing or credentials are invalid.

Using sandboxes in environments

A typical sandbox environment follows this pattern:
  1. Create sandboxes in create_initial_state() with concurrency control via semaphores
  2. Execute commands in env_response() by parsing tool calls and running them in the sandbox
  3. Clean up in a destroy hook when the rollout completes
Sandbox environments use async I/O throughout. The sandbox provider handles timeout enforcement, error translation, and resource cleanup.

Multi-turn configuration for agentic tasks

Key config parameters for tool-using and agentic environments:
priority scheduling is important for multi-turn environments: it ensures the model completes earlier turns before starting new ones, preventing scenarios where later turns queue behind a flood of first-turn requests. interleaved_rollouts (enabled by default) reuses token IDs from previous turns exactly, avoiding subtle tokenization differences that could corrupt logprob computation across turns.