Spaces:
Runtime error
Runtime error
File size: 3,257 Bytes
add4140 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
"""
Data models for the Compressionenv Environment.
The compressionenv environment gives the agent a Paul Graham essay and asks it to
propose compression + decompression algorithms (as Python code).
"""
from typing import Any, Dict, Optional
from pydantic import Field
from openenv.core.env_server.types import Action, Observation
class CompressionenvAction(Action):
"""
Agent-provided compression/decompression algorithms.
The environment expects `compression_code` and `decompression_code` to define:
- compress(text: str) -> bytes
- decompress(data: bytes) -> str
"""
compression_code: str = Field(
...,
description="Python code defining compress(text: str) -> bytes",
min_length=1,
)
decompression_code: str = Field(
...,
description="Python code defining decompress(data: bytes) -> str",
min_length=1,
)
algo_name: str = Field(
default="agent_algo",
description="Optional name/label for this algorithm variant",
)
class CompressionenvObservation(Observation):
"""Observation from the Compressionenv environment."""
essay_id: str = Field(..., description="Selected essay slug/id for this episode")
essay_text: str = Field(
...,
description="Full essay text for the agent to compress",
)
valid: bool = Field(
default=False,
description="Whether the submitted algorithms successfully round-tripped",
)
error: Optional[str] = Field(
default=None,
description="Error message if the algorithms failed validation/execution",
)
compressed_size_bytes: Optional[int] = Field(
default=None,
description="Size of compressed bytes produced by the agent algorithm",
ge=0,
)
avg_prev_compressed_size_bytes: Optional[float] = Field(
default=None,
description="Average compressed size over previous successful steps for this essay",
ge=0,
)
improved_over_avg: Optional[bool] = Field(
default=None,
description="True if current compressed size < avg of previous sizes",
)
baselines_size_bytes: Dict[str, int] = Field(
default_factory=dict,
description="Baseline compressor sizes for this essay (zlib/bz2/lzma)",
)
best_baseline_size_bytes: Optional[int] = Field(
default=None,
description="Best (smallest) baseline size in bytes",
ge=0,
)
beat_any_baseline: Optional[bool] = Field(
default=None,
description="True if current compressed size is smaller than at least one baseline",
)
beat_best_baseline: Optional[bool] = Field(
default=None,
description="True if current compressed size is smaller than the best baseline",
)
reward: float = Field(default=0.0, description="Reward for this step")
done: bool = Field(default=False, description="Whether episode is done")
metadata: Dict[str, Any] = Field(default_factory=dict, description="Extra info")
|