|
32 | 32 |
|
33 | 33 | _SYSTEM_EXECUTION_TIMEOUT_SECONDS = 600 |
34 | 34 |
|
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 = ( |
36 | 46 | "\n\n## Output Format (required)\n" |
37 | 47 | "优先输出以下 YAML;若无法稳定产出 YAML,可降级为结构化 Markdown(Summary/Findings/Recommendations):\n\n" |
38 | 48 | "```yaml\n" |
@@ -60,11 +70,13 @@ def _should_retry_run_exception(exc: Exception) -> bool: |
60 | 70 | return not isinstance(exc, TimeoutError | asyncio.CancelledError) |
61 | 71 |
|
62 | 72 |
|
63 | | -def _append_output_schema(prompt: str) -> str: |
| 73 | +def _append_output_schema(prompt: str, stage_name: str | None = None) -> str: |
64 | 74 | """为 prompt 注入统一输出格式(如果尚未注入)。""" |
65 | 75 | if "## Output Format (required)" in prompt: |
66 | 76 | 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}" |
68 | 80 |
|
69 | 81 |
|
70 | 82 | async def run_single_agent(prompt: str, agent_name: str, *, stage_name: str | None = None) -> dict: |
@@ -110,7 +122,7 @@ async def _query_agent(): |
110 | 122 | tool_calls = [] |
111 | 123 | first_result = True |
112 | 124 |
|
113 | | - effective_prompt = _append_output_schema(prompt) |
| 125 | + effective_prompt = _append_output_schema(prompt, stage_name=stage_name) |
114 | 126 | async for message in query(prompt=effective_prompt, options=options): |
115 | 127 | # AssistantMessage: AI 响应(文本或工具调用) |
116 | 128 | if isinstance(message, AssistantMessage): |
@@ -922,6 +934,7 @@ async def run_agent_task(agent_name: str, results: dict[str, dict]) -> None: |
922 | 934 | - 请以 [Agent: {agent_name}] 为前缀发布你的回复 |
923 | 935 | - 专注于 Issue 的讨论话题和内容 |
924 | 936 | - 不要去分析项目代码或架构(除非 Issue 明确要求) |
| 937 | +- 仅输出 Markdown,禁止输出 YAML/JSON 代码块 |
925 | 938 | """ |
926 | 939 | if os.environ.get("PROMPT_LOG") == "1": |
927 | 940 | max_len = 2000 |
|
0 commit comments