# memtensor/memrl architecture

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

- Interactive diagram: https://gitdiagram.com/memtensor/memrl
- Repository: https://github.com/memtensor/memrl

## Overview

MemRL is a runtime-learning agent system: benchmark runners execute tasks, the agent uses an LLM to act, and MemoryService retrieves episodic strategies and updates memory from outcomes without changing model weights. Its documented benchmark branches cover HLE, ALFWorld, Lifelong Agent Bench (LLB), and BigCodeBench (BCB); LLB also has optional JSONL tracing. The graph uses the README and SOURCE INDEX references for relationships; unsampled implementations are represented only at paths present in the tree.

Main entry points: [`memrl/service/memory_service.py`](https://github.com/memtensor/memrl/blob/main/memrl/service/memory_service.py) (Memory service), [`memrl/run/llb_rl_runner.py`](https://github.com/memtensor/memrl/blob/main/memrl/run/llb_rl_runner.py) (LLB runner), [`memrl/providers/llm.py`](https://github.com/memtensor/memrl/blob/main/memrl/providers/llm.py) (LLM provider), [`memrl/run/alfworld_rl_runner.py`](https://github.com/memtensor/memrl/blob/main/memrl/run/alfworld_rl_runner.py) (ALFWorld runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_execution["Agent execution"]
  node_cli["CLI<br/>[main.py]"]
  node_agent["Memory agent<br/>[memp_agent.py]"]
  node_agent_history["Agent history<br/>[history.py]"]
end

subgraph group_memory["Episodic memory"]
  node_memory_service["Memory service<br/>[memory_service.py]"]
  node_memory_build["Memory building<br/>[builders.py]"]
  node_memory_retrieval["Memory retrieval<br/>[retrievers.py]"]
  node_memory_update["Memory update<br/>[updater.py]"]
  node_memory_strategies["Strategy config<br/>[strategies.py]"]
  node_value_learning["Value learning<br/>[value_driven.py]"]
end

subgraph group_models["Model providers"]
  node_llm["LLM provider<br/>[llm.py]"]
  node_embeddings["Embedding provider<br/>[embedding.py]"]
end

subgraph group_benchmarks["Benchmark integrations"]
  node_hle_runner["HLE runner<br/>[hle_runner.py]"]
  node_alfworld_runner["ALFWorld runner"]
  node_alfworld_env["ALFWorld environment<br/>[alfworld_env.py]"]
  node_llb_runner["LLB runner<br/>[llb_rl_runner.py]"]
  node_llb_adapter["LLB task adapter<br/>[task_wrappers.py]"]
  node_bcb_runner["BCB runner<br/>[bcb_runner.py]"]
  node_bcb_adapter["BCB adapter<br/>[bcb_adapter.py]"]
end

subgraph group_observability["Tracing"]
  node_trace_wrapper["Tracing LLM<br/>[tracing_llm.py]"]
  node_llb_trace["LLB JSONL trace<br/>[llb_jsonl.py]"]
end

node_user(("Experiment operator"))
node_benchmark_tasks["Benchmark tasks"]

node_user -->|"starts runs"| node_cli
node_cli -.->|"dispatches"| node_llb_runner
node_agent -->|"uses"| node_agent_history
node_agent -->|"generates with"| node_llm
node_memory_service -->|"builds memories"| node_memory_build
node_memory_service -->|"retrieves via"| node_memory_retrieval
node_memory_service -->|"updates via"| node_memory_update
node_memory_service -->|"selects strategies"| node_memory_strategies
node_memory_service -->|"selects values"| node_value_learning
node_memory_retrieval -->|"embeds queries"| node_embeddings
node_memory_build -.->|"builds content"| node_llm
node_hle_runner -->|"uses memory"| node_memory_service
node_hle_runner -->|"uses provider"| node_llm
node_alfworld_runner -->|"evaluates"| node_benchmark_tasks
node_alfworld_runner -->|"runs environment"| node_alfworld_env
node_alfworld_runner -.->|"uses memory"| node_memory_service
node_llb_runner -->|"uses memory"| node_memory_service
node_llb_runner -->|"uses provider"| node_llm
node_llb_runner -->|"uses provider"| node_embeddings
node_llb_runner -.->|"adapts tasks"| node_llb_adapter
node_llb_runner -->|"evaluates"| node_benchmark_tasks
node_llb_runner -->|"wraps provider"| node_trace_wrapper
node_trace_wrapper -->|"records calls"| node_llb_trace
node_bcb_runner -.->|"adapts evaluation"| node_bcb_adapter
node_bcb_runner -->|"evaluates"| node_benchmark_tasks
node_bcb_runner -.->|"uses memory"| node_memory_service

click node_cli "https://github.com/memtensor/memrl/blob/main/memrl/cli/main.py"
click node_agent "https://github.com/memtensor/memrl/blob/main/memrl/agent/memp_agent.py"
click node_agent_history "https://github.com/memtensor/memrl/blob/main/memrl/agent/history.py"
click node_memory_service "https://github.com/memtensor/memrl/blob/main/memrl/service/memory_service.py"
click node_memory_build "https://github.com/memtensor/memrl/blob/main/memrl/service/builders.py"
click node_memory_retrieval "https://github.com/memtensor/memrl/blob/main/memrl/service/retrievers.py"
click node_memory_update "https://github.com/memtensor/memrl/blob/main/memrl/service/updater.py"
click node_memory_strategies "https://github.com/memtensor/memrl/blob/main/memrl/service/strategies.py"
click node_value_learning "https://github.com/memtensor/memrl/blob/main/memrl/service/value_driven.py"
click node_llm "https://github.com/memtensor/memrl/blob/main/memrl/providers/llm.py"
click node_embeddings "https://github.com/memtensor/memrl/blob/main/memrl/providers/embedding.py"
click node_hle_runner "https://github.com/memtensor/memrl/blob/main/memrl/run/hle_runner.py"
click node_alfworld_runner "https://github.com/memtensor/memrl/blob/main/memrl/run/alfworld_rl_runner.py"
click node_alfworld_env "https://github.com/memtensor/memrl/blob/main/memrl/envs/alfworld_env.py"
click node_llb_runner "https://github.com/memtensor/memrl/blob/main/memrl/run/llb_rl_runner.py"
click node_llb_adapter "https://github.com/memtensor/memrl/blob/main/memrl/lifelongbench_eval/task_wrappers.py"
click node_bcb_runner "https://github.com/memtensor/memrl/blob/main/memrl/run/bcb_runner.py"
click node_bcb_adapter "https://github.com/memtensor/memrl/blob/main/memrl/bigcodebench_eval/bcb_adapter.py"
click node_trace_wrapper "https://github.com/memtensor/memrl/blob/main/memrl/trace/tracing_llm.py"
click node_llb_trace "https://github.com/memtensor/memrl/blob/main/memrl/trace/llb_jsonl.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_cli,node_agent,node_agent_history toneBlue
class node_memory_service,node_memory_build,node_memory_retrieval,node_memory_update,node_memory_strategies,node_value_learning toneAmber
class node_llm,node_embeddings toneMint
class node_hle_runner,node_alfworld_runner,node_alfworld_env,node_llb_runner,node_llb_adapter,node_bcb_runner,node_bcb_adapter,node_benchmark_tasks toneRose
class node_trace_wrapper,node_llb_trace,node_user toneIndigo
```

## Components

### Agent execution

- [CLI](https://github.com/memtensor/memrl/blob/main/memrl/cli/main.py): `memrl/cli/main.py`
- [Memory agent](https://github.com/memtensor/memrl/blob/main/memrl/agent/memp_agent.py): `memrl/agent/memp_agent.py`
- [Agent history](https://github.com/memtensor/memrl/blob/main/memrl/agent/history.py): `memrl/agent/history.py`

### Episodic memory

- [Memory service](https://github.com/memtensor/memrl/blob/main/memrl/service/memory_service.py): `memrl/service/memory_service.py`
- [Memory building](https://github.com/memtensor/memrl/blob/main/memrl/service/builders.py): `memrl/service/builders.py`
- [Memory retrieval](https://github.com/memtensor/memrl/blob/main/memrl/service/retrievers.py): `memrl/service/retrievers.py`
- [Memory update](https://github.com/memtensor/memrl/blob/main/memrl/service/updater.py): `memrl/service/updater.py`
- [Strategy config](https://github.com/memtensor/memrl/blob/main/memrl/service/strategies.py): `memrl/service/strategies.py`
- [Value learning](https://github.com/memtensor/memrl/blob/main/memrl/service/value_driven.py): `memrl/service/value_driven.py`

### Model providers

- [LLM provider](https://github.com/memtensor/memrl/blob/main/memrl/providers/llm.py): `memrl/providers/llm.py`
- [Embedding provider](https://github.com/memtensor/memrl/blob/main/memrl/providers/embedding.py): `memrl/providers/embedding.py`

### Benchmark integrations

- [HLE runner](https://github.com/memtensor/memrl/blob/main/memrl/run/hle_runner.py): `memrl/run/hle_runner.py`
- [ALFWorld runner](https://github.com/memtensor/memrl/blob/main/memrl/run/alfworld_rl_runner.py): `memrl/run/alfworld_rl_runner.py`
- [ALFWorld environment](https://github.com/memtensor/memrl/blob/main/memrl/envs/alfworld_env.py): `memrl/envs/alfworld_env.py`
- [LLB runner](https://github.com/memtensor/memrl/blob/main/memrl/run/llb_rl_runner.py): `memrl/run/llb_rl_runner.py`
- [LLB task adapter](https://github.com/memtensor/memrl/blob/main/memrl/lifelongbench_eval/task_wrappers.py): `memrl/lifelongbench_eval/task_wrappers.py`
- [BCB runner](https://github.com/memtensor/memrl/blob/main/memrl/run/bcb_runner.py): `memrl/run/bcb_runner.py`
- [BCB adapter](https://github.com/memtensor/memrl/blob/main/memrl/bigcodebench_eval/bcb_adapter.py): `memrl/bigcodebench_eval/bcb_adapter.py`

### Tracing

- [Tracing LLM](https://github.com/memtensor/memrl/blob/main/memrl/trace/tracing_llm.py): `memrl/trace/tracing_llm.py`
- [LLB JSONL trace](https://github.com/memtensor/memrl/blob/main/memrl/trace/llb_jsonl.py): `memrl/trace/llb_jsonl.py`

### Other components

- **Experiment operator**
- **Benchmark tasks**

## Connections

- Experiment operator → CLI: starts runs
- CLI → LLB runner: dispatches
- Memory agent → Agent history: uses (evidence: `memrl/agent/memp_agent.py`)
- Memory agent → LLM provider: generates with (evidence: `memrl/agent/memp_agent.py`)
- Memory service → Memory building: builds memories (evidence: `memrl/service/memory_service.py`)
- Memory service → Memory retrieval: retrieves via (evidence: `memrl/service/memory_service.py`)
- Memory service → Memory update: updates via (evidence: `memrl/service/memory_service.py`)
- Memory service → Strategy config: selects strategies (evidence: `memrl/service/memory_service.py`)
- Memory service → Value learning: selects values (evidence: `memrl/service/memory_service.py`)
- Memory retrieval → Embedding provider: embeds queries (evidence: `memrl/service/retrievers.py`)
- Memory building → LLM provider: builds content
- HLE runner → Memory service: uses memory (evidence: `memrl/run/hle_runner.py`)
- HLE runner → LLM provider: uses provider (evidence: `memrl/run/hle_runner.py`)
- ALFWorld runner → Benchmark tasks: evaluates
- ALFWorld runner → ALFWorld environment: runs environment (evidence: `memrl/envs/alfworld_env.py`)
- ALFWorld runner → Memory service: uses memory
- LLB runner → Memory service: uses memory (evidence: `memrl/run/llb_rl_runner.py`)
- LLB runner → LLM provider: uses provider (evidence: `memrl/run/llb_rl_runner.py`)
- LLB runner → Embedding provider: uses provider (evidence: `memrl/run/llb_rl_runner.py`)
- LLB runner → LLB task adapter: adapts tasks (evidence: `memrl/run/llb_rl_runner.py`)
- LLB runner → Benchmark tasks: evaluates
- LLB runner → Tracing LLM: wraps provider (evidence: `memrl/run/llb_rl_runner.py`)
- Tracing LLM → LLB JSONL trace: records calls (evidence: `memrl/trace/tracing_llm.py`)
- BCB runner → BCB adapter: adapts evaluation
- BCB runner → Benchmark tasks: evaluates
- BCB runner → Memory service: uses memory
