| Metadata-Version: 2.4 |
| Name: echo-cli |
| Version: 0.1.0 |
| Summary: Add your description here |
| Requires-Python: >=3.10 |
| Description-Content-Type: text/markdown |
|
|
| --- |
| title: Echo Environment Server |
| emoji: π |
| colorFrom: blue |
| colorTo: yellow |
| sdk: docker |
| pinned: false |
| app_port: 8000 |
| base_path: /web |
| tags: |
| - openenv |
| --- |
| |
| |
|
|
| A simple test environment that echoes back messages. Perfect for testing the env APIs as well as demonstrating environment usage patterns. |
|
|
| |
|
|
| The simplest way to use the Echo environment is through the `EchoEnv` class: |
|
|
| ```python |
| from envs.echo_env import EchoAction, EchoEnv |
|
|
| try: |
| |
| echo_env = EchoEnv.from_docker_image("echo-env:latest") |
|
|
| |
| result = echo_env.reset() |
| print(f"Reset: {result.observation.echoed_message}") |
| |
| # Send multiple messages |
| messages = ["Hello, World!", "Testing echo", "Final message"] |
|
|
| for msg in messages: |
| result = echo_env.step(EchoAction(message=msg)) |
| print(f"Sent: '{msg}'") |
| print(f" β Echoed: '{result.observation.echoed_message}'") |
| print(f" β Length: {result.observation.message_length}") |
| print(f" β Reward: {result.reward}") |
| |
| finally: |
| # Always clean up |
| echo_env.close() |
| ``` |
| |
| That's it! The `EchoEnv.from_docker_image()` method handles: |
| - Starting the Docker container |
| - Waiting for the server to be ready |
| - Connecting to the environment |
| - Container cleanup when you call `close()` |
| |
| ## Building the Docker Image |
| |
| Before using the environment, you need to build the Docker image: |
| |
| ```bash |
| # From project root |
| docker build -t echo-env:latest -f src/envs/echo_env/server/Dockerfile . |
| ``` |
| |
| ## Environment Details |
| |
| ### Action |
| **EchoAction**: Contains a single field |
| - `message` (str) - The message to echo back |
| |
| ### Observation |
| **EchoObservation**: Contains the echo response and metadata |
| - `echoed_message` (str) - The message echoed back |
| - `message_length` (int) - Length of the message |
| - `reward` (float) - Reward based on message length (length Γ 0.1) |
| - `done` (bool) - Always False for echo environment |
| - `metadata` (dict) - Additional info like step count |
| |
| ### Reward |
| The reward is calculated as: `message_length Γ 0.1` |
| - "Hi" β reward: 0.2 |
| - "Hello, World!" β reward: 1.3 |
| - Empty message β reward: 0.0 |
|
|
| |
|
|
| |
|
|
| If you already have an Echo environment server running, you can connect directly: |
|
|
| ```python |
| from envs.echo_env import EchoEnv |
|
|
| |
| echo_env = EchoEnv(base_url="<ENV_HTTP_URL_HERE>") |
|
|
| |
| result = echo_env.reset() |
| result = echo_env.step(EchoAction(message="Hello!")) |
| ``` |
|
|
| Note: When connecting to an existing server, `echo_env.close()` will NOT stop the server. |
|
|
| |
|
|
| |
|
|
| Test the environment logic directly without starting the HTTP server: |
|
|
| ```bash |
| |
| python3 src/envs/echo_env/server/test_echo_env.py |
| ``` |
|
|
| This verifies that: |
| - Environment resets correctly |
| - Step executes actions properly |
| - State tracking works |
| - Rewards are calculated correctly |
|
|
| |
|
|
| Run the complete example that demonstrates the full workflow: |
|
|
| ```bash |
| python3 examples/local_echo_env.py |
| ``` |
|
|
| This example shows: |
| - Creating an environment from a Docker image |
| - Resetting and stepping through the environment |
| - Automatic cleanup with `close()` |
|
|
| |
|
|
| ``` |
| echo_env/ |
| βββ __init__.py |
| βββ README.md |
| βββ client.py |
| βββ models.py |
| βββ server/ |
| βββ __init__.py |
| βββ echo_environment.py |
| βββ app.py |
| βββ test_echo_env.py |
| βββ Dockerfile |
| ``` |
|
|