> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # buildBasePrompt() `buildBasePrompt()` 为 Coding Agent 构建共享的基础系统 Prompt,即让 Agent 成为优秀编程助手的行为指令。它接收描述当前环境(项目、平台、Git 分支、模式和模型)的 `PromptContext`,并以字符串形式返回 Prompt。 产品特定字符串通过 `productName`、`coAuthorName` 和 `coAuthorEmail` 参数化,因此无需 Fork 即可更换 Prompt 和 Commit Trailer 中的品牌。这些字段默认为 `"Mastra Code"` / `"noreply@mastra.ai"`,因此现有调用方的输出保持不变。 为 Agent 构建运行时定义的指令时,可将它与 [`createCodingAgent()`](https://mastra.zisheng.pro/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`): 当前已批准的 Plan(如果有)。 **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 的基础系统 Prompt。 ## 相关内容 - [`createCodingAgent()`](https://mastra.zisheng.pro/reference/coding-agent/create-coding-agent)