Skip to content

Commit 7995504

Browse files
committed
Added all code used for the HF App
1 parent f628597 commit 7995504

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+18395
-14
lines changed

src/envs/warehouse_env/Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
# Copy all warehouse environment files (for HF Spaces deployment)
6+
COPY . /app/
7+
8+
# Install Python dependencies
9+
RUN pip install --no-cache-dir \
10+
fastapi==0.104.1 \
11+
uvicorn==0.24.0 \
12+
pydantic==2.5.0 \
13+
requests==2.31.0
14+
15+
# Expose port
16+
EXPOSE 8000
17+
18+
# Environment variables with defaults
19+
ENV DIFFICULTY_LEVEL=2
20+
ENV GRID_WIDTH=0
21+
ENV GRID_HEIGHT=0
22+
ENV NUM_PACKAGES=0
23+
ENV MAX_STEPS=0
24+
ENV RANDOM_SEED=0
25+
26+
# Set Python path to include current directory
27+
ENV PYTHONPATH=/app
28+
29+
# Run the server
30+
CMD ["python", "-m", "uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "8000"]

src/envs/warehouse_env/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1+
---
2+
title: Warehouse Env Environment Server
3+
emoji: 🏭
4+
colorFrom: blue
5+
colorTo: indigo
6+
sdk: docker
7+
pinned: false
8+
app_port: 8000
9+
base_path: /demo
10+
tags:
11+
- openenv
12+
- reinforcement-learning
13+
- logistics
14+
- warehouse
15+
- robotics
16+
---
17+
118
# Warehouse Optimization Environment
219

320
A grid-based warehouse logistics optimization environment for reinforcement learning. This environment simulates a warehouse robot that must navigate through obstacles, pick up packages from pickup zones, and deliver them to designated dropoff zones while optimizing for time and efficiency.
421

522
## Overview
623

7-
The Warehouse Environment is designed for training RL agents on logistics and pathfinding tasks. It features:
24+
The Warehouse Environment is designed for training reinforcement learning agents on logistics and pathfinding tasks. It features:
825

926
- **Grid-based navigation** with walls and obstacles
1027
- **Package pickup and delivery** mechanics
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# <img width="35" height="35" alt="image" src="https://github.com/user-attachments/assets/2700a971-e5d6-4036-b03f-2f89c9791609" /> OpenEnv: Agentic Execution Environments
2+
3+
An e2e framework for creating, deploying and using isolated execution environments for agentic RL training, built using Gymnasium style simple APIs. OpenEnv provides a standard for interacting with agentic execution environments via simple Gymnasium style APIs - step(), reset(), state(). Users of agentic execution environments can interact with the environment during RL training loops using these simple APIs.
4+
5+
In addition to making it easier for researchers and RL framework writers, we also provide tools for environment creators making it easier for them to create richer environments and make them available over familiar protocols like HTTP and packaged using canonical technologies like docker. Environment creators can use the OpenEnv framework to create environments that are isolated, secure, and easy to deploy and use.
6+
7+
8+
## Overview
9+
`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.
10+
11+
> ⚠️ **Early Development Warning** OpenEnv is currently in an experimental
12+
> stage. You should expect bugs, incomplete features, and APIs that may change
13+
> in future versions. The project welcomes bugfixes, but to make sure things are
14+
> well coordinated you should discuss any significant change before starting the
15+
> work. It's recommended that you signal your intention to contribute in the
16+
> issue tracker, either by filing a new issue or by claiming an existing one.
17+
18+
19+
# OpenEnv Core
20+
21+
Core components for OpenEnv - a framework for building HTTP-based agentic environments.
22+
23+
## Features
24+
25+
- **HTTPEnvClient**: Generic HTTP client for interacting with remote environments
26+
- **HTTPEnvServer**: FastAPI-based server wrapper for exposing environments over HTTP
27+
- **Container Providers**: Pluggable architecture for running containers (Docker, Kubernetes, etc.)
28+
- **Type System**: Strongly-typed Action/Observation/State interfaces
29+
- **Web Interface**: Optional web UI for interacting with environments
30+
31+
## Installation
32+
33+
```bash
34+
pip install openenv-core
35+
```
36+
37+
For development:
38+
```bash
39+
pip install openenv-core[dev]
40+
```
41+
42+
## Quick Start
43+
44+
### Creating an Environment Client
45+
46+
```python
47+
from openenv_core import HTTPEnvClient, StepResult
48+
from dataclasses import dataclass
49+
50+
@dataclass
51+
class MyAction:
52+
text: str
53+
54+
@dataclass
55+
class MyObservation:
56+
response: str
57+
58+
class MyEnvClient(HTTPEnvClient[MyAction, MyObservation]):
59+
def _step_payload(self, action: MyAction) -> dict:
60+
return {"text": action.text}
61+
62+
def _parse_result(self, payload: dict) -> StepResult[MyObservation]:
63+
obs_data = payload["observation"]
64+
return StepResult(
65+
observation=MyObservation(**obs_data),
66+
reward=payload.get("reward"),
67+
done=payload.get("done", False)
68+
)
69+
70+
def _parse_state(self, payload: dict) -> Any:
71+
return payload
72+
73+
# Use with Docker
74+
env = MyEnvClient.from_docker_image("my-env:latest")
75+
result = env.reset()
76+
step_result = env.step(MyAction(text="hello"))
77+
env.close()
78+
```
79+
80+
### Creating an Environment Server
81+
82+
```python
83+
from openenv_core.env_server import Environment, HTTPEnvServer, create_app
84+
from dataclasses import dataclass
85+
86+
@dataclass
87+
class MyAction:
88+
text: str
89+
90+
@dataclass
91+
class MyObservation:
92+
response: str
93+
reward: float = 0.0
94+
done: bool = False
95+
96+
class MyEnvironment(Environment):
97+
def reset(self) -> MyObservation:
98+
return MyObservation(response="Ready")
99+
100+
def step(self, action: MyAction) -> MyObservation:
101+
return MyObservation(
102+
response=f"Echo: {action.text}",
103+
reward=1.0,
104+
done=False
105+
)
106+
107+
# Create FastAPI app
108+
env = MyEnvironment()
109+
app = create_app(env, MyAction, MyObservation)
110+
111+
# Run with: uvicorn module:app --host 0.0.0.0 --port 8000
112+
```
113+
114+
## Container Providers
115+
116+
OpenEnv Core supports multiple container providers:
117+
118+
### Local Docker Provider
119+
120+
```python
121+
from openenv_core.containers.runtime import LocalDockerProvider
122+
123+
provider = LocalDockerProvider()
124+
base_url = provider.start_container("my-env:latest")
125+
provider.wait_for_ready(base_url)
126+
# Use environment...
127+
provider.stop_container()
128+
```
129+
130+
### Kubernetes Provider (Coming Soon)
131+
132+
```python
133+
from openenv_core.containers.runtime import KubernetesProvider
134+
135+
provider = KubernetesProvider(namespace="envs")
136+
base_url = provider.start_container("my-env:latest")
137+
# Use environment...
138+
provider.stop_container()
139+
```
140+
141+
142+
## API Reference
143+
144+
### HTTPEnvClient
145+
146+
Base class for environment clients with these abstract methods:
147+
148+
- `_step_payload(action)`: Convert action to JSON
149+
- `_parse_result(payload)`: Parse response to StepResult
150+
- `_parse_state(payload)`: Parse state response
151+
152+
### HTTPEnvServer
153+
154+
Server wrapper with these methods:
155+
156+
- `register_routes(app)`: Register endpoints on FastAPI app
157+
- `_deserialize_action(data)`: Convert JSON to Action
158+
- `_serialize_observation(obs)`: Convert Observation to JSON
159+
160+
### Environment Interface
161+
162+
Base interface for environment implementations:
163+
164+
- `reset()`: Reset environment and return initial observation
165+
- `step(action)`: Execute action and return observation
166+
- `state`: Property returning current environment state
167+
168+
## License
169+
170+
This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.
171+
172+
## Contributing
173+
174+
Contributions are welcome! Please see the main OpenEnv repository for contribution guidelines.
175+
176+
## Links
177+
178+
- **Homepage**: https://github.com/meta-pytorch/OpenEnv
179+
- **Documentation**: https://github.com/meta-pytorch/OpenEnv/blob/main/README.md
180+
- **Bug Tracker**: https://github.com/meta-pytorch/OpenEnv/issues
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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."""
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
#
8+
# OpenEnv Base Image
9+
#
10+
# This is the standard base image for all OpenEnv environment servers.
11+
# It includes the minimal dependencies needed to run HTTP environment servers
12+
# and uv for fast dependency management.
13+
#
14+
# Build from repo root: docker build -t openenv-base:latest -f src/core/containers/images/Dockerfile .
15+
# Tag: docker tag openenv-base:latest openenv-base:0.2.0
16+
#
17+
18+
FROM ghcr.io/astral-sh/uv:0.5.27-python3.11-bookworm-slim AS builder
19+
20+
# Set working directory
21+
WORKDIR /app
22+
23+
# Copy core pyproject.toml and lockfile for dependency installation
24+
COPY src/core/pyproject.toml src/core/uv.lock* ./
25+
26+
# Install core dependencies using uv with cache mount
27+
RUN --mount=type=cache,target=/root/.cache/uv \
28+
uv pip install --system -r pyproject.toml
29+
30+
# Final runtime stage
31+
FROM python:3.11-slim
32+
33+
# Set metadata
34+
LABEL maintainer="OpenEnv Team"
35+
LABEL description="Base image for OpenEnv based environment servers with uv"
36+
LABEL version="0.2.0"
37+
38+
# Install system dependencies
39+
RUN apt-get update && apt-get install -y --no-install-recommends \
40+
curl \
41+
ca-certificates \
42+
&& rm -rf /var/lib/apt/lists/*
43+
44+
# Copy uv from builder
45+
COPY --from=builder /usr/local/bin/uv /usr/local/bin/uvx /usr/local/bin/
46+
47+
# Copy installed Python packages from builder
48+
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
49+
50+
# Set working directory
51+
WORKDIR /app
52+
53+
# Default environment variables
54+
ENV PYTHONPATH=/app/src
55+
ENV PYTHONUNBUFFERED=1
56+
ENV UV_SYSTEM_PYTHON=1
57+
58+
# Default expose port (can be overridden)
59+
EXPOSE 8000
60+
61+
# Note: CMD should be specified in child Dockerfiles

0 commit comments

Comments
 (0)