组装最终的 system prompt 段落列表
(self)
| 435 | |
| 436 | # 对应 prompt.rs:134-156 的 build() |
| 437 | def build(self) -> list[str]: |
| 438 | """组装最终的 system prompt 段落列表""" |
| 439 | sections = [] |
| 440 | |
| 441 | # 固定段落 (对应 get_simple_intro_section 等) |
| 442 | sections.append("You are Claude, an AI assistant by Anthropic.") |
| 443 | |
| 444 | # 可选: 输出风格 |
| 445 | if self._style_name and self._style_prompt: |
| 446 | sections.append(f"# Output Style: {self._style_name}\n{self._style_prompt}") |
| 447 | |
| 448 | sections.append("# System\n- Follow instructions carefully.") |
| 449 | sections.append("# Doing tasks\n- Complete tasks step by step.") |
| 450 | |
| 451 | # 动态分界线 (对应 SYSTEM_PROMPT_DYNAMIC_BOUNDARY) |
| 452 | # 分界线以上是静态内容 (API 缓存), 以下是动态内容 (每次不同) |
| 453 | sections.append("__SYSTEM_PROMPT_DYNAMIC_BOUNDARY__") |
| 454 | |
| 455 | # 可选: 环境信息 |
| 456 | if self._os_name: |
| 457 | sections.append( |
| 458 | f"# Environment\n" |
| 459 | f"- Platform: {self._os_name} {self._os_version}\n" |
| 460 | f"- CWD: {self._project_cwd or 'unknown'}\n" |
| 461 | f"- Date: {self._current_date or 'unknown'}" |
| 462 | ) |
| 463 | |
| 464 | # 自定义段落 |
| 465 | sections.extend(self._extra_sections) |
| 466 | |
| 467 | return sections |
| 468 | |
| 469 | # ---- 使用 Builder ---- |
| 470 | print(" 正面教材 (Builder 链式调用):") |