Skip to main content

Core Execution Concepts

The following concepts define the lifecycle and data units of an evaluation. These match the semantics used by the @evaluation_test decorator in the Python SDK.

invocation

A single execution of a test function. One invocation can generate one or more experiments.

experiment

A group of runs for a specific combination of parameters (e.g., model x dataset x generation params). Each new execution of the test function produces a new experiment.

run

A group of rollouts produced when repeating the same experiment multiple times. When num_runs > 1, each repetition has a unique run_id.

rollout

The process that produces a trajectory for a single row. Each rollout has a unique rollout_id.

trajectory

The sequence of chat messages (and optional tool calls) produced during a rollout.

row

The atomic evaluation unit. A row contains the conversation messages, optional ground_truth, and the evaluator’s evaluation_result. Every row is uniquely identified by its row_id. If not provided by the dataset, a stable hash is generated based on the row’s content.

dataset

A collection (list) of rows. When stored, it is a JSONL file where each line is an EvaluationRow.

eval

The rubric implemented in the body of an @evaluation_test-decorated function. It computes a score in [0, 1] and writes it to the row’s evaluation_result.

Execution IDs and how they relate

Eval Protocol uses a small set of IDs to make rollouts traceable across systems (log stores, tracing UIs, dataset artifacts, etc.). These IDs are correlation identifiers, not “job objects” by themselves. Each rollout/trajectory can be identified by the tuple:
  • invocation_idexperiment_idrun_idrow_idrollout_id
In other words:
  • An invocation contains one or more experiments
  • An experiment contains one or more runs (repetitions)
  • A run contains many rows
  • For each row, there may be one or more rollouts (e.g., (N) samples per prompt)

What each ID means

Remote rollout processors: why all 5 IDs appear together

When using remote rollout processors, Eval Protocol passes a RolloutMetadata object that includes invocation_id, experiment_id, run_id, row_id, and rollout_id so the remote system can:
  • tag logs/traces (e.g., rollout_id:*) for retrieval,
  • correlate failures to a specific row and rollout,
  • emit artifacts that can be merged back into the evaluation dataset.

Mapping these IDs to “RL job” and “RL step”

Eval Protocol itself does not define an “RL job” concept; it defines rollouts and evaluations. In RL training pipelines, we recommend:
  • RL job id: set/use invocation_id as the top-level grouping id (e.g., your trainer job id, CI run id, or workflow id).
  • RL step / epoch / iteration: encode this in either:
    • run_id (if your “step” is conceptually a repetition of the same experiment), or
    • execution_metadata.extra / input_metadata.session_data (preferred when you need multiple axes like epoch + step + shard).
The key requirement is consistency: pick a convention so that all systems (tracing, dataset artifacts, training code) can join on the same keys.

Foundational Types

JSONType

Message

Represents a chat message with trajectory evaluation support. content supports either a string or OpenAI content parts.

CompletionParams

InputMetadata

ErrorInfo (AIP-193)

Structured error detail used inside Status.details per Google’s AIP-193.

Status (AIP-193)

TerminationReason

MetricResult

Result of a single metric evaluation:

StepOutput

Defines the base reward and other metrics for a single conceptual step within a rollout:

EvaluationThreshold

EvalMetadata

CostMetrics

ExecutionMetadata

EvaluateResult

The EvaluateResult represents the complete result of an evaluator, providing an overall score and component metrics.
Key Features:
  • Unified Model: Serves both per-turn and per-trajectory evaluation scenarios
  • Component Metrics: Detailed breakdown through MetricResult objects
  • RL Support: Per-step base rewards via step_outputs for reinforcement learning
  • Error Handling: Graceful error reporting and validation
  • Trajectory Info: Additional metadata for trajectory-based evaluations
  • Aggregation: Optional agg_score and standard_error for multi-run summaries

EvaluationRow

The EvaluationRow is the canonical JSON-serializable unit of data used for both single-turn and trajectory evaluations. It contains the conversation, tool context, evaluation results, and metadata needed for reproducibility and analysis.
Key Features:
  • Unified Format: Canonical row format for both pointwise and trajectory evaluations
  • Explicit Status: rollout_status captures running/finished/error
  • Reproducibility: input_metadata, seeds, and identifiers support traceability
  • Usage Tracking: Captures token usage statistics from LLM calls

Dataset

A list of EvaluationRows. When saved to file, it is a JSONL file where each line is a JSON-encoded EvaluationRow.

JSONL example

EvaluationTest

The EvaluationTest represents a test configuration for evaluating models. While not explicitly defined as a separate class in the current implementation, evaluation tests are configured through the evaluation_test decorator. The decorator can be used to configure the following:
  • Dataset Configuration: JSONL files containing test cases or hard-coded input_messages
  • Model Configuration: Completion parameters (must include model) and generation settings via completion_params
  • Evaluation Criteria: Success thresholds (via passed_threshold), with optional standard deviation constraint
  • Environment Configuration: MCP config, rollout steps, server path, and concurrency
  • Rollout Processor: Class to execute rollouts (e.g., SingleTurnRolloutProcessor())
  • Number of Runs: Number of times to repeat the rollout (e.g., num_runs=1)
  • Mode: Evaluation mode (pointwise, groupwise, or all)
  • Aggregation: Aggregation method (e.g., mean) and optional env overrides for summaries

MCP Gym

McpGym is the base class for building environments that an LLM can interact with via MCP tool calls (data plane) while exposing rewards and episode status via HTTP control-plane endpoints. This enables reproducible RL-style rollouts with clean separation of concerns. Key concepts:
  • Data plane: Tool calls and JSON responses used by the model to act and observe state
  • Control plane: Session-scoped endpoints for rewards, termination, and info
  • Multi-session: Stable session_id keys route control-plane queries to the right episode
Core API surface:
  • control_plane_endpoint(path): Decorator to register a session-aware endpoint
  • _register_tools(): Register domain tools with self.mcp.tool()
  • format_observation(obs, env) -> Dict[str, Any]: Return JSON-serializable observation payloads
  • run(transport="streamable-http"): Start the FastMCP server with high-concurrency settings
  • Standard control-plane endpoints on subclasses: /control/reward, /control/status, /control/info, /control/initial_state
Example stub:
See python-sdk/eval_protocol/mcp/mcpgym.py for the full implementation including the control_plane_endpoint decorator and session handling.

Environment

The EnvironmentAdapter class provides the interface for connecting environments to the MCP framework.
Key Features:
  • Default Implementations: Works with most gymnasium-style and complex environments
  • Flexible Configuration: Supports custom configuration dictionaries
  • Seed Support: Reproducible environments through seed-based initialization
  • Clean Interface: Separates MCP protocol layer from environment implementation
Core Methods:
  • create_environment(): Create and return a new environment instance
  • create_environment_with_seed(): Create environment with specific seed for reproducibility
  • reset_environment(): Reset environment to initial state
  • step_environment(): Execute one step in the environment
  • close_environment(): Clean up environment resources
  • parse_action(): Parse action string to environment-specific format
  • format_observation(): Format observation for MCP transmission

Policy

A policy is a model such as gpt-4o or llama-3.1-8b. In more advanced scenarios, a policy can be your own custom fine-tuned model. The LiteLLMPolicy class provides a unified implementation that works with ANY MCP environment via tool calling:
Key Features:
  • Provider Agnostic: Supports OpenAI, Anthropic, Fireworks AI, and other providers
  • Built-in Caching: Multiple cache types (memory, Redis, dual, S3, disk)
  • Retry Logic: Robust retry strategies with exponential backoff
  • Tool Calling: Native support for MCP tool calling
  • Environment Agnostic: No environment-specific logic - everything from MCP tools
Specialized Implementations:
  • OpenAIPolicy: OpenAI-specific policy implementation
  • AnthropicPolicy: Anthropic Claude-specific policy implementation
  • FireworksPolicy: Fireworks AI-specific policy implementation
  • LocalPolicy: Local model policy implementation
Core Capabilities:
  • Multi-Tool Support: Handle multiple tool calls per turn
  • Conversation History: Maintain context across interactions
  • Error Handling: Graceful handling of API failures and retries
  • Caching: Response caching for improved performance and cost reduction
  • Logging: Comprehensive logging for debugging and analysis

Additional Core Classes

MCPSession

Represents a single MCP session with an environment:

Trajectory

Represents a complete rollout trajectory: