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() 使用此函式。
使用範例「使用範例」的直接連結
從 PromptContext 建立基礎 prompt:
src/mastra/prompt.ts
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 的品牌,請傳入產品與共同作者欄位:
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
= Mastra Code
prompt 標頭中使用的顯示名稱。
coAuthorName?:
string
= Mastra Code
commit Co-Authored-By 行中使用的名稱。
coAuthorEmail?:
string
= noreply@mastra.ai
commit Co-Authored-By 行中使用的電子郵件。
傳回值「傳回值」的直接連結
prompt:
string
Coding Agent 的基礎 system prompt。