How facebookresearch/context-language-models works
The repository implements CLM agents whose main workflow lets a model edit its conversation context through a sandbox, then records the run as a context-aware trajectory. Separate branches evolve context-management skills in-context and provide suffix-cache reuse for serving. The README also describes reinforcement learning, but no RL source appears in the supplied tree. Relationships below are limited to README statements and SOURCE INDEX references; unsampled implementation details are not inferred.
Main entry points: harness.py CLM agent · env.py Context environment · models.py ATIF-CTX models · evolve.py Skill evolution
Components 24
CLM agent runtime
- CLM agent
clm/clm_harness/clm_agent/harness.py - Context environment
clm/clm_harness/context_env/env.py - Context text codec
clm/clm_harness/context_utils/context_string.py - Edit gate
clm/clm_harness/context_env/edit_gate.py - Context budgeting
clm/clm_harness/utils/budget.py - Token counting
clm/clm_harness/utils/tokens.py - Trial resume
clm/clm_harness/utils/resume.py - Skill support
clm/clm_harness/utils/skills.py
Trajectory and metrics
- Trajectory export
clm/clm_harness/agent_trajectory_format/harness_export.py - Trajectory builder
clm/clm_harness/agent_trajectory_format/builder.py - ATIF-CTX models
clm/clm_harness/agent_trajectory_format/models.py - Trajectory validator
clm/clm_harness/agent_trajectory_format/validator.py - KV-cache FLOPs
clm/clm_harness/flops_metrics/kv_cache_flops.py
In-context learning
- Skill evolution
clm/clm_icl/evolve.py - Task sources
clm/clm_icl/tasks.py - Skill proposer
clm/clm_icl/propose.py - Evolution notes
clm/clm_icl/note.py
Efficient serving
- Reuse configuration
suffix_cache_reuse/suffix_cache_reuse/config.py - KV reuse overlay
suffix_cache_reuse/suffix_cache_reuse/overlay.py - Server site hook
suffix_cache_reuse/suffix_cache_reuse/_site/sitecustomize.py - Serving entry
suffix_cache_reuse/suffix_cache_reuse/serve.py
Other components
- Task user
- Harbor task runner
- Language model
Connections 25
- Task user → Harbor task runner: starts task
- Harbor task runner → CLM agent: runs agent
- CLM agent → Language model: requests completions
- CLM agent → Context environment: uses sandbox
clm/clm_harness/clm_agent/harness.py - CLM agent → Trial resume: restores state
clm/clm_harness/clm_agent/harness.py - CLM agent → Skill support: installs skills
clm/clm_harness/clm_agent/harness.py - CLM agent → Trajectory export: exports rollout
clm/clm_harness/clm_agent/harness.py - CLM agent → KV-cache FLOPs: records metrics
clm/clm_harness/clm_agent/harness.py - Context environment → Context text codec: renders edits
clm/clm_harness/context_env/env.py - Context environment → Edit gate: checks edits
clm/clm_harness/context_env/env.py - Context environment → Context budgeting: checks budget
clm/clm_harness/context_env/env.py - Context environment → Token counting: counts context
clm/clm_harness/context_env/env.py - Context budgeting → Token counting: counts tokens
clm/clm_harness/utils/budget.py - Trajectory export → Trajectory builder: builds segments
clm/clm_harness/agent_trajectory_format/harness_export.py - Trajectory export → ATIF-CTX models: creates records
clm/clm_harness/agent_trajectory_format/harness_export.py - Trajectory builder → ATIF-CTX models: constructs models
clm/clm_harness/agent_trajectory_format/builder.py - KV-cache FLOPs → ATIF-CTX models: reads trajectories
clm/clm_harness/flops_metrics/kv_cache_flops.py - Trajectory validator → ATIF-CTX models: validates schema
clm/clm_harness/agent_trajectory_format/validator.py - Skill evolution → Task sources: runs tasks
clm/clm_icl/evolve.py - Skill evolution → Skill proposer: requests candidates
clm/clm_icl/evolve.py - Skill evolution → Evolution notes: uses notes
clm/clm_icl/evolve.py - Server site hook → Reuse configuration: loads config
suffix_cache_reuse/suffix_cache_reuse/_site/sitecustomize.py - Server site hook → KV reuse overlay: loads overlay
suffix_cache_reuse/suffix_cache_reuse/_site/sitecustomize.py - Serving entry → Reuse configuration: uses config
suffix_cache_reuse/suffix_cache_reuse/serve.py - KV reuse overlay → Language model: reuses KV cache