Spaces:
Sleeping
Project File Structure
Target layout for the Nation Optimizer RL environment. The project uses
uv, TDD, centralized telemetry, and top-level Python packages.
Root
nation-optimizer-rl/
βββ README.md
βββ FILE_STRUCTURE.md
βββ pyproject.toml
βββ uv.lock # generated by uv
βββ Dockerfile
βββ openenv.yaml
βββ .gitignore
β
βββ assets/
β βββ poster.png # local optional; not tracked (Hub git rejects large binaries)
β βββ results/ # committed plots for judging
β
βββ specification/ # authoritative game design docs
β
βββ core/ # pure game engine, no OpenEnv/HF deps
βββ server/ # OpenEnv + FastAPI integration
βββ schemas/ # shared Action/Observation/Reward models
βββ agents/ # swappable policy adapters
βββ telemetry/ # central JSONL logging and metrics
βββ evaluation/ # seeded comparisons and plots
βββ training/ # TRL/Unsloth scripts and rollout datasets
β
βββ tests/
β βββ unit/
β βββ integration/
β βββ fixtures/
β
βββ scripts/ # thin CLI wrappers only
βββ notebooks/ # Colab-ready training notebooks
Top-level packages keep the repository easy to scan during the hackathon and match the existing core/ directory the environment team is already using.
Package Layout
core/
Pure game mechanics. This layer owns rules and state transitions:
- phase progression
- proposal and voting resolution
- treasury updates
- event generation and event impacts
- revenue, productivity, population, reward, termination
It must not import OpenEnv, Hugging Face clients, or agent implementations.
server/
OpenEnv adapter layer:
environment.py:MCPEnvironment/Environmentwrapper around coremodels.py: OpenEnv-facing request/response modelsapp.py: FastAPI/Space entrypoint
This layer translates between OpenEnv APIs and shared schemas. It should stay thin.
schemas/
Shared contracts used by core, server, agents, telemetry, evaluation, and tests:
actions.py:DEBATE,PROPOSE_BUDGET,VOTE,ABSTAIN_FROM_PROPOSALobservations.py: public/private phase-specific observation datarewards.py: reward components and per-step reward infometrics.py: episode and benchmark metricsphases.py: phase enum and phase/action mappingdepartments.py: department identifiers and defaults
Schemas are the integration contract. Agents should depend on these, not server internals.
agents/
Policy adapters that consume observations and emit structured actions:
agents/
βββ base.py
βββ action_parser.py
βββ prompts.py
βββ rule_based/
β βββ greedy.py
β βββ equal_split.py
β βββ conservative.py
β βββ optimal_zone.py
βββ llm/
β βββ hf_client.py
β βββ parliamentary.py
β βββ dictator.py
βββ trained/
βββ trl_policy.py
Every adapter implements the same contract:
adapter.act(observation, valid_actions, agent_id) -> Action
Adapters do not enforce game rules. They suggest actions; the environment validates and records outcomes.
telemetry/
Central logging is a first-order feature:
events.py: structured telemetry event typesepisode_logger.py: in-memory and file-backed episode loggerjsonl_writer.py: append-only JSONL sinkmetrics_collector.py: episode and benchmark aggregationplotter.py: reward/loss/result plots for README and judging
Default artifact format is JSONL so rollouts can be inspected, plotted, or converted into training data.
evaluation/
Benchmarking and comparison code:
run_episode.py: run one seeded episodebenchmark_policies.py: compare adapters on shared seedscompare_adapters.py: greedy vs equal split vs parliament vs dictatorseed_sweep.py: reproducible multi-seed evaluation
training/
Hackathon training artifacts:
build_rollout_dataset.py: convert telemetry JSONL into supervised/preference datatrain_trl.py: minimal HF TRL training scriptreward_curve.py: plot training progress
Training code should be runnable locally with uv and portable to Colab/HF.
Dependency Direction
flowchart TD
Scripts[Scripts] --> Evaluation
Notebooks[Notebooks] --> Training
Server[OpenEnv Server] --> Core
Server --> Schemas
Agents[Policy Adapters] --> Schemas
Evaluation --> Agents
Evaluation --> Telemetry
Evaluation --> Server
Training --> Telemetry
Training --> Agents
Core --> Schemas
Telemetry --> Schemas
Allowed dependency flow:
corecan depend onschemas.servercan depend oncoreandschemas.agentscan depend onschemasonly, plus optional provider clients.evaluationcoordinatesserver,agents, andtelemetry.trainingconsumes telemetry and trained-policy adapters.
Forbidden:
- agents importing core internals
- clients importing server internals
- core importing OpenEnv, FastAPI, TRL, or Hugging Face clients
- direct agent-agent communication outside environment observations
TDD Checklist
Start each slice with tests:
tests/unit/test_action_schema.pytests/unit/test_observation_schema.pytests/unit/test_greedy_adapter.pytests/unit/test_equal_split_adapter.pytests/unit/test_episode_logger.pytests/integration/test_mock_env_episode.pytests/integration/test_openenv_contract.pytests/integration/test_policy_benchmark_smoke.py
Standard commands:
uv sync
uv run pytest
uv run python -m evaluation.benchmark_policies
Implementation Phases
- Shared schemas and adapter interface.
- Central telemetry with JSONL output.
- Rule-based baselines against mock observations.
- Mock phased environment contract for adapter development.
- OpenEnv wrapper integration once core loop is ready.
- LLM adapters with strict JSON actions and prompt/action logging.
- Seeded baseline comparisons and committed plots.
- TRL/Unsloth training script and Colab-ready notebook.