メインコンテンツへ移動

Confident AI exporter

Confident AI は、開発環境と本番環境の両方で信頼性の高い AI アプリケーションを構築するチーム向けの LLM Observability・評価プラットフォームです。

@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 の Project 設定で生成する
  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',
}),
],
},
},
}),
})

Metric collection
Metric collectionへの直接リンク

Confident AI は、Project で定義された Metric collection を使用して、受信した Trace を評価します。Metric collection は Trace レベルまたは Span type ごとに関連付けます。Trace レベルのメトリクスは Trace 全体に対して実行され、Type ごとのメトリクスは一致する 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 type のマッピング
Span type のマッピングへの直接リンク

Mastra の Span は、Confident AI に表示される次の Span type にマッピングされます。

Mastra Span typeConfident AI Span type
AGENT_RUN, WORKFLOW_RUNAGENT
MODEL_GENERATIONLLM
TOOL_CALL, MCP_TOOL_CALL, PROVIDER_TOOL_CALL, CLIENT_TOOL_CALLTOOL
RAG_EMBEDDING, RAG_VECTOR_OPERATIONRETRIEVER
その他のエクスポート対象 Span typeCUSTOM