MCPcopy Create free account
hub / github.com/OpenRaiser/NanoResearch / CodingAgent

Class CodingAgent

nanoresearch/agents/coding.py:26–549  ·  view source on GitHub ↗

Generates runnable training code + SLURM scripts based on cloned repos and experiment plan.

Source from the content-addressed store, hash-verified

24
25
26class CodingAgent(_CodingHelpersMixin, BaseResearchAgent):
27 """Generates runnable training code + SLURM scripts based on cloned repos and experiment plan."""
28
29 stage = PipelineStage.CODING
30
31 @property
32 def stage_config(self):
33 """Use code_gen model config for writing code."""
34 return self.config.for_stage("code_gen")
35
36 @staticmethod
37 def _default_code_plan_files() -> list[dict[str, Any]]:
38 return [
39 {
40 "path": "run_experiments.py",
41 "description": "Unified entrypoint that loads configs/experiment_matrix.json, executes proposed/baseline/ablation/optimization/complexity runs, and writes all required result artifacts",
42 "is_entrypoint": True,
43 },
44 {
45 "path": "train.py",
46 "description": "Single-run training/evaluation implementation used by run_experiments.py; supports --dry-run / --quick-eval",
47 "is_entrypoint": False,
48 },
49 {"path": "model.py", "description": "Model and measured baseline definitions"},
50 {"path": "dataset.py", "description": "Dataset loading and preprocessing"},
51 {"path": "evaluate.py", "description": "Evaluation metrics and testing"},
52 {"path": "config.py", "description": "Default hyperparameters and configuration"},
53 ]
54
55 def _normalize_code_plan(self, code_plan: dict[str, Any] | None) -> dict[str, Any]:
56 plan = dict(code_plan) if isinstance(code_plan, dict) else {}
57
58 normalized_files: list[dict[str, Any]] = []
59 seen_paths: set[str] = set()
60 for raw_spec in plan.get("files", []):
61 if not isinstance(raw_spec, dict):
62 continue
63 path = str(raw_spec.get("path") or "").strip().replace("\\", "/")
64 if not path or path in seen_paths:
65 continue
66 seen_paths.add(path)
67 normalized_files.append(
68 {
69 "path": path,
70 "description": str(raw_spec.get("description") or "").strip(),
71 "is_entrypoint": bool(raw_spec.get("is_entrypoint", False)),
72 }
73 )
74
75 for default_spec in self._default_code_plan_files():
76 if default_spec["path"] in seen_paths:
77 continue
78 normalized_files.append(dict(default_spec))
79 seen_paths.add(default_spec["path"])
80
81 dependencies: list[str] = []
82 seen_dependencies: set[str] = set()
83 for raw_dependency in plan.get("dependencies", []):

Callers 2

run_execution_smokeFunction · 0.90
_build_agentsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected