Gymnasium api - #1350
Conversation
✅ Deploy Preview for agent-sandbox ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: drogovozDP The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Important Review skippedAuto reviews are limited based on label configuration. 🚫 Review skipped — only excluded labels are configured. (3)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @drogovozDP. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
There was a problem hiding this comment.
Pull request overview
This PR adds a Gymnasium-style RL environment interface for Agent Sandbox (Python) and provides an end-to-end example (FastAPI sandbox runtime + Kubernetes manifests + a Jupyter notebook) to demonstrate training/fine-tuning workflows against remote sandbox pods.
Changes:
- Adds
SandboxEnv+ reward/termination function abstractions to the Python SDK (k8s_agent_sandbox.sandbox_env) with anrloptional extra for Gymnasium. - Introduces a standalone integration package under
clients/integrations/gymnasium(with unit tests) that exposes similar Gymnasium APIs. - Adds a tutorial example under
examples/agent-sandbox-gymnasium/including build artifacts, manifests, and a training notebook.
Reviewed changes
Copilot reviewed 29 out of 30 changed files in this pull request and generated 31 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/agent-sandbox-gymnasium/source/main.py | Adds a FastAPI runtime that executes commands inside the sandbox container. |
| examples/agent-sandbox-gymnasium/source/Dockerfile | Builds the example runtime image. |
| examples/agent-sandbox-gymnasium/source/cloudbuild.yaml | Cloud Build recipe for publishing the example runtime image. |
| examples/agent-sandbox-gymnasium/sandbox/template.yaml | SandboxTemplate for running the example runtime image. |
| examples/agent-sandbox-gymnasium/sandbox/warmpool.yaml | SandboxWarmPool for pre-warming sandboxes for RL workloads. |
| examples/agent-sandbox-gymnasium/README.md | Tutorial instructions for deploying and running the example. |
| examples/agent-sandbox-gymnasium/jupyter/rl_training.ipynb | Demonstrates using the env and a training loop from Jupyter. |
| examples/agent-sandbox-gymnasium/jupyter/jupyter.yaml | Deploys a GPU Jupyter instance to run the tutorial notebook. |
| examples/agent-sandbox-gymnasium/jupyter/jupyter-rbac.yaml | RBAC allowing the Jupyter pod to manage SandboxClaims/Sandboxes. |
| clients/python/agentic-sandbox-client/pyproject.toml | Adds an rl extra dependency for Gymnasium usage. |
| clients/python/agentic-sandbox-client/k8s_agent_sandbox/sandbox_env/gymnasium_env.py | SDK-native Gymnasium env implementation (connection modes + lifecycle). |
| clients/python/agentic-sandbox-client/k8s_agent_sandbox/sandbox_env/reward_fn.py | Reward function interface for RL tasks. |
| clients/python/agentic-sandbox-client/k8s_agent_sandbox/sandbox_env/reward_fns.py | Concrete reward implementations (sparse, step penalty, etc.). |
| clients/python/agentic-sandbox-client/k8s_agent_sandbox/sandbox_env/termination_fn.py | Termination function interface for episode termination. |
| clients/python/agentic-sandbox-client/k8s_agent_sandbox/sandbox_env/termination_fns.py | Concrete termination function(s). |
| clients/python/agentic-sandbox-client/k8s_agent_sandbox/sandbox_env/init.py | Re-exports for sandbox_env module. |
| clients/integrations/gymnasium/pyproject.toml | Defines the standalone k8s-agent-sandbox-gymnasium integration package. |
| clients/integrations/gymnasium/k8s_agent_sandbox_gymnasium/gymnasium_env.py | Standalone integration Gymnasium env implementation. |
| clients/integrations/gymnasium/k8s_agent_sandbox_gymnasium/reward_fn.py | Reward function interface for the integration package. |
| clients/integrations/gymnasium/k8s_agent_sandbox_gymnasium/reward_fns.py | Reward implementations for the integration package. |
| clients/integrations/gymnasium/k8s_agent_sandbox_gymnasium/termination_fn.py | Termination function interface for the integration package. |
| clients/integrations/gymnasium/k8s_agent_sandbox_gymnasium/termination_fns.py | Termination implementations for the integration package. |
| clients/integrations/gymnasium/k8s_agent_sandbox_gymnasium/init.py | Re-exports for the integration package. |
| clients/integrations/gymnasium/tests/unit/test_gymnasium_env.py | Unit tests for the integration env. |
| clients/integrations/gymnasium/tests/unit/test_reward_fn.py | Unit tests for RewardFn. |
| clients/integrations/gymnasium/tests/unit/test_reward_fns.py | Unit tests for reward implementations. |
| clients/integrations/gymnasium/tests/unit/test_termination_fn.py | Unit tests for TerminationFn. |
| clients/integrations/gymnasium/tests/unit/test_termination_fns.py | Unit tests for termination implementations. |
| clients/integrations/gymnasium/tests/unit/init.py | Test package marker. |
| result = subprocess.run( | ||
| req.command, | ||
| shell=True, | ||
| capture_output=True, | ||
| text=True, | ||
| executable="/bin/bash", | ||
| timeout=60 | ||
| ) |
| gcloud container clusters create-auto sandbox-rl-cluster --location=us-east1 | ||
| ``` | ||
|
|
||
| Follow the instructions from oficial guide to [install Agent Sandbox CRDs and Router](https://github.com/kubernetes-sigs/agent-sandbox#installation). |
| - apiGroups: ["extensions.agents.x-k8s.io"] | ||
| resources: ["sandboxclaims", "sandboxes"] | ||
| verbs: ["get", "list", "watch", "create", "delete"] | ||
| - apiGroups: ["agents.x-k8s.io"] | ||
| resources: ["sandboxes", "sandboxclaims"] | ||
| verbs: ["get", "list", "watch", "create", "delete"] |
| - name: jupyter | ||
| image: tensorflow/tensorflow:latest-gpu-jupyter |
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "!pip install \"git+https://github.com/volatilemolotov/agent-sandbox.git@gymnasium-api#subdirectory=clients/integrations/gymnasium\" --upgrade" |
| @@ -0,0 +1 @@ | |||
| # Unit tests No newline at end of file | |||
| def __init__( | ||
| self, | ||
| reward_fn: RewardFn, | ||
| termination_fn: TerminationFn, | ||
| warmpool: str = "simple-sandbox-warmpool", | ||
| namespace: str = "default", | ||
| client: SandboxClient = None, | ||
| max_episode_steps: int = 20, | ||
| max_obs_length: int = 4096, | ||
| ): | ||
| super().__init__() | ||
|
|
||
| if not isinstance(reward_fn, RewardFn): | ||
| raise TypeError(f"reward_fn must be a RewardFn instance, got {type(reward_fn)}") | ||
|
|
||
| self.reward_fn = reward_fn | ||
| self.termination_fn = termination_fn | ||
| self.warmpool = warmpool | ||
| self.namespace = namespace | ||
| self.max_episode_steps = max_episode_steps | ||
| self.max_obs_length = max_obs_length | ||
|
|
||
| self._client = client | ||
| self._sandbox = None |
| class SparseTaskTermination(TerminationFn): | ||
| """ | ||
| Returns True if obs["reward"] == 1 and False otherwise | ||
|
|
||
| Example: | ||
| termination_fn = SparseTaskTermination() | ||
| """ |
| "The 'gymnasium' library is required to use 'k8s_agent_sandbox.sandbox_env'. " | ||
| "Please install the 'rl' extra: `pip install 'k8s-agent-sandbox[rl]'` " | ||
| "or install gymnasium directly: `pip install gymnasium`." |
| [project] | ||
| name = "k8s-agent-sandbox-gymnasium" | ||
| description = "Gymnasium-compatible RL environments backed by kubernetes-sigs/agent-sandbox" | ||
| readme = "README.md" | ||
| requires-python = ">=3.10" |
This is an example PR. The goal: highlight the potential changes. This example PR provides:
clients/integrations/gymnasium: a gymnasium integration itself.example/agent-sandbox-gymnasium: a small tutorial on how to useSandboxEnv.