B. 故障排查¶
Studio 里看不到 Agent¶
检查:
src/mastra/index.ts是否导出了mastra。- Agent 是否注册到
new Mastra({ agents: { ... } })。 - TypeScript 是否有编译错误。
id是否重复。
模型调用失败¶
检查:
.env是否存在。- API Key 名称是否和供应商要求一致。
model: 'provider/model-name'是否写对。- 当前供应商是否支持你使用的 tool calling 或 structured output。
Tool 没有被调用¶
常见原因:
- description 太模糊。
- instructions 没告诉 agent 什么时候使用工具。
- 输入 schema 太复杂或字段不清楚。
- 用户问题不需要工具。
.generate()或.stream()里限制了activeTools。
排查方式:
- 在 Studio 看 tool call。
- 临时把 instructions 写得更明确。
- 单独测试 Tool 的
execute。 - 减少同类工具数量。
Tool 参数不对¶
优先改 schema 和 description,而不是在 prompt 里补一堆自然语言。
建议:
- 给字段加
.describe()。 - 使用 enum 限定取值。
- 用
strict: true,前提是模型供应商支持。 - 在
execute内做业务校验。
Workflow 没有输出¶
检查:
- 是否调用了
.commit()。 - 每个 step 的
outputSchema是否匹配实际返回。 - 上一步 output 是否满足下一步 input。
- 是否检查了
result.status。 - 是否进入
suspended或failed状态。
Memory 记不住¶
检查:
- 是否安装并配置了 storage。
- Agent 是否配置了
memory: new Memory(...)。 - 每次调用是否传入同一个
resource和thread。 - 是否把 thread id 给不同 resource 复用了。
- storage 是否在服务重启后丢失。
MCP 连接失败¶
检查:
- stdio MCP 的
command和args是否能在 shell 中单独运行。 - remote MCP 的 URL 是否可访问。
- token 是否通过环境变量传入。
- 多租户场景是否错误复用了全局凭据。
- 用完动态 MCPClient 后是否调用
disconnect()。
构建时报模块解析错误¶
检查 tsconfig.json:
不要在新 Mastra 项目里使用 CommonJS 配置。