Recipes
Copy-pasteable cookbook for @dudousxd/nestjs-agent — a hand-rolled ModelProvider, flipping the inline runner to durable, DI-powered functional tools, a billing export off the governance read-model, and exercising the whole loop offline.
Every recipe here is a complete, working example built against the real SPIs — the same interfaces the shipped adapters (aiSdkModel, the MikroORM/Drizzle stores, InlineAgentRunner) implement. Read the problem statement, copy the code, adapt the clearly-marked sketch parts to your stack.
| Recipe | When you reach for it |
|---|---|
Custom ModelProvider | You're not going through the Vercel AI SDK — implement the ModelProvider SPI by hand against your own gateway or client, streaming to the sink and returning tool calls without ever executing them. |
| Inline → durable | You started with the in-process runner and now want checkpointed, replay-safe turns and a real HITL suspend — flip durable: true, same wire protocol. |
| Functional tools with DI | A tool needs constructor-injected dependencies but you don't want a whole @AiTool class — register it as data + handler via provideAgentTool. |
| Billing export | Beyond the shipped dashboard/telescope surfaces, you want your own CSV/JSON spend export off the same governance read-model. |
| Offline testing | Unit- or e2e-test tool calling, HITL approval, and multi-agent delegation with zero API key, zero Redis, fully in-memory. |
Each recipe links back to the concept or guide page that explains the mechanism — the recipes are the how, the guides are the why.
@dudousxd/nestjs-agent-testing
In-memory store, governance queries, quota, token sink, and a deterministic fake model — the whole agent loop, offline.
Custom ModelProvider
Implement the ModelProvider SPI by hand for a gateway or client aiSdkModel doesn't cover — stream text deltas to the sink, translate the endpoint's tool-call events, and never execute a tool yourself.