> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # Confident AI exporter [Confident AI](https://www.confident-ai.com/) 是一个 LLM 可观测性与评估平台,帮助团队在开发和生产环境中构建可靠的 AI 应用。 `@mastra/deepeval` 软件包会将 Mastra Trace 发送到 Confident AI,你可以在那里针对 Trace 运行指标,并持续跟踪质量变化。它基于平台背后的开源评估 SDK [DeepEval](https://www.confident-ai.com/docs) 构建。 ## 安装 **npm**: ```bash npm install @mastra/deepeval@latest ``` **pnpm**: ```bash pnpm add @mastra/deepeval@latest ``` **Yarn**: ```bash yarn add @mastra/deepeval@latest ``` **Bun**: ```bash bun add @mastra/deepeval@latest ``` ## 配置 ### 前提条件 1. **Confident AI 账户**:在 [confident-ai.com](https://www.confident-ai.com/) 注册 2. **API key**:在 Confident AI 项目设置中生成 3. **环境变量**:设置凭据: ```bash CONFIDENT_API_KEY=confident_proj_xxxxxxxxxxxxx # Optional CONFIDENT_TRACE_ENVIRONMENT=production # Defaults to "development" ``` ### 零配置设置 设置环境变量后,无需任何配置即可使用 exporter: ```typescript import { Mastra } from '@mastra/core' import { Observability } from '@mastra/observability' import { DeepEvalExporter } from '@mastra/deepeval' export const mastra = new Mastra({ observability: new Observability({ configs: { deepeval: { serviceName: 'my-service', exporters: [new DeepEvalExporter()], }, }, }), }) ``` ### 显式配置 你也可以直接传入凭据(优先于环境变量): ```typescript import { Mastra } from '@mastra/core' import { Observability } from '@mastra/observability' import { DeepEvalExporter } from '@mastra/deepeval' export const mastra = new Mastra({ observability: new Observability({ configs: { deepeval: { serviceName: 'my-service', exporters: [ new DeepEvalExporter({ apiKey: process.env.CONFIDENT_API_KEY, environment: 'production', }), ], }, }, }), }) ``` ### 指标集合 Confident AI 会使用项目中定义的指标集合评估传入的 Trace。可以在 Trace 级别或按 span 类型附加指标集合。Trace 级指标针对完整 Trace 运行,按类型指标则针对匹配的 span 运行。 ```typescript new DeepEvalExporter({ metricCollection: 'trace-metrics', // trace-level llmMetricCollection: 'llm-metrics', // applied to LLM spans agentMetricCollection: 'agent-metrics', // applied to agent spans toolMetricCollectionMap: { search: 'search-tool-metrics', // applied to the "search" tool }, }) ``` ### 完整配置 ```typescript new DeepEvalExporter({ apiKey: process.env.CONFIDENT_API_KEY, environment: 'production', // Default: "development" name: 'my-trace', // Default: the Mastra serviceName tags: ['production'], metadata: { team: 'growth' }, }) ``` ## Span 类型映射 Mastra span 会映射到 Confident AI 中显示的 span 类型: | Mastra span 类型 | Confident AI span 类型 | | ---------------------------------------------------------------------- | -------------------- | | `AGENT_RUN`, `WORKFLOW_RUN` | `AGENT` | | `MODEL_GENERATION` | `LLM` | | `TOOL_CALL`, `MCP_TOOL_CALL`, `PROVIDER_TOOL_CALL`, `CLIENT_TOOL_CALL` | `TOOL` | | `RAG_EMBEDDING`, `RAG_VECTOR_OPERATION` | `RETRIEVER` | | 所有其他导出的 span 类型 | `CUSTOM` | ## 相关内容 - [Tracing 概览](https://mastra.zisheng.pro/docs/observability/tracing/overview) - [DeepEvalExporter 参考](https://mastra.zisheng.pro/reference/observability/tracing/exporters/confident-ai) - [Confident AI 文档](https://www.confident-ai.com/docs)