Skip to main content

buildBasePrompt()

buildBasePrompt() builds the shared base system prompt for a coding agent — the behavioral instructions that make the agent a good coding assistant. It takes a PromptContext describing the current environment (project, platform, git branch, mode, model) and returns the prompt as a string.

Product-specific strings are parameterized through productName, coAuthorName, and coAuthorEmail, so you can rebrand the prompt and commit trailer without forking it. They default to "Mastra Code" / "noreply@mastra.ai", so existing callers keep identical output.

Use this with createCodingAgent() when you build dynamic instructions for the agent.

Usage example
Direct link to Usage example

Build the base prompt from a PromptContext:

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: '',
})

To rebrand the prompt, pass the product and co-author fields:

const prompt = buildBasePrompt({
// ...environment fields
productName: 'Acme Coder',
coAuthorName: 'Acme Bot',
coAuthorEmail: 'bot@acme.dev',
})

Parameters
Direct link to Parameters

buildBasePrompt() takes a single PromptContext object.

projectPath:

string
Absolute path to the project root.

projectName:

string
Display name of the project.

gitBranch?:

string
Current git branch, if the project is a git repository.

platform:

string
Operating system platform (for example, the value of process.platform).

commonBinaries?:

{ name: string; path: string | null }[]
Common binaries detected on the system, each with a name and resolved path (or null when not found).

date:

string
Current date string injected into the prompt.

mode:

string
Active agent mode (for example, "build" or "plan").

modelId?:

string
Identifier of the active model, included in the commit Co-Authored-By line when provided.

activePlan?:

{ title: string; plan: string; approvedAt: string } | null
The currently approved plan, if any.

toolGuidance:

string
Tool-usage guidance section appended to the prompt.

productName?:

string
= Mastra Code
Display name used in the prompt header.

coAuthorName?:

string
= Mastra Code
Name used in the commit Co-Authored-By line.

coAuthorEmail?:

string
= noreply@mastra.ai
Email used in the commit Co-Authored-By line.

Returns
Direct link to Returns

prompt:

string
The base system prompt for the coding agent.
On this page