> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # buildBasePrompt() `buildBasePrompt()` 會建立 Coding Agent 共用的基礎 system prompt,也就是讓 Agent 成為優良程式設計助理的行為指示。此函式接受描述目前環境(專案、平台、git branch、模式、模型)的 `PromptContext`,並以字串傳回 prompt。 產品專屬字串透過 `productName`、`coAuthorName` 與 `coAuthorEmail` 參數化,因此不必建立 fork,即可變更 prompt 與 commit trailer 的品牌。這些欄位預設為 `"Mastra Code"` / `"noreply@mastra.ai"`,所以現有呼叫端會維持相同輸出。 為 Agent 建立執行階段定義的 instructions 時,請搭配 [`createCodingAgent()`](https://mastra.zisheng.pro/zh-TW/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 repository,則為目前的 git branch。 **platform** (`string`): 作業系統平台(例如 process.platform 的值)。 **commonBinaries** (`{ name: string; path: string | null }[]`): 系統上偵測到的常用 binary,每個項目包含名稱與解析後的路徑(找不到時為 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`): Coding Agent 的基礎 system prompt。 ## 相關內容 - [`createCodingAgent()`](https://mastra.zisheng.pro/zh-TW/reference/coding-agent/create-coding-agent)