niadraProcessor() is an input and output processor for the Mastra agent: it rewrites the prompt of each model call without touching the message list and records the final answer. niadraTools(session) returns the history kit as Mastra tools. TypeScript only.
Install
@niadra/sdk on npm.
The five primitives
The session comes from the request context (
requestContext.set("niadra", convo)), or is fixed when the processor is built for one conversation.
Minimal example
examples/mastra.ts.
Agent memory
niadraProcessor({ agentMemory: true }) puts the agent’s own notes before the customer’s context, and niadraTools(convo, { agentMemory: { write: true } }) adds the two tools. See Agent memory.
Turn records
With theturns feature on in the space (it ships on), niadraProcessor({ turns: true }) records each request as a turn record, with the tool and model calls. A run inside a turn in progress records into it, and in a replay Mastra tools answer from the record. A turn never waits for Niadra and never repeats the conversation’s text.
Limits
- Mastra’s
Memory(threads, working memory) stays Mastra’s; Niadra is the customer’s memory shared with the company’s other agents. - Nothing here fails the call: without a pack, the prompt goes as Mastra built it.
- Tested against
@mastra/core1.71 with a fake model and Niadra on the emulator.
Next steps
Vercel AI SDK
the middleware for
wrapLanguageModel.TypeScript SDK
the conversation, the
suffix and markInjected().
