AgentsMDInjector
AgentsMDInjector loads directory instructions before a model step. It scans completed tool calls in the message list, newest first, and searches their path arguments for AGENTS.md, CLAUDE.md, or CONTEXT.md in the directory ancestry.
import { AgentsMDInjector } from '@mastra/core/processors'
const injector = new AgentsMDInjector({ maxTokens: 1000 })
Add the processor to an agent's inputProcessors. Each invocation injects at most one new instruction reminder as a persisted reactive signal. The search skips already loaded paths and continues until it finds an uncovered instruction file.
Constructor optionsDirect link to Constructor options
maxTokens?:
reminderText?:
pathExists?:
isDirectory?:
readFile?:
getIgnoredInstructionPaths?:
isEnabled?:
getReader?:
ReminderFileReaderDirect link to reminderfilereader
A reader controls both file access and optional path identity. Return one from getReader when instruction files live in a virtual filesystem or a trusted git ref rather than the current checkout.
pathExists:
isDirectory:
readFile:
getPathIdentity?:
getPathIdentity applies to in-search deduplication, ignored static paths, and paths in persisted reminder metadata or markup. It doesn't rewrite read addresses, emitted paths, instruction content, or storage. It must accept paths from previous reminders as well as current tool calls, including files that no longer exist in the current checkout.
The default local reader resolves filesystem aliases for comparison. Supplying any instance-level filesystem override, or a custom reader without getPathIdentity, keeps lexical path comparison without adding host filesystem lookups for identity.
For trusted git-ref readers, identify a file by its canonical project root and its path relative to that root. Don't resolve checkout-controlled descendant symlinks: two distinct files in the trusted ref remain distinct even if the checkout makes them point to the same physical file.
Visibility and trustDirect link to Visibility and trust
The reminder remains in model context and storage when a caller uses stream exclusions to hide its signal chunks. Exclusions aren't an instruction-trust boundary. Use isEnabled and a trusted reader to control whether checkout instructions can be loaded.