Skip to main content

config.ts

An agent's config.ts sets its model and runtime options. Use it for options that belong to the Agent itself, while sibling files provide instructions, tools, skills, et cetera.

What belongs in config.ts
Direct link to what-belongs-in-configts

config.ts is the required entry point for a file-based agent's model and runtime options. Put agent-level settings here when they don't need their own file, such as the model, description, default execution options, retry behavior, scorers, and display identity.

Keep adjacent concerns in sibling files when you want file-based routing to merge them into the agent. For example, use instructions.md for the always-on prompt and tools/ for model-callable actions.

Quickstart
Direct link to Quickstart

The following config.ts plus an instructions.md file creates a working file-based agent:

src/mastra/agents/weather/config.ts
import { agentConfig } from '@mastra/core/agent'

export default agentConfig({
model: 'openai/gpt-5.5',
})
src/mastra/agents/weather/instructions.md
You are a helpful weather assistant. Answer questions about current conditions and forecasts.

Mastra uses the weather directory name as the default agent id and name. The sibling instructions.md supplies the required instructions.

Set the model
Direct link to Set the model

The model field is the only required field in agentConfig(). The build fails when an agent directory doesn't provide a model. Other capabilities either come from sibling files or have defaults.

src/mastra/agents/weather/config.ts
import { agentConfig } from '@mastra/core/agent'

export default agentConfig({
model: 'openai/gpt-5.5',
})

Identity from the directory
Direct link to Identity from the directory

A file-based agent's id and name default to the directory name. For src/mastra/agents/weather/, Mastra registers the agent as weather unless you override those fields.

Override id or name when the stable routing key and the display name should differ.

src/mastra/agents/weather/config.ts
import { agentConfig } from '@mastra/core/agent'

export default agentConfig({
id: 'weather-assistant',
name: 'Weather Assistant',
model: 'openai/gpt-5.5',
})

Set runtime options
Direct link to Set runtime options

agentConfig() accepts Agent constructor options, except that id, name, and sibling-file fields can be supplied by the file-based convention. Use the Agent reference for the full option list.

Please note:

  • File-based subagents require a non-empty description because the parent model uses it for delegation routing.
  • defaultOptions, maxRetries, scorers, and other Agent options can live in config.ts when they don't need their own file.

Where adjacent settings live
Direct link to Where adjacent settings live

Keep config.ts focused on runtime options. Use sibling files for concerns that benefit from their own location.

SettingFile or folderWhy it lives there
Instructionsinstructions.mdKeeps the always-on prompt readable as markdown
Toolstools/Gives each callable action its own typed module
Skillsskills/Keeps load-on-demand procedures separate from always-on instructions
Memorymemory.tsConfigures persistent memory without crowding runtime options
Workspaceworkspace.tsConfigures files and sandbox behavior separately from model settings
Processorsprocessors/Separates input and output processing pipelines
Subagentssubagents/Gives each specialist child agent its own directory

Precedence
Direct link to Precedence

config.ts merges with the agent's other files according to these rules:

DomainSource ASource BWinner
InstructionsDynamic config.instructionsinstructions.mdDynamic config.instructions
InstructionsStatic config.instructionsinstructions.mdinstructions.md
Toolsconfig.toolstools/Both merge; config.tools wins on key collisions
ToolsFunction config.toolstools/Function config.tools; discovered tools are ignored
Skillsconfig.skillsskills/Both merge; config.skills wins on name collisions
SkillsFunction config.skillsskills/Function config.skills; discovered skills are ignored
Memoryconfig.memorymemory.tsconfig.memory
Workspaceconfig.workspaceworkspace.tsconfig.workspace

Missing both instructions.md and config.instructions fails the build. Missing both config.memory and memory.ts leaves the agent without memory.