"""Canonical coding-agent prompts used by both rubric families.""" from __future__ import annotations INITIAL_USER_TEMPLATE = r"""You are solving the Kaggle competition `{competition_id}`. {description} The prepared data is at: {data_dir} containing: {files} Your submission must match the format of {sample_submission_name}, which starts: {sample_submission_head} Write a complete Python script that trains on the training data and writes its predictions to exactly this path: {submission_path} It will run in this environment — write code valid for exactly these versions, and do not use anything not listed: {environment} Respond with a single ```python code block and nothing else. The script must run start to finish on its own. Prefer a simple approach that definitely runs over an elaborate one that might not.""" REPAIR_USER_TEMPLATE = r"""{task_prompt} Your previous script failed. ```python {code} ``` Output: {output_tail} Return the full corrected script in a single ```python block.""" def build_initial(task: object) -> str: files = "\n".join( f" {path.name}" for path in sorted(task.data_dir.iterdir())[:40] ) head = "" if task.sample_submission.is_file(): with task.sample_submission.open(errors="replace") as handle: head = "".join(next(handle, "") for _ in range(3)) prompt = INITIAL_USER_TEMPLATE.format( competition_id=task.competition_id, description=task.description, data_dir=task.data_dir, files=files, sample_submission_name=task.sample_submission.name, sample_submission_head=head, submission_path=task.submission_path, environment=task.env_note, ) manifest = getattr(task, "static_task_manifest", "").strip() if manifest: block = f"\n\n{manifest}\n\n" prompt = prompt.replace( "\nYour submission must match", block + "\nYour submission must match" ) return prompt def build_repair(initial: dict) -> str: execution = initial["execution"] output = execution.get("stdout", "") + "\n--- stderr ---\n" + execution.get("stderr", "") return REPAIR_USER_TEMPLATE.format( task_prompt=initial["task_prompt"], code=initial["code"], output_tail=output[-4000:], ) # ---------------------------------------------------------------- hill-climb # (performance family). Restored after the prompts unification: collect.py's # climb turns import THIS module, and the function existed only in the older # prompts/coder_prompts.py -- every climb turn since the merge died with # AttributeError before reaching the model. PERF_FEEDBACK_TEMPLATE = r"""{task_prompt} Your previous program ran successfully and scored {score} on the competition metric ({direction} is better). ```python {code} ``` Revise the program to achieve a better score. You may change the approach, features, model, or hyperparameters. Keep the same submission path and format, and stay within the runtime budget -- a program that does not finish scores nothing. Return the full revised program in a single ```python block.""" def build_perf_feedback(task_prompt: str, code: str, score: float, lower_better: bool) -> str: """The hill-climb turn: the agent sees its own measured score and revises. This is the performance analog of the repair loop. A repair turn shows the traceback and asks for a fix; this shows the score and asks for a better one. Each accepted turn yields a (weaker, stronger) pair from the SAME lineage -- one deliberate change, one measured delta -- which is exactly the evidence cross-program pairs cannot give: nothing else varies. TRAIN ONLY. Feeding a program its held-out score would optimize eval programs against the private answers; collect.py refuses the combination. """ return PERF_FEEDBACK_TEMPLATE.format( task_prompt=task_prompt, code=code, score=score, direction="lower" if lower_better else "higher")