ワンクリックで
mastra-patterns
Mastra Agent/Tool/Workflow 定义模式、config-as-data 函数式壳、Concierge/Vertical Agent、注册中心、流式响应、自定义路由。编写 src/mastra/ 下代码前必读。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Mastra Agent/Tool/Workflow 定义模式、config-as-data 函数式壳、Concierge/Vertical Agent、注册中心、流式响应、自定义路由。编写 src/mastra/ 下代码前必读。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
IoT AI Platform 的 TypeScript 严格模式、错误处理、测试策略、依赖管理、Git commit 规范、安全编码守则。编写任何代码前先读本 Skill。
接入层(Tap)集成模式:MQTT Tap、Webhook Tap、Shifu 可选连接器;统一 Event Envelope、幂等/DLQ。编写设备接入代码时使用。见 ADR-0016。
Mastra Model Router、多 provider、成本控制(3 道闸门)、Vertical Skill(垂类模型经 MCP 发现 + 独立推理端点)、Embedding。编写 LLM/模型调用代码时使用。见 ADR-0008。
三层租户隔离 SQL 模式、pgvector 记忆表、遥测时序(TimescaleDB)与特征库(Feast)、迁移规范。编写数据库相关代码时使用。见 ADR-0004/0010/0013。
IoT AI Platform 目标架构(分面)、层间契约、数据流、可扩展性核心。理解系统全局、做跨层决策、新增能力前使用。真相源是 CONTEXT.md + docs/adr/。
| name | mastra-patterns |
| description | Mastra Agent/Tool/Workflow 定义模式、config-as-data 函数式壳、Concierge/Vertical Agent、注册中心、流式响应、自定义路由。编写 src/mastra/ 下代码前必读。 |
Agent 框架 = Mastra(ADR-0007,无沉没成本 bake-off 后确认)。垂类由声明式 Solution Pack manifest 驱动,非每垂类写死代码。
不要每垂类写死一个 Agent。定义少数 agent 壳,其 instructions/tools/model 是 runtimeContext 的函数,按 Pack Manifest 在运行时解析:
new Agent({
id: "vertical-agent-shell",
model: ({ runtimeContext }) =>
resolveModel(packRegistry.get(runtimeContext.get("packId")).model),
tools: ({ runtimeContext }) =>
packRegistry.get(runtimeContext.get("packId")).tools,
instructions: ({ runtimeContext }) =>
packRegistry.get(runtimeContext.get("packId")).instructions,
});
manifest 加载前 Zod 强校验;只引用白名单工具、不内联代码/密钥(ADR-0014)。
id kebab-case 全局唯一;instructions 中文,含输入/输出/工具/边界model 用 resolveModel() 字符串路由——绝不硬编码厂商 SDK(避免硬编码模型字面量,优先 env/manifest)src/mastra/tools/<category>/<tool-id>.ts,zod inputSchema/outputSchemarequestContext 取 tenantId+accountId,绝不用客户端传入的(ADR-0014)inputSchema/outputSchema,output→input 显式衔接mastra.getAgent('id').generate(),不裸 APIcreateRun({ resourceId }) 带三层租户上下文 tenant:{t}:account:{a}:user:{u}const stream = await agent.stream(message, {
memory: { thread: conversationId, resource: resourceId },
});
return new Response(stream.toDataStreamResponse().body, {
headers: { "Content-Type": "text/event-stream" },
});
registerApiRoute("/webhooks/iot-event", {
method: "POST",
handler: async (c) => {
/* ... */
},
});
Mastra 保留 /api/ 前缀,自定义路由用其他前缀。