niadraMiddleware(session) is a language model middleware for wrapLanguageModel({ model, middleware }): the AI SDK’s idiomatic path, which works with every provider without a separate provider package. niadraTools(session) returns the history kit as AI SDK tools. TypeScript only.
Install
@niadra/sdk 0.3.0, ready on main and on npm when it is published; until then the npm package is 0.1.1.
The five primitives
Minimal example
examples/ai-sdk.ts.
Agent memory
niadraMiddleware(convo, { 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.
Limits
- Nothing here fails the model call: a context that does not arrive is left out, and a failure to record is logged without content.
- The middleware does not wrap the provider: any AI SDK
LanguageModel, from any provider, works. - Tested against
ai7 (with the types of versions 5 and 6) and a fake model, with Niadra on the emulator, on Node, Deno, Bun, workerd and the Edge Runtime.
Next steps
Mastra
the same design, as an agent processor.
TypeScript SDK
the conversation, the
suffix and markInjected().
