跳到主要内容

Confident AI exporter

Confident AI 是一个 LLM 可观测性与评估平台,帮助团队在开发和生产环境中构建可靠的 AI 应用。

@mastra/deepeval 软件包会将 Mastra Trace 发送到 Confident AI,你可以在那里针对 Trace 运行指标,并持续跟踪质量变化。它基于平台背后的开源评估 SDK DeepEval 构建。

安装
安装的直接链接

npm install @mastra/deepeval@latest

配置
配置的直接链接

前提条件
前提条件的直接链接

  1. Confident AI 账户:在 confident-ai.com 注册
  2. API key:在 Confident AI 项目设置中生成
  3. 环境变量:设置凭据:
.env
CONFIDENT_API_KEY=confident_proj_xxxxxxxxxxxxx

# Optional
CONFIDENT_TRACE_ENVIRONMENT=production # Defaults to "development"

零配置设置
零配置设置的直接链接

设置环境变量后,无需任何配置即可使用 exporter:

src/mastra/index.ts
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()],
},
},
}),
})

显式配置
显式配置的直接链接

你也可以直接传入凭据(优先于环境变量):

src/mastra/index.ts
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 运行。

src/mastra/index.ts
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
},
})

完整配置
完整配置的直接链接

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 类型映射
Span 类型映射的直接链接

Mastra span 会映射到 Confident AI 中显示的 span 类型:

Mastra span 类型Confident AI span 类型
AGENT_RUN, WORKFLOW_RUNAGENT
MODEL_GENERATIONLLM
TOOL_CALL, MCP_TOOL_CALL, PROVIDER_TOOL_CALL, CLIENT_TOOL_CALLTOOL
RAG_EMBEDDING, RAG_VECTOR_OPERATIONRETRIEVER
所有其他导出的 span 类型CUSTOM