openenv-core 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,206 @@
1
+ Metadata-Version: 2.4
2
+ Name: openenv-core
3
+ Version: 0.1.0
4
+ Summary: Core components for OpenEnv - HTTP-based agentic environments
5
+ Author-email: "Meta Platforms, Inc." <opensource@meta.com>
6
+ License: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/facebookresearch/OpenEnv
8
+ Project-URL: Repository, https://github.com/facebookresearch/OpenEnv
9
+ Project-URL: Documentation, https://github.com/facebookresearch/OpenEnv/blob/main/README.md
10
+ Project-URL: Bug Tracker, https://github.com/facebookresearch/OpenEnv/issues
11
+ Keywords: environment,agent,http,docker,fastapi
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: requests>=2.25.0
15
+ Requires-Dist: fastapi>=0.104.0
16
+ Requires-Dist: uvicorn>=0.24.0
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
19
+ Requires-Dist: black>=23.0.0; extra == "dev"
20
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
21
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
22
+
23
+ # OpenEnv Core
24
+
25
+ Core components for OpenEnv - a framework for building HTTP-based agentic environments.
26
+
27
+ ## Overview
28
+
29
+ `openenv-core` provides the foundational building blocks for creating and interacting with containerized environments over HTTP. It enables you to build agent environments that can be deployed as Docker containers and accessed via a simple HTTP API.
30
+
31
+ ## Features
32
+
33
+ - **HTTPEnvClient**: Generic HTTP client for interacting with remote environments
34
+ - **HTTPEnvServer**: FastAPI-based server wrapper for exposing environments over HTTP
35
+ - **Container Providers**: Pluggable architecture for running containers (Docker, Kubernetes, etc.)
36
+ - **Type System**: Strongly-typed Action/Observation/State interfaces
37
+ - **Web Interface**: Optional web UI for interacting with environments
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ pip install openenv-core
43
+ ```
44
+
45
+ For development:
46
+ ```bash
47
+ pip install openenv-core[dev]
48
+ ```
49
+
50
+ ## Quick Start
51
+
52
+ ### Creating an Environment Client
53
+
54
+ ```python
55
+ from openenv_core import HTTPEnvClient, StepResult
56
+ from dataclasses import dataclass
57
+
58
+ @dataclass
59
+ class MyAction:
60
+ text: str
61
+
62
+ @dataclass
63
+ class MyObservation:
64
+ response: str
65
+
66
+ class MyEnvClient(HTTPEnvClient[MyAction, MyObservation]):
67
+ def _step_payload(self, action: MyAction) -> dict:
68
+ return {"text": action.text}
69
+
70
+ def _parse_result(self, payload: dict) -> StepResult[MyObservation]:
71
+ obs_data = payload["observation"]
72
+ return StepResult(
73
+ observation=MyObservation(**obs_data),
74
+ reward=payload.get("reward"),
75
+ done=payload.get("done", False)
76
+ )
77
+
78
+ def _parse_state(self, payload: dict) -> Any:
79
+ return payload
80
+
81
+ # Use with Docker
82
+ env = MyEnvClient.from_docker_image("my-env:latest")
83
+ result = env.reset()
84
+ step_result = env.step(MyAction(text="hello"))
85
+ env.close()
86
+ ```
87
+
88
+ ### Creating an Environment Server
89
+
90
+ ```python
91
+ from openenv_core.env_server import Environment, HTTPEnvServer, create_app
92
+ from dataclasses import dataclass
93
+
94
+ @dataclass
95
+ class MyAction:
96
+ text: str
97
+
98
+ @dataclass
99
+ class MyObservation:
100
+ response: str
101
+ reward: float = 0.0
102
+ done: bool = False
103
+
104
+ class MyEnvironment(Environment):
105
+ def reset(self) -> MyObservation:
106
+ return MyObservation(response="Ready")
107
+
108
+ def step(self, action: MyAction) -> MyObservation:
109
+ return MyObservation(
110
+ response=f"Echo: {action.text}",
111
+ reward=1.0,
112
+ done=False
113
+ )
114
+
115
+ # Create FastAPI app
116
+ env = MyEnvironment()
117
+ app = create_app(env, MyAction, MyObservation)
118
+
119
+ # Run with: uvicorn module:app --host 0.0.0.0 --port 8000
120
+ ```
121
+
122
+ ## Container Providers
123
+
124
+ OpenEnv Core supports multiple container providers:
125
+
126
+ ### Local Docker Provider
127
+
128
+ ```python
129
+ from openenv_core.containers.runtime import LocalDockerProvider
130
+
131
+ provider = LocalDockerProvider()
132
+ base_url = provider.start_container("my-env:latest")
133
+ provider.wait_for_ready(base_url)
134
+ # Use environment...
135
+ provider.stop_container()
136
+ ```
137
+
138
+ ### Kubernetes Provider (Coming Soon)
139
+
140
+ ```python
141
+ from openenv_core.containers.runtime import KubernetesProvider
142
+
143
+ provider = KubernetesProvider(namespace="envs")
144
+ base_url = provider.start_container("my-env:latest")
145
+ # Use environment...
146
+ provider.stop_container()
147
+ ```
148
+
149
+ ## Architecture
150
+
151
+ OpenEnv Core follows a client-server architecture:
152
+
153
+ ```
154
+ ┌─────────────────┐ HTTP ┌─────────────────┐
155
+ │ │◄─────────────────────►│ │
156
+ │ HTTPEnvClient │ /reset, /step │ HTTPEnvServer │
157
+ │ │ /state, /health │ │
158
+ └─────────────────┘ └─────────────────┘
159
+ │ │
160
+ │ │
161
+ ▼ ▼
162
+ ┌─────────────────┐ ┌─────────────────┐
163
+ │ Container │ │ Environment │
164
+ │ Provider │ │ Implementation │
165
+ └─────────────────┘ └─────────────────┘
166
+ ```
167
+
168
+ ## API Reference
169
+
170
+ ### HTTPEnvClient
171
+
172
+ Base class for environment clients with these abstract methods:
173
+
174
+ - `_step_payload(action)`: Convert action to JSON
175
+ - `_parse_result(payload)`: Parse response to StepResult
176
+ - `_parse_state(payload)`: Parse state response
177
+
178
+ ### HTTPEnvServer
179
+
180
+ Server wrapper with these methods:
181
+
182
+ - `register_routes(app)`: Register endpoints on FastAPI app
183
+ - `_deserialize_action(data)`: Convert JSON to Action
184
+ - `_serialize_observation(obs)`: Convert Observation to JSON
185
+
186
+ ### Environment Interface
187
+
188
+ Base interface for environment implementations:
189
+
190
+ - `reset()`: Reset environment and return initial observation
191
+ - `step(action)`: Execute action and return observation
192
+ - `state`: Property returning current environment state
193
+
194
+ ## License
195
+
196
+ This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.
197
+
198
+ ## Contributing
199
+
200
+ Contributions are welcome! Please see the main OpenEnv repository for contribution guidelines.
201
+
202
+ ## Links
203
+
204
+ - **Homepage**: https://github.com/facebookresearch/OpenEnv
205
+ - **Documentation**: https://github.com/facebookresearch/OpenEnv/blob/main/README.md
206
+ - **Bug Tracker**: https://github.com/facebookresearch/OpenEnv/issues
@@ -0,0 +1,184 @@
1
+ # OpenEnv Core
2
+
3
+ Core components for OpenEnv - a framework for building HTTP-based agentic environments.
4
+
5
+ ## Overview
6
+
7
+ `openenv-core` provides the foundational building blocks for creating and interacting with containerized environments over HTTP. It enables you to build agent environments that can be deployed as Docker containers and accessed via a simple HTTP API.
8
+
9
+ ## Features
10
+
11
+ - **HTTPEnvClient**: Generic HTTP client for interacting with remote environments
12
+ - **HTTPEnvServer**: FastAPI-based server wrapper for exposing environments over HTTP
13
+ - **Container Providers**: Pluggable architecture for running containers (Docker, Kubernetes, etc.)
14
+ - **Type System**: Strongly-typed Action/Observation/State interfaces
15
+ - **Web Interface**: Optional web UI for interacting with environments
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install openenv-core
21
+ ```
22
+
23
+ For development:
24
+ ```bash
25
+ pip install openenv-core[dev]
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ### Creating an Environment Client
31
+
32
+ ```python
33
+ from openenv_core import HTTPEnvClient, StepResult
34
+ from dataclasses import dataclass
35
+
36
+ @dataclass
37
+ class MyAction:
38
+ text: str
39
+
40
+ @dataclass
41
+ class MyObservation:
42
+ response: str
43
+
44
+ class MyEnvClient(HTTPEnvClient[MyAction, MyObservation]):
45
+ def _step_payload(self, action: MyAction) -> dict:
46
+ return {"text": action.text}
47
+
48
+ def _parse_result(self, payload: dict) -> StepResult[MyObservation]:
49
+ obs_data = payload["observation"]
50
+ return StepResult(
51
+ observation=MyObservation(**obs_data),
52
+ reward=payload.get("reward"),
53
+ done=payload.get("done", False)
54
+ )
55
+
56
+ def _parse_state(self, payload: dict) -> Any:
57
+ return payload
58
+
59
+ # Use with Docker
60
+ env = MyEnvClient.from_docker_image("my-env:latest")
61
+ result = env.reset()
62
+ step_result = env.step(MyAction(text="hello"))
63
+ env.close()
64
+ ```
65
+
66
+ ### Creating an Environment Server
67
+
68
+ ```python
69
+ from openenv_core.env_server import Environment, HTTPEnvServer, create_app
70
+ from dataclasses import dataclass
71
+
72
+ @dataclass
73
+ class MyAction:
74
+ text: str
75
+
76
+ @dataclass
77
+ class MyObservation:
78
+ response: str
79
+ reward: float = 0.0
80
+ done: bool = False
81
+
82
+ class MyEnvironment(Environment):
83
+ def reset(self) -> MyObservation:
84
+ return MyObservation(response="Ready")
85
+
86
+ def step(self, action: MyAction) -> MyObservation:
87
+ return MyObservation(
88
+ response=f"Echo: {action.text}",
89
+ reward=1.0,
90
+ done=False
91
+ )
92
+
93
+ # Create FastAPI app
94
+ env = MyEnvironment()
95
+ app = create_app(env, MyAction, MyObservation)
96
+
97
+ # Run with: uvicorn module:app --host 0.0.0.0 --port 8000
98
+ ```
99
+
100
+ ## Container Providers
101
+
102
+ OpenEnv Core supports multiple container providers:
103
+
104
+ ### Local Docker Provider
105
+
106
+ ```python
107
+ from openenv_core.containers.runtime import LocalDockerProvider
108
+
109
+ provider = LocalDockerProvider()
110
+ base_url = provider.start_container("my-env:latest")
111
+ provider.wait_for_ready(base_url)
112
+ # Use environment...
113
+ provider.stop_container()
114
+ ```
115
+
116
+ ### Kubernetes Provider (Coming Soon)
117
+
118
+ ```python
119
+ from openenv_core.containers.runtime import KubernetesProvider
120
+
121
+ provider = KubernetesProvider(namespace="envs")
122
+ base_url = provider.start_container("my-env:latest")
123
+ # Use environment...
124
+ provider.stop_container()
125
+ ```
126
+
127
+ ## Architecture
128
+
129
+ OpenEnv Core follows a client-server architecture:
130
+
131
+ ```
132
+ ┌─────────────────┐ HTTP ┌─────────────────┐
133
+ │ │◄─────────────────────►│ │
134
+ │ HTTPEnvClient │ /reset, /step │ HTTPEnvServer │
135
+ │ │ /state, /health │ │
136
+ └─────────────────┘ └─────────────────┘
137
+ │ │
138
+ │ │
139
+ ▼ ▼
140
+ ┌─────────────────┐ ┌─────────────────┐
141
+ │ Container │ │ Environment │
142
+ │ Provider │ │ Implementation │
143
+ └─────────────────┘ └─────────────────┘
144
+ ```
145
+
146
+ ## API Reference
147
+
148
+ ### HTTPEnvClient
149
+
150
+ Base class for environment clients with these abstract methods:
151
+
152
+ - `_step_payload(action)`: Convert action to JSON
153
+ - `_parse_result(payload)`: Parse response to StepResult
154
+ - `_parse_state(payload)`: Parse state response
155
+
156
+ ### HTTPEnvServer
157
+
158
+ Server wrapper with these methods:
159
+
160
+ - `register_routes(app)`: Register endpoints on FastAPI app
161
+ - `_deserialize_action(data)`: Convert JSON to Action
162
+ - `_serialize_observation(obs)`: Convert Observation to JSON
163
+
164
+ ### Environment Interface
165
+
166
+ Base interface for environment implementations:
167
+
168
+ - `reset()`: Reset environment and return initial observation
169
+ - `step(action)`: Execute action and return observation
170
+ - `state`: Property returning current environment state
171
+
172
+ ## License
173
+
174
+ This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.
175
+
176
+ ## Contributing
177
+
178
+ Contributions are welcome! Please see the main OpenEnv repository for contribution guidelines.
179
+
180
+ ## Links
181
+
182
+ - **Homepage**: https://github.com/facebookresearch/OpenEnv
183
+ - **Documentation**: https://github.com/facebookresearch/OpenEnv/blob/main/README.md
184
+ - **Bug Tracker**: https://github.com/facebookresearch/OpenEnv/issues
@@ -0,0 +1,19 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ """Core components for agentic environments."""
8
+
9
+ # Re-export main components from submodules for convenience
10
+ from .env_server import *
11
+ from .client_types import StepResult
12
+ from .http_env_client import HTTPEnvClient
13
+
14
+ # Note: MCP module doesn't export anything yet
15
+
16
+ __all__ = [
17
+ "HTTPEnvClient",
18
+ "StepResult",
19
+ ]
@@ -0,0 +1,22 @@
1
+ # Type definitions for EnvTorch
2
+ from dataclasses import dataclass
3
+ from typing import Any, Generic, Optional, TypeVar
4
+
5
+ # Generic type for observations
6
+ ObsT = TypeVar("ObsT") # TypeVar for typehinting in IDEs
7
+
8
+
9
+ @dataclass
10
+ class StepResult(Generic[ObsT]):
11
+ """
12
+ Represents the result of one environment step.
13
+
14
+ Attributes:
15
+ observation: The environment's observation after the action.
16
+ reward: Scalar reward for this step (optional).
17
+ done: Whether the episode is finished.
18
+ """
19
+
20
+ observation: ObsT
21
+ reward: Optional[float] = None
22
+ done: bool = False
@@ -0,0 +1,7 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ """Container management for environment servers."""
@@ -0,0 +1,15 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ """Container runtime providers."""
8
+
9
+ from .providers import ContainerProvider, KubernetesProvider, LocalDockerProvider
10
+
11
+ __all__ = [
12
+ "ContainerProvider",
13
+ "LocalDockerProvider",
14
+ "KubernetesProvider",
15
+ ]