# ydnyshhh/async-rl-lab architecture

> Architecture diagram of the GitHub repository ydnyshhh/async-rl-lab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ydnyshhh/async-rl-lab
- Repository: https://github.com/ydnyshhh/async-rl-lab

## Overview

1. **Project shape**
   - This is a small, typed Python package (`src/async_rl_lab`) for async reinforcement learning / agentic training experiments.
   - It is organized as a library plus a demo entrypoint, with unit tests covering each subsystem and a CI workflow for validation.

2. **Top-level architecture**
   - The code is split into clear boundaries: **runtime orchestration**, **data buffering**, **policy/inference**, **objectives**, **environments/tools**, **verification**, and **serialization/persistence**.
   - The package is intentionally research-oriented rather than application-specific, so most modules are reusable components wired together by the runtime.

3. **Runtime orchestration**
   - `runtime.py` is the central coordination layer.
   - It likely owns the asynchronous training loop: launching rollouts, receiving results, tracking policy lag, dispatching inference requests, and feeding data into objective computation.
   - `demo.py` is the executable example that exercises the whole stack end-to-end.

4. **Rollout and event flow**
   - `events.py` defines the messages or records that move between subsystems.
   - `buffer.py` is the central storage for trajectory fragments, grouped rollouts, or experience batches before they are consumed by objectives.
   - The architecture suggests an async producer/consumer flow: environments generate interactions, the buffer accumulates them, and the learner/runtime drains them for optimization.

5. **Policy and inference boundary**
   - `models.py` and `inference.py` separate model definitions from serving/inference execution.
   - `policy_store.py` implies a versioned policy registry or cache, which is important for **policy lag** and asynchronous rollouts where actors may use stale policies.
   - `ids.py` likely provides stable identifiers for policies, runs, rollouts, or requests so components can correlate async messages.

6. **Environment and tool-use layer**
   - `environments.py` and `tools.py` define the interaction surface for agentic tasks.
   - This is the boundary where the RL system talks to task environments and external tools, which matters because rollout latency and tool execution are part of the learning signal and system behavior.
   - The README’s emphasis on “tool-use environments” indicates this is not just classic vectorized RL; the environment layer is designed for agent-like sequences.

7. **Objectives and learning logic**
   - `objectives.py` contains the GRPO-family / group-based optimization logic.
   - The repo’s focus on grouped rollouts suggests the objective consumes sets of candidate trajectories rather than single-step transitions.
   - This module is the algorithmic heart of the library and is separated from runtime mechanics so different training objectives can be swapped in.

8. **Verification and metrics**
   - `verifiers.py` represents reward/validation logic, likely including asynchronous or delayed evaluation of completions.
   - `metrics.py` collects training and system measurements, especially relevant here because the README calls out verifier latency as a first-class concern.
   - This creates a distinct evaluation path: rollout output is not only trained on, but also checked/scored by verifiers whose timing affects the async pipeline.

9. **Serialization and persistence**
   - `serialization.py` handles object encoding/decoding for moving data across process boundaries or storing policies/rollouts.
   - Together with `policy_store.py`, it forms the persistence boundary between in-memory runtime state and durable artifacts.
   - This is important for async systems where actors, learners, and verifiers may not share process memory.

10. **Testing and validation**
   - The `tests/` directory covers the main subsystems individually: buffer, inference, objectives, parser, policy store, runtime, runtime environment, serialization, and verifiers.
   - That test layout mirrors the architecture and indicates the repository is designed around composable modules with stable contracts.

11. **Packaging and runtime environment**
   - The project uses modern Python packaging (`pyproject.toml`, `uv.lock`, `.python-version`) and ships type hints (`py.typed`).
   - There is an optional Hugging Face-related extra in the README, suggesting an alternate model backend or integration path, but the core architecture does not depend on it.

12. **How data likely moves through the system**
   - At a high level: the runtime starts policies/inference, environments produce grouped interactions, events are buffered, verifiers score outputs, metrics are recorded, and objectives consume completed batches to update or rank policies.
   - The main architectural concern is coordinating asynchronous timing across rollout generation, inference serving, verification, and policy refresh.

13. **Diagramming guidance**
   - A good architecture diagram should show four main planes: **orchestration**, **experience generation**, **learning/objective computation**, and **evaluation/persistence**.
   - The critical boundaries are between environment/tool execution, inference serving, policy storage/versioning, and verifier-based scoring.

Main entry points: [`src/async_rl_lab/runtime.py`](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/runtime.py) (Runtime), [`tests`](https://github.com/ydnyshhh/async-rl-lab/tree/main/tests) (Tests), [`src/async_rl_lab/buffer.py`](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/buffer.py) (Buffer), [`src/async_rl_lab/inference.py`](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/inference.py) (Inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Orchestration"]
  node_runtime["Runtime<br/>async coordinator<br/>[runtime.py]"]
  node_demo(("Demo<br/>entrypoint<br/>[demo.py]"))
  node_events["Events<br/>message schema<br/>[events.py]"]
  node_buffer[("Buffer<br/>experience store<br/>[buffer.py]")]
  node_ids["IDs<br/>identity types<br/>[ids.py]"]
end

subgraph group_experience["Experience"]
  node_environments["Environments<br/>task runtime<br/>[environments.py]"]
  node_tools["Tools<br/>tooling layer<br/>[tools.py]"]
end

subgraph group_learning["Learning"]
  node_models["Models<br/>[models.py]"]
  node_inference["Inference<br/>serving layer<br/>[inference.py]"]
  node_objectives{{"Objectives<br/>optimization logic<br/>[objectives.py]"}}
end

subgraph group_evaluation["Evaluation"]
  node_policy_store[("Policy Store<br/>versioned cache<br/>[policy_store.py]")]
  node_verifiers["Verifiers<br/>reward checks<br/>[verifiers.py]"]
  node_metrics["Metrics<br/>telemetry<br/>[metrics.py]"]
  node_serialization["Serialization<br/>codec layer<br/>[serialization.py]"]
end

node_tests["Tests<br/>validation suite"]
node_ci["CI<br/>workflow<br/>[ci.yml]"]

node_demo -->|"starts"| node_runtime
node_runtime -->|"drives"| node_environments
node_environments -->|"uses"| node_tools
node_environments -->|"emits"| node_events
node_runtime -->|"requests"| node_inference
node_inference -->|"executes"| node_models
node_runtime -->|"stores"| node_buffer
node_buffer -->|"feeds"| node_objectives
node_events -->|"accumulates"| node_buffer
node_runtime -->|"reads/writes"| node_policy_store
node_policy_store -->|"serves"| node_inference
node_runtime -->|"updates"| node_objectives
node_runtime -->|"submits"| node_verifiers
node_verifiers -->|"records"| node_metrics
node_runtime -->|"reports"| node_metrics
node_runtime -->|"encodes"| node_serialization
node_serialization -->|"persists"| node_policy_store
node_tests -.->|"covers"| node_buffer
node_tests -.->|"covers"| node_inference
node_tests -.->|"covers"| node_objectives
node_tests -.->|"covers"| node_runtime
node_tests -.->|"covers"| node_serialization
node_tests -.->|"covers"| node_verifiers
node_ci -->|"runs"| node_tests

click node_runtime "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/runtime.py"
click node_demo "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/demo.py"
click node_events "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/events.py"
click node_buffer "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/buffer.py"
click node_environments "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/environments.py"
click node_tools "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/tools.py"
click node_ids "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/ids.py"
click node_models "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/models.py"
click node_inference "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/inference.py"
click node_policy_store "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/policy_store.py"
click node_objectives "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/objectives.py"
click node_verifiers "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/verifiers.py"
click node_metrics "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/metrics.py"
click node_serialization "https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/serialization.py"
click node_tests "https://github.com/ydnyshhh/async-rl-lab/tree/main/tests"
click node_ci "https://github.com/ydnyshhh/async-rl-lab/blob/main/.github/workflows/ci.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_runtime,node_demo,node_events,node_buffer,node_ids toneBlue
class node_environments,node_tools toneAmber
class node_models,node_inference,node_objectives toneMint
class node_policy_store,node_verifiers,node_metrics,node_serialization toneRose
class node_tests,node_ci toneNeutral
```

## Components

### Orchestration

Async runtime that coordinates rollout, inference, buffering, and training.

- [Runtime](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/runtime.py): async coordinator · Central async loop that wires rollout, inference, buffering, verification, and updates. · `src/async_rl_lab/runtime.py`
- [Demo](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/demo.py): entrypoint · Executable example that exercises the stack end to end. · `src/async_rl_lab/demo.py`
- [Events](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/events.py): message schema · Shared records passed between producers, learners, and verifiers. · `src/async_rl_lab/events.py`
- [Buffer](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/buffer.py): experience store · Holds trajectory fragments and grouped rollouts before consumption. · `src/async_rl_lab/buffer.py`
- [IDs](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/ids.py): identity types · Stable identifiers for policies, runs, rollouts, and requests. · `src/async_rl_lab/ids.py`

### Experience

Environment and tool-use layer that produces interactions and events.

- [Environments](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/environments.py): task runtime · Defines agent interaction surfaces and rollout environments. · `src/async_rl_lab/environments.py`
- [Tools](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/tools.py): tooling layer · External tool-use interfaces available to agentic environments. · `src/async_rl_lab/tools.py`

### Learning

Policy, objectives, and model/inference components.

- [Models](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/models.py): policy models · Policy and model definitions used by inference and training. · `src/async_rl_lab/models.py`
- [Inference](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/inference.py): serving layer · Runs model execution for actors and runtime requests. · `src/async_rl_lab/inference.py`
- [Objectives](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/objectives.py): optimization logic · Implements group-based training objectives and scoring rules. · `src/async_rl_lab/objectives.py`

### Evaluation

Verification, metrics, serialization, and persistent state.

- [Policy Store](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/policy_store.py): versioned cache · Tracks policy versions and supports asynchronous policy lag. · `src/async_rl_lab/policy_store.py`
- [Verifiers](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/verifiers.py): reward checks · Scores outputs and performs validation with possible latency. · `src/async_rl_lab/verifiers.py`
- [Metrics](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/metrics.py): telemetry · Collects training and system measurements across the async pipeline. · `src/async_rl_lab/metrics.py`
- [Serialization](https://github.com/ydnyshhh/async-rl-lab/blob/main/src/async_rl_lab/serialization.py): codec layer · Encodes and decodes objects across process and persistence boundaries. · `src/async_rl_lab/serialization.py`

### Other components

- [Tests](https://github.com/ydnyshhh/async-rl-lab/tree/main/tests): validation suite · Subsystem coverage for buffer, inference, objectives, runtime, serialization, and verifiers. · `tests`
- [CI](https://github.com/ydnyshhh/async-rl-lab/blob/main/.github/workflows/ci.yml): workflow · Automated validation pipeline for the repository. · `.github/workflows/ci.yml`

## Connections

- Demo → Runtime: starts · Demo drives the full async system through the runtime.
- Runtime → Environments: drives · Runtime launches and coordinates environment interaction.
- Environments → Tools: uses · Environments call out to tools during agent execution.
- Environments → Events: emits · Rollout interactions are converted into shared events.
- Runtime → Inference: requests · Runtime dispatches inference work for actors and learners.
- Inference → Models: executes · Inference serves model/policy definitions.
- Runtime → Buffer: stores · Completed fragments and grouped rollouts are buffered.
- Buffer → Objectives: feeds · Buffered batches are consumed by the learning objective.
- Events → Buffer: accumulates · Event stream is aggregated into rollout storage.
- Runtime → Policy Store: reads/writes · Runtime manages policy versions and actor freshness.
- Policy Store → Inference: serves · Inference can be backed by the current policy version.
- Runtime → Objectives: updates · Runtime applies optimization logic to completed data.
- Runtime → Verifiers: submits · Runtime sends outputs for delayed or async validation.
- Verifiers → Metrics: records · Verification results contribute to telemetry and analysis.
- Runtime → Metrics: reports · Core loop publishes system and training measurements.
- Runtime → Serialization: encodes · Runtime serializes data for boundaries and persistence.
- Serialization → Policy Store: persists · Serialized artifacts support durable policy storage.
- Tests → Buffer: covers · Tests validate buffer behavior.
- Tests → Inference: covers · Tests validate inference behavior.
- Tests → Objectives: covers · Tests validate objective logic.
- Tests → Runtime: covers · Tests validate orchestration behavior.
- Tests → Serialization: covers · Tests validate encoding and decoding.
- Tests → Verifiers: covers · Tests validate verification behavior.
- CI → Tests: runs · CI executes the test suite for validation.
