iT邦幫忙

2025 iThome 鐵人賽

DAY 3
1
生成式 AI

團隊 AI 運維手冊:System Prompt 的設計、部署與維護系列 第 3

Day 3|System Prompt 範例研究 (一):從 x1xhlol 收集看其他人的設計

  • 分享至 

  • xImage
  •  

站在巨人的肩膀上

在 Day 2 我們發現了核心問題:AI 工具的「世界觀」不統一,導致程式碼風格差異巨大。在開始設計自己的團隊 System Prompt 之前,我們決定先研究業界最成功的範例,看看別人是怎麼設計的。

x1xhlol:GitHub 上的 System Prompt 的收集庫

第一個研究對象:x1xhlol/system-prompts-and-models-of-ai-tools

x1xhlol/system-prompts-and-models-of-ai-tools 收集的不是推測或逆向工程的結果,而是從實際運行環境中提取的完整設定檔,包括:

  • 主流商業工具:Cursor、Claude Code、Windsurf、Devin 等付費產品的完整配置
  • 開源解決方案:Cline、Bolt、Continue 等開源工具的標準設定
  • 企業級服務:v0、Lovable、Manus 等企業產品的內部配置

但我還是針對我的需求,Claude Code 與 Cursor 的設定檔進行研究:

Claude Code 的 System Prompt 設計解析

讓我們深入分析 x1xhlol/system-prompts-and-models-of-ai-tools 收集的 Claude Code 完整設定檔:

工具定義與功能範圍

Claude Code 的配置檔首先明確其身份和能力:

You are an interactive CLI tool that helps users with software engineering tasks.

清楚表明其使用情境:命令列介面的軟體工程助手。

溝通風格設計

You MUST answer concisely with fewer than 4 lines (not including tool use or code generation), unless user asks for detail.
IMPORTANT: You should minimize output tokens as much as possible while maintaining helpfulness, quality, and accuracy.

這種設計反映了 CLI 工具追求效率的特性,避免冗長的回應影響工作流程。

程式風格規範

IMPORTANT: DO NOT ADD ***ANY*** COMMENTS unless asked
Do not add additional code explanation summary unless requested by the user.

這個設計哲學是「程式碼應該自我解釋」,只有在必要時才添加註解。

任務管理機制

強制使用任務管理工具:

IMPORTANT: Always use the TodoWrite tool to plan and track tasks throughout the conversation.

這確保了每個開發任務都有清晰的追蹤和管理。

Cursor Agent 的 System Prompt 設計解析

接下來看看 x1xhlol 收集的 Cursor Agent 設定檔:

工具定位與協作理念

You are a powerful agentic AI coding assistant, powered by Claude 3.5 Sonnet. You operate exclusively in Cursor, the world's best IDE. You are pair programming with a USER to solve their coding task.

Cursor 的身份定位完全不同:

  • 角色:程式設計夥伴
  • 環境:專屬 IDE 整合
  • 關係:協作式互動

高詳細度程式標準

Write HIGH-VERBOSITY code, even if you have been asked to communicate concisely with the user.
Use **meaningful** variable names as described in Martin's 'Clean Code': Descriptive enough that comments are generally not needed

在程式品質上有明確要求,這反映了 IDE 環境中對程式可讀性和維護性的重視。

上下文理解策略

TRACE every symbol back to its definitions and usages so you fully understand it.
Look past the first seemingly relevant result. EXPLORE alternative implementations, edge cases, and varied search terms until you have COMPREHENSIVE coverage of the topic.

採用深度理解策略,這確保了 AI 在處理複雜問題時有足夠的上下文理解。

兩套範本的核心差異比較

設計哲學對比

Claude Code 的哲學

  • 極簡主義:最少的輸出,最大的效率
  • 工具導向:用戶知道自己要什麼,AI 只需執行
  • CLI 思維:快速、直接、無多餘資訊

Cursor 的哲學

  • 協作主義:AI 是開發夥伴,需要主動思考
  • IDE 導向:提供豐富的上下文和選擇
  • 品質優先:詳細的程式勝過簡潔的程式

實際產出差異

當面對「實作用戶登入功能」的需求時:

Claude Code 可能產出

function authenticateUser($username, $password) {
    return verifyCredentials($username, $password) ? loginSuccess() : loginFailure();
}

Cursor 可能產出

/**
 * 處理用戶登入請求
 * @param string $username 用戶名稱
 * @param string $password 用戶密碼
 * @return AuthenticationResult 認證結果
 * @throws AuthenticationException 當認證過程失敗時拋出異常
 */
function authenticateUser(string $username, string $password): AuthenticationResult
{
    try {
        $authenticationResult = $this->authenticationService
            ->verifyCredentials($username, $password);
        
        if ($authenticationResult->isSuccessful()) {
            return $this->handleLoginSuccess($authenticationResult);
        } else {
            return $this->handleLoginFailure($authenticationResult->getErrorCode());
        }
    } catch (Exception $authenticationError) {
        $this->logger->error('User authentication failed', [
            'error' => $authenticationError->getMessage(),
            'username' => $username
        ]);
        
        throw new AuthenticationException(
            'Authentication process failed', 
            0, 
            $authenticationError
        );
    }
}

設計原則的啟發

透過研究 x1xhlol 收集的這些頂級 System Prompt,我們歸納出幾個關鍵設計原則:

  1. 明確的身份定位:成功的 System Prompt 都會清楚定義 AI 的角色和能力邊界
  2. 分層的功能設計:從安全、效率到品質,每個層面都有專門的設計考量
  3. 環境適應性:不同工具針對其使用環境進行了深度優化
  4. 可擴展的架構:設計都預留了學習和適應的機制

對我們團隊的具體啟示

通過這次研究,我們發現了幾個關鍵問題:

  1. 風格差異的根本原因:不是工具本身的問題,而是設計哲學的差異
  2. 統一的可能性:兩套系統都有明確的規範結構,證明統一標準是可行的
  3. 漸進式改進:可以先統一核心要素(命名、註解),再逐步精緻化

這些發現為我們後續設計統一的 System Prompt 提供了重要方向。我們需要在 Claude Code 的效率和 Cursor 的完整性之間找到平衡點,確保團隊成員無論使用哪種工具,都能產出風格一致的程式碼。

明天我們將繼續探討其他重要的參考來源。我們的目標是通過多方研究,最終設計出一套確保團隊一致性的統一 System Prompt 架構。


上一篇
Day 2|AI 幫寫程式,怎麼搞得像不同團隊寫的?
下一篇
Day 4|System Prompt 範例研究 (二):AGENTS.md 規範看統一配置的可能性
系列文
團隊 AI 運維手冊:System Prompt 的設計、部署與維護5
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言