# nvlabs/enpire architecture

> Architecture diagram of the GitHub repository nvlabs/enpire, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nvlabs/enpire
- Repository: https://github.com/nvlabs/enpire

## Overview

ENPIRE is a real-world robot-policy improvement harness. Its documented workflow resets an environment, runs a policy on a robot, verifies and records the result, then uses evidence to refine the next experiment. Code-as-Policy and real-world RL are distinct improvement paths; station tooling supports both. The README establishes the overall loop, while sampled files show selected CAP-agent, UI, and RL relationships. Other subsystem links are documented capabilities rather than inspected call paths.

Main entry points: [`enpire/policy/rl/context.py`](https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/context.py) (RL actor context), [`enpire/env/forge/cap/agent/agent_step.py`](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/agent_step.py) (Generate and execute steps), [`enpire/env/forge/cap/agent/agent_pipeline.py`](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/agent_pipeline.py) (Agent iteration loop), [`enpire/env/forge/cap/env/real_bimanual_yam/env.py`](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/env/real_bimanual_yam/env.py) (Task environment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_environment["Environment and station"]
  node_task_env["Task environment<br/>[env.py]"]
  node_station["Robot and station<br/>[yam_controller.py]"]
  node_calibration["Station calibration<br/>[calibrator.py]"]
end

subgraph group_cap["Code-as-Policy"]
  node_cap_ui["CAP operator UI<br/>[App.tsx]"]
  node_cap_api["CAP UI API client<br/>[client.ts]"]
  node_agent_pipeline["Agent iteration loop<br/>[agent_pipeline.py]"]
  node_agent_context["Agent run context<br/>[agent_context.py]"]
  node_agent_steps["Generate and execute steps<br/>[agent_step.py]"]
  node_llm["LLM backend interface<br/>[base.py]"]
  node_skills["Skill scripts and library<br/>[skill_library.py]"]
end

subgraph group_rl["Real-world RL"]
  node_rl_context["RL actor context<br/>[context.py]"]
  node_rl_config["RL configuration<br/>[config.py]"]
  node_rl_handlers["Reset and safety handlers<br/>[handlers.py]"]
  node_rl_policy["RL policy runtime<br/>[policy.py]"]
  node_rl_learner["Policy learner<br/>[learner.py]"]
  node_rollout_recording["Rollout recording"]
end

subgraph group_evolution["Evaluation and refinement"]
  node_reward["Reward verification<br/>[evaluator.py]"]
  node_reflection["Failure analysis and reflection<br/>[reflection.py]"]
  node_experiment_data[("Experiment outcomes")]
end

node_researcher(("Researcher or agent"))
node_cli["ENPIRE CLI<br/>[cli.py]"]

node_researcher -->|"starts runs"| node_cli
node_cli -->|"runs examples"| node_task_env
node_researcher -.->|"operates"| node_cap_ui
node_cap_ui -->|"requests actions"| node_cap_api
node_cap_api -.->|"calls services"| node_agent_pipeline
node_agent_pipeline -->|"updates context"| node_agent_context
node_agent_pipeline -->|"runs steps"| node_agent_steps
node_agent_steps -->|"reads and writes"| node_agent_context
node_agent_steps -->|"generates code"| node_llm
node_agent_steps -.->|"executes scripts"| node_skills
node_task_env -.->|"runs on robot"| node_station
node_calibration -.->|"calibrates"| node_station
node_researcher -.->|"starts training"| node_rl_context
node_rl_context -->|"uses settings"| node_rl_config
node_rl_context -.->|"handles resets"| node_rl_handlers
node_rl_context -->|"routes actions"| node_rl_policy
node_rl_context -->|"coordinates learner"| node_rl_learner
node_task_env -.->|"verifies outcomes"| node_reward
node_rl_context -->|"wraps episodes"| node_rollout_recording
node_rollout_recording -.->|"records episodes"| node_experiment_data
node_reward -.->|"informs refinement"| node_reflection
node_reflection -.->|"guides next iteration"| node_agent_pipeline
node_rl_learner -.->|"improves policy"| node_rl_policy

click node_cli "https://github.com/nvlabs/enpire/blob/main/enpire/cli.py"
click node_task_env "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/env/real_bimanual_yam/env.py"
click node_station "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/robot/yam/yam_controller.py"
click node_calibration "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/yam/calibration/calibrator.py"
click node_cap_ui "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/ui/src/App.tsx"
click node_cap_api "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/ui/src/api/client.ts"
click node_agent_pipeline "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/agent_pipeline.py"
click node_agent_context "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/agent_context.py"
click node_agent_steps "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/agent_step.py"
click node_llm "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/llm/base.py"
click node_skills "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/skill_library.py"
click node_rl_context "https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/context.py"
click node_rl_config "https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/config.py"
click node_rl_handlers "https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/handlers.py"
click node_rl_policy "https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/policy.py"
click node_rl_learner "https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/learner.py"
click node_rollout_recording "https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/record_episode_wrapper.py"
click node_reward "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/reward/evaluator.py"
click node_reflection "https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/reflection.py"
click node_experiment_data "https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/record_episode_wrapper.py"

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_task_env,node_station,node_calibration toneBlue
class node_cap_ui,node_cap_api,node_agent_pipeline,node_agent_context,node_agent_steps,node_llm,node_skills toneAmber
class node_rl_context,node_rl_config,node_rl_handlers,node_rl_policy,node_rl_learner,node_rollout_recording toneMint
class node_reward,node_reflection,node_experiment_data toneRose
class node_researcher toneIndigo
class node_cli toneTeal
```

## Components

### Environment and station

- [Task environment](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/env/real_bimanual_yam/env.py): `enpire/env/forge/cap/env/real_bimanual_yam/env.py`
- [Robot and station](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/robot/yam/yam_controller.py): `enpire/env/forge/robot/yam/yam_controller.py`
- [Station calibration](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/yam/calibration/calibrator.py): `enpire/env/forge/yam/calibration/calibrator.py`

### Code-as-Policy

- [CAP operator UI](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/ui/src/App.tsx): `enpire/env/forge/cap/ui/src/App.tsx`
- [CAP UI API client](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/ui/src/api/client.ts): `enpire/env/forge/cap/ui/src/api/client.ts`
- [Agent iteration loop](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/agent_pipeline.py): `enpire/env/forge/cap/agent/agent_pipeline.py`
- [Agent run context](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/agent_context.py): `enpire/env/forge/cap/agent/agent_context.py`
- [Generate and execute steps](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/agent_step.py): `enpire/env/forge/cap/agent/agent_step.py`
- [LLM backend interface](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/llm/base.py): `enpire/env/forge/cap/agent/llm/base.py`
- [Skill scripts and library](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/skill_library.py): `enpire/env/forge/cap/agent/skill_library.py`

### Real-world RL

- [RL actor context](https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/context.py): `enpire/policy/rl/context.py`
- [RL configuration](https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/config.py): `enpire/policy/rl/config.py`
- [Reset and safety handlers](https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/handlers.py): `enpire/policy/rl/handlers.py`
- [RL policy runtime](https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/policy.py): `enpire/policy/rl/policy.py`
- [Policy learner](https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/learner.py): `enpire/policy/rl/learner.py`
- [Rollout recording](https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/record_episode_wrapper.py): `enpire/policy/rl/record_episode_wrapper.py`

### Evaluation and refinement

- [Reward verification](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/reward/evaluator.py): `enpire/env/forge/cap/reward/evaluator.py`
- [Failure analysis and reflection](https://github.com/nvlabs/enpire/blob/main/enpire/env/forge/cap/agent/reflection.py): `enpire/env/forge/cap/agent/reflection.py`
- [Experiment outcomes](https://github.com/nvlabs/enpire/blob/main/enpire/policy/rl/record_episode_wrapper.py): `enpire/policy/rl/record_episode_wrapper.py`

### Other components

- **Researcher or agent**
- [ENPIRE CLI](https://github.com/nvlabs/enpire/blob/main/enpire/cli.py): `enpire/cli.py`

## Connections

- Researcher or agent → ENPIRE CLI: starts runs (evidence: `README.md`)
- ENPIRE CLI → Task environment: runs examples (evidence: `enpire/cli.py`)
- Researcher or agent → CAP operator UI: operates
- CAP operator UI → CAP UI API client: requests actions (evidence: `enpire/env/forge/cap/ui/src/App.tsx`)
- CAP UI API client → Agent iteration loop: calls services
- Agent iteration loop → Agent run context: updates context (evidence: `enpire/env/forge/cap/agent/agent_pipeline.py`)
- Agent iteration loop → Generate and execute steps: runs steps (evidence: `enpire/env/forge/cap/agent/agent_pipeline.py`)
- Generate and execute steps → Agent run context: reads and writes (evidence: `enpire/env/forge/cap/agent/agent_step.py`)
- Generate and execute steps → LLM backend interface: generates code (evidence: `enpire/env/forge/cap/agent/agent_step.py`)
- Generate and execute steps → Skill scripts and library: executes scripts
- Task environment → Robot and station: runs on robot
- Station calibration → Robot and station: calibrates
- Researcher or agent → RL actor context: starts training
- RL actor context → RL configuration: uses settings (evidence: `enpire/policy/rl/context.py`)
- RL actor context → Reset and safety handlers: handles resets (evidence: `enpire/policy/rl/handlers.py`)
- RL actor context → RL policy runtime: routes actions (evidence: `enpire/policy/rl/context.py`)
- RL actor context → Policy learner: coordinates learner (evidence: `enpire/policy/rl/context.py`)
- Task environment → Reward verification: verifies outcomes
- RL actor context → Rollout recording: wraps episodes (evidence: `enpire/policy/rl/context.py`)
- Rollout recording → Experiment outcomes: records episodes
- Reward verification → Failure analysis and reflection: informs refinement
- Failure analysis and reflection → Agent iteration loop: guides next iteration (evidence: `enpire/env/forge/cap/agent/agent_pipeline.py`)
- Policy learner → RL policy runtime: improves policy
