İçeriğe geç
mcpd
daemon yok
Kaynak

Hızlı başlangıç

Daemon çalışıyor, ajan ölçümlendi, trace ekranda. Kaydolunacak bir yer ve yanına kurulacak bir şey yok.

1. Daemon'u çalıştırın

Henüz bir sürüm yayımlanmadı.

Bu sitedeki komutların adını verdiği imaj, chart ve paketler planlanan dağıtımdır; hiçbiri yayımlanmadı. Bugün çalışan yol, kaynaktan derlemektir ve Rust ile Node gerekir:

Derleyip çalıştırma

git clone https://github.com/mcpd/mcpd && cd mcpd && make build && ./target/release/mcpd demo

mcpd, depolaması içine derlenmiş tek bir süreçtir. Ayağa kaldırılacak bir veritabanı ve yazılacak bir yapılandırma dosyası yoktur.

docker run -p 4317:4317 -v mcpd-data:/data ghcr.io/mcpd/mcpd

Volume isteğe bağlıdır ama eklemeye değer: onsuz, konteyner gittiğinde trace'ler de gider. İkili dosyayı mı tercih edersiniz? Doğrudan kurun.

görmeniz gereken
$ docker run -p 4317:4317 ghcr.io/mcpd/mcpdWARN listening on 0.0.0.0:4317 with open ingest. Anyone who can reach this port can write to it. Set --ingest-key (or MCPD_INGEST_KEYS) before exposing it.WARN listening on 0.0.0.0:4317 with an open read API. Stored prompts and completions are readable by anyone who can reach this port. Set --read-key to require a key.WARN listening on 0.0.0.0:4317 with an open run surface. Anyone who can reach this port can start runs and claim steps. Set --execute-key and --worker-key before exposing it.INFO mcpd 0.1.0 listening on http://0.0.0.0:4317INFO   interface   http://0.0.0.0:4317/INFO   OTLP        http://0.0.0.0:4317/v1/tracesINFO   native      http://0.0.0.0:4317/v1/ingestINFO   runs        http://0.0.0.0:4317/v1/api/runsINFO   storage     sqlite at /data/mcpd.db

Uyarılar en başta gelir ve bu bilinçlidir. Dizüstünüzde bir önemleri yok. Bu porta başka bir şey erişebilir hâle gelmeden önce Dağıtım sayfasını okuyun.

2. Ona bir şey gönderin

İki giriş yolu var ve bizimkini seçmek zorunda değilsiniz. Ajanınız zaten OpenTelemetry üretiyorsa onu mcpd'ye yöneltin ve tek satır yeni kod yazmayın:

export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317

Aksi hâlde dilinizin SDK'sını kurun. Zorunlu bağımlılığı yoktur ve bir span kaydetmek asla bloklamaz, asla hata fırlatmaz.

bağlanma

import { Mcpd } from '@mcpd/sdk'

// Every field here also reads an environment variable, so the same code runs
// unchanged in development and in production. With no arguments at all this
// talks to a daemon on http://localhost:4317.
const mcpd = new Mcpd({
  project: 'support',
  environment: 'development',
  serviceName: 'support-agent',
  serviceVersion: '1.4.0',
})

3. Bir çalıştırmayı ölçümleyin

Ajanınızın yaptığı işi sarın. Bir span; neyin girdiğini, neyin çıktığını, ne kadar sürdüğünü ve ne kadara mal olduğunu kaydeder. Alt span'ler onun içine kendiliğinden yerleşir, böylece bloğun içinde yapılan bir araç çağrısı, nereye ait olduğu söylenmeden ağaçta doğru yere düşer.

bir çalıştırmayı kaydetme

/**
 * One ticket, one trace.
 *
 * `withSpan` opens the span, keeps it active for everything the callback
 * starts, and ends it when the callback settles. Nothing inside has to be
 * passed a handle to be nested under it.
 */
async function handleTicket(ticket: Ticket): Promise<{ answer: string; traceId: string }> {
  let traceId = ''
  const answer = await mcpd.withSpan('support_agent', async (run) => {
    // Keep the id: a score or a piece of feedback that arrives later attaches
    // to this run by it.
    traceId = run.traceId
    // Tags label the whole run, so the trace list can filter on them.
    run.setTags(['support', 'tier-1'])
    run.setCorrelation({ sessionId: ticket.id, userId: ticket.customerId })
    run.setInput({ question: ticket.question })

    const order = await lookUpOrder(ticket)
    const answer = await draftAnswer(ticket, order)

    run.setOutput({ answer })
    return answer
  })
  return { answer, traceId }
}

4. Okuyun

localhost:4317 adresini açın. Çalıştırmanız listede. Onu açtığınızda ağacın tamamını alırsınız: her model çağrısı prompt'u ve tamamlamasıyla, her araç çağrısı argümanları ve sonucuyla, süreler, token sayıları ve maliyet.

Trace b3d9e71a Fault
0ms 2.1s 4.2s 6.3s 8.4s
  1. agent support_agent fail
  2. model chat
  3. tool returns_policy
  4. model chat
  5. tool returns_policy
  6. model chat
  7. tool returns_policy

The model called one tool three times and never answered. That is visible in four seconds here, and invisible in a log file.

5. İlginç olanı bulun

Vaktinizi listede değil, aramada geçireceksiniz. mcpd her prompt'u ve her tamamlamayı dizinler; böylece bir müşterinin şikâyet ettiği şeyi modelin söylediği çalıştırmaya doğrudan gidebilirsiniz:

arama ve analiz

// The same client reads. This is the query that finds bad answers: every run
// that a scorer put below the bar.
const suspect = await mcpd.listTraces({
  hasScore: 'answer_relevance',
  scoreBelow: 0.5,
  limit: 10,
})
console.log(`runs scoring under 0.5: ${suspect.traces.length}`)

const recent = await mcpd.listTraces({ limit: 5, sort: 'start_time', order: 'desc' })
for (const trace of recent.traces) {
  const seconds = ((trace.durationNs ?? 0) / 1e9).toFixed(2)
  console.log(
    `${trace.traceId.slice(0, 8)}  ${trace.name.padEnd(16)} ${trace.status.padEnd(6)} ` +
      `${seconds}s  ${trace.spanCount} spans  $${(trace.cost?.totalCost ?? 0).toFixed(6)}`,
  )
}

// One run, with every span in it, ordered so a waterfall renders directly.
const detail = await mcpd.getTrace(traceId, { include: ['scores', 'feedback'] })
for (const span of detail.spans) {
  console.log(`  ${span.kind.padEnd(18)} ${span.name}`)
}

Bundan sonra nereye

Artık döngünün tamamı elinizde. Sırada okumaya değer sayfalar ne yaptığınıza bağlı: