Skip to content

Commit 2261bf8

Browse files
committed
feat: enforce markdown-only output for comment publishing
1 parent 3c6f8f3 commit 2261bf8

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/issuelab/agents/executor.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@
3232

3333
_SYSTEM_EXECUTION_TIMEOUT_SECONDS = 600
3434

35-
_OUTPUT_SCHEMA_BLOCK = (
35+
_OUTPUT_SCHEMA_BLOCK_MARKDOWN = (
36+
"\n\n## Output Format (required)\n"
37+
"请使用 Markdown 输出,禁止输出 YAML/JSON 代码块。\n\n"
38+
"请严格使用以下结构:\n"
39+
"- `## Summary`:1-3 句结论\n"
40+
"- `## Key Findings`:2-5 条要点(列表)\n"
41+
"- `## Recommended Actions`:1-5 条可执行动作(任务列表)\n"
42+
"- 如需触发协作,仅在文末使用受控区:`---\\n相关人员: @user1 @user2` 或 `协作请求:` 列表\n"
43+
)
44+
45+
_OUTPUT_SCHEMA_BLOCK_YAML = (
3646
"\n\n## Output Format (required)\n"
3747
"优先输出以下 YAML;若无法稳定产出 YAML,可降级为结构化 Markdown(Summary/Findings/Recommendations):\n\n"
3848
"```yaml\n"
@@ -60,11 +70,13 @@ def _should_retry_run_exception(exc: Exception) -> bool:
6070
return not isinstance(exc, TimeoutError | asyncio.CancelledError)
6171

6272

63-
def _append_output_schema(prompt: str) -> str:
73+
def _append_output_schema(prompt: str, stage_name: str | None = None) -> str:
6474
"""为 prompt 注入统一输出格式(如果尚未注入)。"""
6575
if "## Output Format (required)" in prompt:
6676
return prompt
67-
return f"{prompt}{_OUTPUT_SCHEMA_BLOCK}"
77+
if stage_name:
78+
return f"{prompt}{_OUTPUT_SCHEMA_BLOCK_YAML}"
79+
return f"{prompt}{_OUTPUT_SCHEMA_BLOCK_MARKDOWN}"
6880

6981

7082
async def run_single_agent(prompt: str, agent_name: str, *, stage_name: str | None = None) -> dict:
@@ -110,7 +122,7 @@ async def _query_agent():
110122
tool_calls = []
111123
first_result = True
112124

113-
effective_prompt = _append_output_schema(prompt)
125+
effective_prompt = _append_output_schema(prompt, stage_name=stage_name)
114126
async for message in query(prompt=effective_prompt, options=options):
115127
# AssistantMessage: AI 响应(文本或工具调用)
116128
if isinstance(message, AssistantMessage):
@@ -922,6 +934,7 @@ async def run_agent_task(agent_name: str, results: dict[str, dict]) -> None:
922934
- 请以 [Agent: {agent_name}] 为前缀发布你的回复
923935
- 专注于 Issue 的讨论话题和内容
924936
- 不要去分析项目代码或架构(除非 Issue 明确要求)
937+
- 仅输出 Markdown,禁止输出 YAML/JSON 代码块
925938
"""
926939
if os.environ.get("PROMPT_LOG") == "1":
927940
max_len = 2000

0 commit comments

Comments
 (0)