export_dpo_pairs
Extract DPO preference pairs from local memory logs to enable direct preference optimization for AI model training.
Instructions
Export DPO preference pairs from local memory log
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| memoryLogPath | No |
Implementation Reference
- adapters/mcp/server-stdio.js:225-255 (handler)The handler function `buildExportDpoResponse` in `adapters/mcp/server-stdio.js` implements the `export_dpo_pairs` tool, which takes memories and exports DPO JSONL triples.
function buildExportDpoResponse(args = {}) { let memories = []; if (args.inputPath) { const inputPath = resolveSafePath(args.inputPath, { mustExist: true }); const raw = fs.readFileSync(inputPath, 'utf-8'); const parsed = JSON.parse(raw); memories = Array.isArray(parsed) ? parsed : parsed.memories || []; } else { const memoryLogPath = args.memoryLogPath ? resolveSafePath(args.memoryLogPath, { mustExist: true }) : DEFAULT_LOCAL_MEMORY_LOG; memories = readJSONL(memoryLogPath); } const result = exportDpoFromMemories(memories); if (args.outputPath) { const outputPath = resolveSafePath(args.outputPath); fs.mkdirSync(path.dirname(outputPath), { recursive: true }); fs.writeFileSync(outputPath, result.jsonl); } return toTextResult({ pairs: result.pairs.length, errors: result.errors.length, learnings: result.learnings.length, unpairedErrors: result.unpairedErrors.length, unpairedLearnings: result.unpairedLearnings.length, outputPath: args.outputPath ? resolveSafePath(args.outputPath) : null, }); } - scripts/export-dpo-pairs.js:155-187 (handler)The logic for exporting DPO pairs from memories is implemented in `exportDpoFromMemories` in `scripts/export-dpo-pairs.js`.
function exportDpoFromMemories(memories) { const errors = memories.filter((m) => m.category === 'error'); const learnings = memories.filter((m) => m.category === 'learning'); const result = buildDpoPairs(errors, learnings); const traces = result.pairs.map((pair) => traceForDpoPair(pair)); const reasoning = aggregateTraces(traces); const pairsWithTraces = result.pairs.map((pair, i) => ({ ...pair, metadata: { ...pair.metadata, reasoningTrace: { traceId: traces[i].traceId, confidence: traces[i].summary.confidence, passed: traces[i].summary.passed, verified: traces[i].summary.verified, refuted: traces[i].summary.refuted, edgeCases: traces[i].edgeCases, }, }, })); return { pairs: pairsWithTraces, unpairedErrors: result.unpairedErrors, unpairedLearnings: result.unpairedLearnings, errors, learnings, reasoning, jsonl: toJSONL(pairsWithTraces), }; } - adapters/mcp/server-stdio.js:388-389 (registration)The `export_dpo_pairs` tool is registered in the switch block of the `callToolInner` function within `adapters/mcp/server-stdio.js`.
case 'export_dpo_pairs': return buildExportDpoResponse(args);