This document maps the C3 paper to the implementation in this repository and records the main execution contracts that should remain stable across releases.
- paper target: contextual counterfactual credit assignment for two-agent
Reasoner -> Actorcollaboration, - repository target: public release of the reference implementation,
- audit goal: make the paper-facing path, compatibility path, and reproducibility path explicit.
flowchart TD
PaperSpec["PaperSpec"] --> TaskConfigs["configs/tasks/*.yaml"]
TaskConfigs --> RoleConfigs["configs/roles/**/*.json"]
TaskConfigs --> TaskLoader["c3/integration/marl_specs.py"]
TaskLoader --> DatasetLoader["c3/integration/task_datasets.py"]
RoleConfigs --> RoleGraph["c3/mas/role_graph.py"]
RoleGraph --> PromptRender["c3/mas/prompt_render.py"]
DatasetLoader --> RolloutGen["c3/mas/rollout_generator.py"]
PromptRender --> RolloutGen
RolloutGen --> ExperienceMaker["openrlhf/trainer/ppo_utils/experience_maker.py"]
ExperienceMaker --> CreditProvider["c3/credit/c3/*"]
ExperienceMaker --> EnvReward["c3/envs/math/* + c3/envs/code/*"]
CreditProvider --> Trainer["openrlhf/trainer/ppo_trainer.py"]
EnvReward --> Trainer
Trainer --> MainResults["c3/tools/main_results.py"]
Trainer --> Analysis["c3/analysis/* + c3/tools/analysis_results.py"]
| Paper area | Primary implementation | Role in repo | Key contract |
|---|---|---|---|
| Protocol and roles | configs/tasks/math.yaml, configs/tasks/code.yaml, configs/roles/math/roles_duo.json, configs/roles/code/roles_duo.json |
Declares the paper-facing tasks and Reasoner -> Actor protocol |
Task files are the paper defaults; role files define prompt text, dependencies, and with_answer |
| Task loading | c3/integration/marl_specs.py |
Canonical loader for task and role configs | TaskSpec must expose environment, role graph, and dataset specs in a stable shape |
| Dataset loading | c3/integration/task_datasets.py |
Converts task configs into HF datasets | Local dataset paths must resolve independent of cwd; eval suite names must remain stable |
| Multi-agent execution | c3/mas/role_graph.py, c3/mas/prompt_render.py, c3/mas/rollout_generator.py |
Builds topo order, renders prompts, materializes MAS rollouts | Topology must remain acyclic; prompt rendering must be deterministic; rollout metadata feeds downstream credit/reward |
| C3 credit path | openrlhf/trainer/ppo_utils/experience_maker.py, c3/credit/c3/provider.py, c3/credit/c3/materialize.py, c3/credit/c3/baselines.py |
Computes per-node credit and broadcasts token-level advantages | This is the real C3 path used by training |
| MAPPO baseline | c3/algorithms/mappo.py |
Step-level GAE baseline | Consumes step-ordered episode tensors and returns scalar advantages/returns |
| MAGRPO baseline | c3/algorithms/magrpo.py |
Group-based baseline | Computes group-centered advantages, then broadcasts them over action tokens |
| C3 fallback | c3/algorithms/c3.py |
Compatibility and fallback path only | Not the paper’s primary C3 implementation |
| Training entry | openrlhf/cli/train_ppo_ray_tooling.py, openrlhf/cli/train_ppo_ray.py, openrlhf/trainer/ppo_trainer.py |
Normalizes args, creates critics, drives PPO/Q-critic training | marl_algorithm=auto does not imply c3; Q-critic is enabled only for specific C3 variants |
| Math evaluation | c3/envs/math/reward.py, c3/envs/math/backends/marft/* |
Math reward and answer checking | Current paper path scores only the final actor output |
| Code evaluation | c3/envs/code/reward.py, c3/envs/code/executor.py |
Code reward and sandboxed execution | Reward is a pass-rate style score based on hidden tests in metadata |
| Paper main results | scripts/reproduce/paper_main_results.sh, c3/tools/main_results.py, configs/main_results_registry.yaml |
Eval-only sweep and table aggregation | Datasource names must match task-suite names and registry expectations |
| Paper analyses | scripts/reproduce/paper_analysis_figs.sh, c3/analysis/*, c3/tools/analysis_results.py, c3/tools/plot_paper_figures.py |
Credit, influence, variance, and plotting pipeline | Bucket metadata is the contract for downstream metrics |
math:configs/tasks/math.yamlcode:configs/tasks/code.yaml
- math duo:
configs/roles/math/roles_duo.json - code duo:
configs/roles/code/roles_duo.json
- training:
scripts/reproduce/paper_train.sh - eval-only sweep:
scripts/reproduce/paper_main_results.sh - analyses:
scripts/reproduce/paper_analysis_figs.sh - fast wiring check:
scripts/reproduce/smoke.sh
The paper’s C3 path is:
train_ppo_ray_tooling.pynormalizes the run configuration,train_ppo_ray.pydecides whether a Q-critic is needed,ppo_trainer.pyprepares Q-critic batches,experience_maker.pymaterializes tree groups and requests node-level C3 credit,c3/credit/c3/provider.pycomputes scalar credit values,- the scalar credit is broadcast back to token-level PPO advantages.
c3/algorithms/c3.pyis a fallback and compatibility calculator, not the main C3 algorithm.c3_env_smoke.pycontains compatibility bridging for task loading and should not be used as proof that the training path is correct.configs/roles/critic_preamble.jsonis not part of the default paper path and should be treated as optional or experimental until its consumer contract is documented more clearly.
TaskSpecmust exposetrain_datasetsandeval_suitesin a shape directly consumable byload_task_datasets().- Eval suite names in task YAML must propagate into dataset
datasourcenames unchanged, becausemain_results.pyaggregates by benchmark name. - Local dataset paths such as
data/MATH/train.jsonlmust resolve from any working directory, not only when the process runs from repo root. - The public release must document that the actual C3 credit path lives in
experience_maker.pyplusc3/credit/c3/*, not inc3/algorithms/c3.py. - The public release must keep generated directories (
data/,artifacts/,ckpt/,runs/,wandb/,models/) out of the shipped repository surface.
marl_algorithm=autofor MAS tasks resolves tomagrpowhenK > 1; users must explicitly requestc3for the paper method.- The math paper path scores the final actor output. Multi-answer aggregation settings in
MathEnvshould be interpreted with that default in mind. - The code path relies on tests embedded in dataset metadata; it is not symmetric with the math path’s
answerfield. smoke.shis a wiring smoke test, not a performance regression test.
- task and role loading,
- dataset loading and benchmark naming,
- cwd-independent local path resolution,
RoleGraphvalidity checks,- prompt rendering contract,
- smoke-level math/code evaluator wiring,
- main-results aggregation on synthetic artifacts,
- analysis bucket parsing and metric aggregation.