Skip to content

Commit ded4e79

Browse files
committed
restructure env server and client code for coding env
1 parent 67d731f commit ded4e79

File tree

11 files changed

+149
-344
lines changed

11 files changed

+149
-344
lines changed

src/core/env_server/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""Core environment interfaces and types."""
88

99
from .base_transforms import CompositeTransform, NullTransform
10-
from .code_execution_environment import CodeExecutionEnvironment
1110
from .interfaces import Environment, Transform
1211
from .types import (
1312
Action,
@@ -34,6 +33,4 @@
3433
# Base transforms
3534
"CompositeTransform",
3635
"NullTransform",
37-
# Base environment implementation
38-
"CodeExecutionEnvironment",
3936
]

src/core/env_server/code_execution_environment.py

Lines changed: 0 additions & 167 deletions
This file was deleted.

src/core/env_server/types.py

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
import traceback
87
from dataclasses import dataclass, field
98
from typing import Any, Dict, List, Optional, Union
109

@@ -20,57 +19,6 @@ class Action:
2019
metadata: Dict[str, Any] = field(default_factory=dict)
2120

2221

23-
@dataclass(kw_only=True)
24-
class CodeAction(Action):
25-
"""Action containing Python code to execute in a CodeAct environment."""
26-
27-
code: str
28-
29-
def __post_init__(self):
30-
if not self.code or not self.code.strip():
31-
raise ValueError("code is required and cannot be empty")
32-
33-
34-
@dataclass
35-
class ExecutionResult:
36-
"""Result of executing Python code."""
37-
38-
stdout: str = ""
39-
stderr: str = ""
40-
exit_code: int = 0
41-
execution_time_ms: float = 0.0
42-
43-
@classmethod
44-
def from_exception(
45-
cls, exc: Exception, stdout: str = "", stderr: str = ""
46-
) -> "ExecutionResult":
47-
return cls(
48-
stdout=stdout,
49-
stderr=stderr,
50-
exception=exc,
51-
exception_type=exc.__class__.__name__,
52-
exception_message=str(exc),
53-
traceback_str=traceback.format_exc(),
54-
success=False,
55-
)
56-
57-
@classmethod
58-
def from_success(
59-
cls,
60-
return_value: Any = None,
61-
stdout: str = "",
62-
stderr: str = "",
63-
execution_time_ms: float = 0.0,
64-
) -> "ExecutionResult":
65-
return cls(
66-
stdout=stdout,
67-
stderr=stderr,
68-
return_value=return_value,
69-
execution_time_ms=execution_time_ms,
70-
success=True,
71-
)
72-
73-
7422
@dataclass(kw_only=True)
7523
class Observation:
7624
"""Base class for all environment observations."""
@@ -80,31 +28,9 @@ class Observation:
8028
metadata: Dict[str, Any] = field(default_factory=dict)
8129

8230

83-
@dataclass(kw_only=True)
84-
class CodeObservation(Observation):
85-
"""Observation from CodeAct environment execution."""
86-
87-
execution_result: ExecutionResult = field(default_factory=ExecutionResult)
88-
available_tools: List[str] = field(default_factory=list)
89-
90-
9131
@dataclass
9232
class State:
9333
"""Base class for environment state."""
9434

9535
episode_id: Optional[str] = None
9636
step_count: int = 0
97-
metadata: Dict[str, Any] = field(default_factory=dict)
98-
99-
100-
@dataclass
101-
class CodeState(State):
102-
"""State for CodeAct environment with persistent execution context."""
103-
104-
execution_globals: Dict[str, Any] = field(default_factory=dict)
105-
action_history: List[CodeAction] = field(default_factory=list)
106-
result_history: List[ExecutionResult] = field(default_factory=list)
107-
108-
def __post_init__(self):
109-
if not self.execution_globals:
110-
self.execution_globals = {"__builtins__": __builtins__}

src/envs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
"""Environment implementations."""
7+
"""This module encapsulates all environment implementations."""
88

99
from .coding import CodingEnv
1010

src/envs/coding/__init__.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/envs/coding/coding_env.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/envs/coding_env/env.py renamed to src/envs/coding_env/client/coding_env_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from core.base_env_client import HTTPEnvClient
1919
from core.types import StepResult
2020

21-
from .models import CodeAction, CodeObservation
21+
from ..models import CodeAction, CodeObservation
2222

2323

2424
class CodingEnv(HTTPEnvClient[CodeAction, CodeObservation]):

src/envs/coding_env/example_usage.py renamed to src/envs/coding_env/client/example_usage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from envs.coding_env.env import CodingEnv
21
from envs.coding_env.models import CodeAction
32

3+
from .coding_env_client import CodingEnv
4+
45
env = CodingEnv(base_url="http://localhost:8080")
56
obs0 = env.reset()
67
result = env.step(CodeAction(code="print('hi')"))

0 commit comments

Comments
 (0)