vanishingradient commited on
Commit
2c121ec
·
verified ·
1 Parent(s): 147b723

Add deepagents_rl package sources

Browse files
src/deepagents_rl/data/__pycache__/swe_bench_lite.cpython-312.pyc CHANGED
Binary files a/src/deepagents_rl/data/__pycache__/swe_bench_lite.cpython-312.pyc and b/src/deepagents_rl/data/__pycache__/swe_bench_lite.cpython-312.pyc differ
 
src/deepagents_rl/data/swe_bench_lite.py CHANGED
@@ -46,10 +46,16 @@ def _as_str_list(val: Any) -> list[str]:
46
  def build_agent_prompt(problem_statement: str, *, instance_id: str) -> str:
47
  return (
48
  "You are a software engineering agent inside a full git checkout of the repo.\n"
49
- "Resolve the GitHub issue by exploring and editing files with your tools "
50
- "(ls, glob, grep, read_file, write_file, edit_file, execute).\n"
51
- "Prefer minimal correct edits. Do not modify tests unless necessary.\n"
52
- "When finished, stop calling tools and reply with DONE plus a short summary.\n\n"
 
 
 
 
 
 
53
  f"Instance: {instance_id}\n\n"
54
  f"Issue:\n{problem_statement.strip()}\n"
55
  )
 
46
  def build_agent_prompt(problem_statement: str, *, instance_id: str) -> str:
47
  return (
48
  "You are a software engineering agent inside a full git checkout of the repo.\n"
49
+ "You MUST resolve the GitHub issue by calling tools via the function-calling "
50
+ "interface (not by writing a plan or code only in plain text).\n"
51
+ "Available tools: ls, glob, grep, read_file, write_file, edit_file, execute.\n"
52
+ "Required workflow:\n"
53
+ "1) Call ls or glob to inspect the repo.\n"
54
+ "2) Call read_file / grep to find the bug.\n"
55
+ "3) Call edit_file or write_file to apply a minimal fix.\n"
56
+ "4) Optionally execute a quick check command.\n"
57
+ "5) Stop calling tools and reply DONE with a short summary.\n"
58
+ "Prefer minimal correct edits. Do not modify tests unless necessary.\n\n"
59
  f"Instance: {instance_id}\n\n"
60
  f"Issue:\n{problem_statement.strip()}\n"
61
  )
src/deepagents_rl/train/__pycache__/swe_env.cpython-312.pyc CHANGED
Binary files a/src/deepagents_rl/train/__pycache__/swe_env.cpython-312.pyc and b/src/deepagents_rl/train/__pycache__/swe_env.cpython-312.pyc differ
 
src/deepagents_rl/train/swe_env.py CHANGED
@@ -256,8 +256,8 @@ class DeepAgentSWEEnv:
256
  )
257
  return out
258
 
259
- def reset(self, **kwargs: Any) -> None:
260
- """Materialize repo sandbox from a SWE Lite row. Prompt stays on the dataset."""
261
  self._cleanup()
262
  self._end_trace()
263
 
@@ -317,13 +317,17 @@ class DeepAgentSWEEnv:
317
  _vlog("env.reset.langfuse", enabled=lf is not None)
318
  if lf is not None:
319
  try:
 
 
320
  self._root_cm = lf.start_as_current_observation(
321
- name="grpo-swe-rollout",
322
  as_type="agent",
 
323
  input={
324
  "instance_id": instance_id,
325
  "repo": repo,
326
  "base_commit": base_commit,
 
327
  "prompt_preview": _truncate(
328
  kwargs.get("prompt")
329
  if isinstance(kwargs.get("prompt"), str)
@@ -340,16 +344,18 @@ class DeepAgentSWEEnv:
340
  "docker_image": docker_image,
341
  "phase": "grpo_train_or_eval",
342
  "harness": "deepagents-swe-grpo",
 
343
  "tags": ["deepagents-rl", "swe-bench", "grpo", "tools"],
344
  },
 
345
  )
346
  self._root = self._root_cm.__enter__()
347
- self._trace_id = lf.get_current_trace_id() or ""
348
  _vlog("env.reset.langfuse_trace", trace_id=self._trace_id)
349
  except Exception as e: # noqa: BLE001
350
  _vlog("env.reset.langfuse_failed", error=str(e))
351
  self._root_cm = None
352
  self._root = None
 
353
 
354
  def _materialize() -> None:
355
  _vlog("env.reset.materialize", repo=repo, base_commit=base_commit[:12])
@@ -381,8 +387,15 @@ class DeepAgentSWEEnv:
381
  rollout_id=self._rollout_id,
382
  n_f2p=len(fail_to_pass),
383
  n_p2p=len(pass_to_pass),
 
 
 
 
 
 
 
 
384
  )
385
- return None
386
 
387
  def _cleanup(self) -> None:
388
  self._backend = None
@@ -647,7 +660,7 @@ def prepare_swe_grpo_rows(records: list[dict[str, Any]]) -> list[dict[str, Any]]
647
  Renames `image` -> `docker_image` so TRL does not treat it as multimodal.
648
  Converts `prompt` to conversational chat messages (required for tool calling).
649
  """
650
- from deepagents_rl.data.swe_bench_lite import from_hf_record
651
 
652
  rows: list[dict[str, Any]] = []
653
  for rec in records:
@@ -658,11 +671,16 @@ def prepare_swe_grpo_rows(records: list[dict[str, Any]]) -> list[dict[str, Any]]
658
  else:
659
  task = dict(rec)
660
 
661
- prompt = task.get("prompt") or ""
662
- if isinstance(prompt, list):
663
- messages = prompt
664
- else:
665
- messages = [{"role": "user", "content": str(prompt)}]
 
 
 
 
 
666
 
667
  docker_image = str(task.get("docker_image") or task.get("image") or "")
668
  rows.append(
 
256
  )
257
  return out
258
 
259
+ def reset(self, **kwargs: Any) -> str:
260
+ """Materialize repo sandbox; return tool-forcing text TRL appends to the user message."""
261
  self._cleanup()
262
  self._end_trace()
263
 
 
317
  _vlog("env.reset.langfuse", enabled=lf is not None)
318
  if lf is not None:
319
  try:
320
+ # Fresh root trace per rollout (avoid nesting everything under one parent).
321
+ self._trace_id = lf.create_trace_id()
322
  self._root_cm = lf.start_as_current_observation(
323
+ name=f"grpo-swe-rollout:{instance_id}",
324
  as_type="agent",
325
+ trace_context={"trace_id": self._trace_id},
326
  input={
327
  "instance_id": instance_id,
328
  "repo": repo,
329
  "base_commit": base_commit,
330
+ "rollout_id": self._rollout_id,
331
  "prompt_preview": _truncate(
332
  kwargs.get("prompt")
333
  if isinstance(kwargs.get("prompt"), str)
 
344
  "docker_image": docker_image,
345
  "phase": "grpo_train_or_eval",
346
  "harness": "deepagents-swe-grpo",
347
+ "session_id": self._rollout_id,
348
  "tags": ["deepagents-rl", "swe-bench", "grpo", "tools"],
349
  },
350
+ end_on_exit=True,
351
  )
352
  self._root = self._root_cm.__enter__()
 
353
  _vlog("env.reset.langfuse_trace", trace_id=self._trace_id)
354
  except Exception as e: # noqa: BLE001
355
  _vlog("env.reset.langfuse_failed", error=str(e))
356
  self._root_cm = None
357
  self._root = None
358
+ self._trace_id = ""
359
 
360
  def _materialize() -> None:
361
  _vlog("env.reset.materialize", repo=repo, base_commit=base_commit[:12])
 
387
  rollout_id=self._rollout_id,
388
  n_f2p=len(fail_to_pass),
389
  n_p2p=len(pass_to_pass),
390
+ langfuse_trace_id=self._trace_id,
391
+ )
392
+ # TRL appends this string to the last user message — force tool use.
393
+ return (
394
+ "\n\nCRITICAL: Use structured tool/function calls only. "
395
+ "Your first action MUST be a tool call to `ls` or `glob` on the repo. "
396
+ "Then `read_file`/`grep`, then `edit_file`/`write_file` to fix the issue. "
397
+ "Do not answer with a text-only plan. When the fix is applied, stop tools and say DONE."
398
  )
 
399
 
400
  def _cleanup(self) -> None:
401
  self._backend = None
 
660
  Renames `image` -> `docker_image` so TRL does not treat it as multimodal.
661
  Converts `prompt` to conversational chat messages (required for tool calling).
662
  """
663
+ from deepagents_rl.data.swe_bench_lite import build_agent_prompt, from_hf_record
664
 
665
  rows: list[dict[str, Any]] = []
666
  for rec in records:
 
671
  else:
672
  task = dict(rec)
673
 
674
+ # Rebuild prompt locally so tool-forcing text stays current (HF rows may be stale).
675
+ messages = [
676
+ {
677
+ "role": "user",
678
+ "content": build_agent_prompt(
679
+ str(task.get("problem_statement") or ""),
680
+ instance_id=str(task.get("instance_id") or task.get("task_id") or ""),
681
+ ),
682
+ }
683
+ ]
684
 
685
  docker_image = str(task.get("docker_image") or task.get("image") or "")
686
  rows.append(