Meta-Optimization Using Sequential Experiences — reset-free Gymnasium rollouts
Project description
Mouse Gym 🐭
Warning: Mouse Gym is in early development and is not yet ready for production use. APIs may change without notice.
Imagine an agent deployed to real users. It attempts a task, gets feedback, and learns something useful about how to complete that task. Then the session ends. Some time later, a similar situation recurs. But in the standard episodic setup, both the agent and the environment are treated as if they are starting from scratch. The task begins again, the history is gone, and the agent has to repeat the same learning process all over again. It must relearn what it already discovered because the continuity between interactions has been erased.
Humans do not learn this way. In the real world, people improve after attempting tasks multiple times. They learn on-the-job, make mistakes, adapt, and become better as they work. If we want agents that do not feel like retraining a new hire every single day, we have to train them to improve as related experience accumulates.
That shifts the focus from zero-shot performance — "How good is the agent immediately?" — to few-shot improvement — "How quickly does the agent get better as similar situations repeat?" Measuring that means watching performance across repeating episodes grouped into tasks — consecutive runs on the same env — not single isolated trials.
Gymnasium's usual loop treats every episode as independent (reset(), step(), reset()). mouse-gym wraps standard envs into a continuous stream: only step(), with episode and task boundaries visible in every output.
News
- 2026-07-07 — NumPy I/O Step inputs and outputs use NumPy arrays (Gymnasium-native types). PyTorch is no longer required.
- 2026-07-02 —
tracker→metricsRenamedenv.tracker/Tracker/GroupTrackertoenv.metrics/Metrics/GroupMetrics. Example notebook renamed to 04 — Metrics. - 2026-06-29 — Repository split Mouse Gym is now its own package. Reset-free rollout infrastructure lives here; custom environment implementations live elsewhere.
- 2026-06-26 —
SingleEnv/GroupEnvmake_envreturns one env;make_group_envhandles parallel rollouts.
See CHANGELOG.md for the full release history.
Install
Requirements: Python 3.12+, Gymnasium ≥ 1.3, NumPy ≥ 1.26 (NumPy is also pulled in by Gymnasium).
pip install mouse-gym
For development:
git clone https://github.com/micahr234/mouse-gym.git
cd mouse-gym
source scripts/install.sh
Quick start
from mouse_gym import EnvConfig, make_env
cfg = EnvConfig(
id="CartPole-v1",
reset_seed=0,
episodes_per_task=5,
)
env = make_env(cfg)
for _ in range(1000):
output = env.step(env.sample_random_input())
print(env.metrics.episode_cum_rewards)
env.close()
Differences from Gymnasium
mouse-gym builds on Gymnasium — you wrap ordinary Gymnasium envs and keep their observations, rewards, and spaces. What's different is the rollout interface:
-
Reset-free rollouts. Only call
step()—SingleEnv.reset()is not part of the API, including at task boundaries. When an episode or task ends, the nextstep()returns a reset frame: initial observation,time=0,done=0,reset_reward; the input is ignored. (Mouse-gym calls the underlying env's Gymnasiumreset()internally on that step — you never call it yourself.) One continuous loop; boundaries are fields in the output, not a separatereset()beforestep(). -
Dict I/O instead of Gymnasium's action + tuple. Pass
{"action": ...}tostep()(usesample_random_input()for random rollouts). Eachstep()returns one dict with named fields —observation,reward,done,time,episode_index,task_index, andinfo— rather than(observation, reward, terminated, truncated, info). -
Tasks group episodes. A task is a consecutive run of episodes — length set by
episodes_per_taskinEnvConfig(default0: no task boundary). When a task ends, the nextstep()is a reset frame withtask_indexincremented.donecodes3/4mark the last step of a task. -
donereplacesterminated/truncated. One integer field per step instead of two booleans:0— Running. A normal mid-episode step, or a reset frame (time=0,reward=reset_reward).1— Episode terminated. Underlying env returnedterminated=Trueand this is not the last episode in the task. Do not bootstrap; the nextstep()is a reset frame (next episode, same task).2— Episode truncated. Underlying env returnedtruncated=Trueand this is not the last episode in the task. Same semantics as1.3— Task terminated.terminated=Trueon the last episode in the task (perepisodes_per_task). Bootstrap here; the nextstep()is a reset frame that starts a new task (task_indexincrements).4— Task truncated.truncated=Trueon the last episode in the task. Same bootstrap semantics as3.- With
episodes_per_task=0(default), codes3and4never fire. Gymnasium has no task grouping or equivalent codes.
Additions to Gymnasium
On top of the standard env API, mouse-gym adds:
-
Metrics on the env. Episode returns and lengths accumulate in
env.metrics, not in thestep()return value. See 04 — Metrics. -
Grouped envs.
GroupEnvsteps multipleSingleEnvinstances sequentially in onestep()call and returns a flatlist[dict]— useful for mixed or multi-task setups without a vectorized wrapper. See 02 — Multiple envs. -
Input/output specs.
input_specandoutput_specdescribe the construction-time contract for step dict shapes and dtypes (onGroupEnv,input_specs[i]andoutput_specs[i]). See 01 — Random rollout.
Examples
The notebooks in examples/ are the detailed reference for EnvConfig, input/output fields, and day-to-day usage. Install notebook dependencies with pip install "mouse-gym[examples]", then work through them in order:
01 — Random rollout — Start here. Build an env from EnvConfig, run the reset-free step() loop, and inspect what comes back on each call: input dict (action), output dict (observation, reward, done, time, episode_index, task_index, info), reset frames, and done codes. Also covers input_spec / output_spec and optional env_fn factories.
02 — Multiple envs — Combine several env instances with make_group_env. Step heterogeneous envs (different ids, spaces, and seeds) in one sequential loop; read flat list[dict] inputs and outputs; use env.names, input_specs[i], and output_specs[i].
03 — RNG seeding control — Reproduce or vary behavior with reset_seed (internal reset stream) and env.action_space.seed() (random action sampling), independently.
04 — Metrics — Read episode returns and lengths from env.metrics, clear between eval runs, and aggregate stats across a GroupEnv.
Contributing
See CONTRIBUTING.md.
License
GNU General Public License v3.0 — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mouse_gym-0.1.0.tar.gz.
File metadata
- Download URL: mouse_gym-0.1.0.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cce1322976989142b088dde87ec31fb7de6d3964481c2645c4e22b8b69d0802
|
|
| MD5 |
d116cb953915bddc74750216ac437dee
|
|
| BLAKE2b-256 |
6398508a699036fb9472c547f95a3c1566ea05bcef5dafa09e5e3c74c41f5d3b
|
Provenance
The following attestation bundles were made for mouse_gym-0.1.0.tar.gz:
Publisher:
publish.yml on micahr234/mouse-gym
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mouse_gym-0.1.0.tar.gz -
Subject digest:
3cce1322976989142b088dde87ec31fb7de6d3964481c2645c4e22b8b69d0802 - Sigstore transparency entry: 2103456477
- Sigstore integration time:
-
Permalink:
micahr234/mouse-gym@0a430d5c2bfb4d6f941d0c771cbe51d998add63a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/micahr234
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0a430d5c2bfb4d6f941d0c771cbe51d998add63a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mouse_gym-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mouse_gym-0.1.0-py3-none-any.whl
- Upload date:
- Size: 26.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b233ccc72978482a593161d73734dd1a67b83b683715e6b639c5342cd4b9dc8c
|
|
| MD5 |
d3672cf1a65f66b7b41742424a3c700b
|
|
| BLAKE2b-256 |
5ace09b4f34b498de312e779511aae79c0b4766dbd31cee02ea29b24e347f26c
|
Provenance
The following attestation bundles were made for mouse_gym-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on micahr234/mouse-gym
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mouse_gym-0.1.0-py3-none-any.whl -
Subject digest:
b233ccc72978482a593161d73734dd1a67b83b683715e6b639c5342cd4b9dc8c - Sigstore transparency entry: 2103457032
- Sigstore integration time:
-
Permalink:
micahr234/mouse-gym@0a430d5c2bfb4d6f941d0c771cbe51d998add63a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/micahr234
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0a430d5c2bfb4d6f941d0c771cbe51d998add63a -
Trigger Event:
workflow_dispatch
-
Statement type: