createCodingAgent()
createCodingAgent() builds a coding Agent with portable defaults for the pieces a coding agent always needs: a local workspace, the task-list signal provider, network-retry error processors, and the goal judge prompt. Supply only model, instructions, and tools to get a working agent, or override any default.
The returned value is a standard Agent, so it works anywhere an Agent does — including as the agent passed to an AgentController.
Usage exampleDirect link to Usage example
Pass a model, instructions, and tools. The factory fills in the workspace, task signal, error processors, and goal prompt:
import { createCodingAgent } from '@mastra/core/coding-agent'
const agent = createCodingAgent({
id: 'my-coding-agent',
name: 'My Coding Agent',
model: 'openai/gpt-5',
instructions: 'You are a helpful coding assistant.',
tools: {},
})
ParametersDirect link to Parameters
createCodingAgent() accepts every field of AgentConfig plus the fields below. Fields you provide always take precedence over the factory defaults.
model:
instructions:
tools?:
workspace?:
basePath?:
signals?:
errorProcessors?:
goal?:
ReturnsDirect link to Returns
agent:
DefaultsDirect link to Defaults
The factory only fills a default when you do not provide the corresponding field. Caller-provided values always win.
| Field | Default when omitted |
|---|---|
workspace | A Workspace backed by LocalFilesystem and LocalSandbox rooted at the base path. |
signals | A single TaskSignalProvider. |
errorProcessors | ECONNRESET and bad-request retry processors plus PrefillErrorHandler and ProviderHistoryCompat. |
goal.prompt | DEFAULT_GOAL_JUDGE_PROMPT (only when a goal is configured). |
WorkspaceDirect link to Workspace
When the workspace key is omitted, the factory builds a local workspace rooted at basePath (default process.cwd()):
import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace'
new Workspace({
filesystem: new LocalFilesystem({ basePath }),
sandbox: new LocalSandbox({ workingDirectory: basePath }),
})
To opt out — for example when the workspace is injected at the AgentController level — pass workspace: undefined explicitly:
const agent = createCodingAgent({
id: 'my-coding-agent',
name: 'My Coding Agent',
model: 'openai/gpt-5',
instructions: 'You are a helpful coding assistant.',
tools: {},
workspace: undefined, // opt out of the default workspace
})
Error processorsDirect link to Error processors
The default error processors apply a retry policy for transient failures:
- Network resets (
ECONNRESET/socket hang up) retry up to twice with exponential backoff (1000ms * 2^retryCount, capped at30000ms). - Bad-request errors retry once after
2000ms.
PrefillErrorHandler and ProviderHistoryCompat are also included for provider compatibility.