Skip to content

Commit e020eb0

Browse files
tell agent can edit other files in workspace while handling image_kernel/repo_kernel
1 parent 0dc4726 commit e020eb0

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

‎agents/forge/launch_agent.py‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,32 @@ def _write_program_md(task_config: dict[str, Any], target_funcs, gpu_arch: str,
233233
prompt_cfg = task_config.get("prompt") or {}
234234
instructions = prompt_cfg.get("instructions") or ""
235235
funcs = ", ".join(target_funcs) if target_funcs else "the target kernel"
236+
237+
# Level-3 tasks (repository / image_kernel) give the agent a full source tree,
238+
# so the target kernel file is often only an ENTRY POINT: the code that governs
239+
# its performance may live in other files it includes/imports. Tell the agent
240+
# it may follow the implementation across the workspace and edit those files
241+
# too. Snippet tasks copy a single self-contained file, so the note is omitted
242+
# there to avoid pointing the agent at unrelated files.
243+
task_type = str(task_config.get("task_type") or "").strip().lower()
244+
scope_section = ""
245+
if task_type in ("repository", "image_kernel"):
246+
scope_section = f"""
247+
## Kernel Scope (the target file may not be self-contained)
248+
`{funcs}` lives in the target kernel file, but the code that governs its
249+
performance may span OTHER files in this workspace (headers it includes, modules
250+
it imports, dispatch/config layers, or JIT template sources). You are NOT limited
251+
to the single target file:
252+
1. Before editing, use Grep/Glob/Read to trace the real implementation across the
253+
repository (includes, imports, call sites, templates) so you edit where the
254+
performance-relevant code actually is.
255+
2. You MAY edit any source file the kernel depends on when that is where the
256+
change belongs. The loop stages every tracked source edit, so a cross-file
257+
change is validated, benchmarked, and kept/reverted as one unit.
258+
3. Do NOT edit the measurement files (the test driver / harness / perf helpers);
259+
the loop rejects edits to those.
260+
"""
261+
236262
dest.write_text(
237263
f"""# Program: optimize {funcs}
238264
@@ -242,9 +268,11 @@ def _write_program_md(task_config: dict[str, Any], target_funcs, gpu_arch: str,
242268
## Objective
243269
Optimize the body of `{funcs}` for maximum performance on {gpu_arch} while
244270
keeping numerical results correct (the loop gates on an SNR threshold).
245-
271+
{scope_section}
246272
## Modification Rules
247-
1. Make ONE logical change per iteration with a clear hypothesis.
273+
1. You MAY make multiple changes across several places in the kernel this
274+
iteration (not just one); group them under a clear hypothesis so the
275+
iteration's effect stays attributable.
248276
2. Do NOT change the kernel's function signature or parameter list.
249277
3. Do NOT remove imports or helper utilities in the file.
250278
4. Correctness, validation, and benchmarking are run automatically by the loop

0 commit comments

Comments
 (0)