> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # buildBasePrompt() `buildBasePrompt()` 會建立編程助手共用的基礎系統 prompt,當中包含令 Agent 成為優秀編程助手的行為指示。此函數接受描述目前環境(項目、平台、git 分支、模式、模型)的 `PromptContext`,並以字串形式傳回 prompt。 產品專屬字串會透過 `productName`、`coAuthorName` 和 `coAuthorEmail` 參數化,因此你無需 fork 即可重新命名 prompt 及 commit trailer。這些欄位預設為 `"Mastra Code"` / `"noreply@mastra.ai"`,所以現有呼叫端的輸出會保持不變。 為 Agent 建立執行階段定義的指示時,可將此函數配合 [`createCodingAgent()`](https://mastra.zisheng.pro/zh-HK/reference/coding-agent/create-coding-agent) 使用。 ## 使用範例 根據 `PromptContext` 建立基礎 prompt: ```typescript import { buildBasePrompt } from '@mastra/core/coding-agent' const prompt = buildBasePrompt({ projectPath: process.cwd(), projectName: 'my-app', gitBranch: 'main', platform: process.platform, date: new Date().toDateString(), mode: 'build', modelId: 'openai/gpt-5', toolGuidance: '', }) ``` 如要重新命名 prompt,請傳入產品及共同作者欄位: ```typescript const prompt = buildBasePrompt({ // ...environment fields productName: 'Acme Coder', coAuthorName: 'Acme Bot', coAuthorEmail: 'bot@acme.dev', }) ``` ## 參數 `buildBasePrompt()` 接受單一 `PromptContext` 物件。 **projectPath** (`string`): 項目根目錄的絕對路徑。 **projectName** (`string`): 項目的顯示名稱。 **gitBranch** (`string`): 如果項目是 git 儲存庫,則為目前的 git 分支。 **platform** (`string`): 作業系統平台(例如 process.platform 的值)。 **commonBinaries** (`{ name: string; path: string | null }[]`): 系統偵測到的常用二進制執行檔,每項均包含名稱及解析後的路徑(找不到時為 null)。 **date** (`string`): 注入 prompt 的目前日期字串。 **mode** (`string`): 目前生效的 Agent 模式(例如 "build" 或 "plan")。 **modelId** (`string`): 目前生效的模型標識符;提供時會加入 commit 的 Co-Authored-By 行。 **activePlan** (`{ title: string; plan: string; approvedAt: string } | null`): 目前已獲核准的計劃(如有)。 **toolGuidance** (`string`): 附加至 prompt 的 Tool 使用指引部分。 **productName** (`string`): prompt 標題所用的顯示名稱。 (Default: `Mastra Code`) **coAuthorName** (`string`): commit 的 Co-Authored-By 行所用的名稱。 (Default: `Mastra Code`) **coAuthorEmail** (`string`): commit 的 Co-Authored-By 行所用的電郵地址。 (Default: `noreply@mastra.ai`) ## 傳回值 **prompt** (`string`): 編程助手的基礎系統 prompt。 ## 相關內容 - [`createCodingAgent()`](https://mastra.zisheng.pro/zh-HK/reference/coding-agent/create-coding-agent)