Skip to content

Commit 445ce45

Browse files
committed
upd: enhance subtask constraint assign module prompt
1 parent c281891 commit 445ce45

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

cli/decompose/prompt_modules/subtask_constraint_assign/_subtask_constraint_assign.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020

2121
RE_ASSIGNED_CONS = re.compile(
22-
r"<assigned_constraints>(.+?)</assigned_constraints>",
22+
r"<assigned_constraints>(.*?)</assigned_constraints>",
2323
flags=re.IGNORECASE | re.DOTALL,
2424
)
2525

@@ -92,18 +92,22 @@ def _default_parser(generated_str: str) -> list[SubtaskPromptConstraintsItem]:
9292

9393
subtask_constraint_assign_match = re.search(RE_ASSIGNED_CONS, data[3])
9494

95-
subtask_constraint_assign_str: str | None = (
95+
# ===== fallback: use raw text when there is no tag =====
96+
subtask_constraint_assign_str: str = (
9697
subtask_constraint_assign_match.group(1).strip()
9798
if subtask_constraint_assign_match
98-
else None
99+
else data[3].strip()
99100
)
100101

101-
if subtask_constraint_assign_str is None:
102-
raise TagExtractionError(
103-
'LLM failed to generate correct tags for extraction: "<assigned_constraints>"'
104-
)
102+
subtask_constraint_assign_str = re.sub(
103+
r"\n*All tags are closed and my assignment is finished\.\s*$",
104+
"",
105+
subtask_constraint_assign_str,
106+
flags=re.IGNORECASE,
107+
).strip()
105108

106109
subtask_constraint_assign_str_upper = subtask_constraint_assign_str.upper()
110+
107111
if (
108112
"N/A" in subtask_constraint_assign_str_upper
109113
or "N / A" in subtask_constraint_assign_str_upper
@@ -112,10 +116,22 @@ def _default_parser(generated_str: str) -> list[SubtaskPromptConstraintsItem]:
112116
):
113117
subtask_constraint_assign = []
114118
else:
115-
subtask_constraint_assign = [
116-
line.strip()[2:] if line.strip()[:2] == "- " else line.strip()
117-
for line in subtask_constraint_assign_str.splitlines()
118-
]
119+
subtask_constraint_assign = []
120+
for line in subtask_constraint_assign_str.splitlines():
121+
stripped = line.strip()
122+
123+
if not stripped:
124+
continue
125+
126+
# Only keep lines starting with "- "
127+
if stripped.startswith("- "):
128+
value = stripped[2:].strip()
129+
if value:
130+
subtask_constraint_assign.append(value)
131+
continue
132+
133+
# Remove duplicates while preserving order
134+
subtask_constraint_assign = list(dict.fromkeys(subtask_constraint_assign))
119135

120136
result.append(
121137
SubtaskPromptConstraintsItem(

0 commit comments

Comments
 (0)