Skip to content

M17 slice 1: LangSmith bridge core (fetch → map → verify → feedback) - #217

Merged
surlymochan merged 1 commit into
mainfrom
m17s1-langsmith-bridge
Nov 18, 2026
Merged

surlymochan merged 1 commit into
mainfrom
m17s1-langsmith-bridge

Conversation

@surlymochan

Copy link
Copy Markdown
Owner

M17 slice 1: LangSmith bridge core (fetch → map → verify → feedback)

Fixes #216 · part of epic #215 (evalid as LangSmith's external deterministic judge)

What lands

src/core/langsmith-bridge.js (new) + xflow langsmith verify subcommand:

  1. Client — official langsmith JS SDK (Client, now a package dependency). Credentials only from env LANGSMITH_API_KEY; missing key is a hard, named error — nothing is fabricated. Optional LANGSMITH_ENDPOINT (SDK apiUrl) / LANGSMITH_PROJECT. The key is never written to disk or logs, and the SDK is dynamically imported so the rest of the CLI never loads it.
  2. Fetch — listRuns pulls up to --limit root runs (newest first, optional --since), then each root's full trace. A failed child-fetch degrades that trace to its root run with the error recorded, not silently dropped.
  3. Mapping (documented in the module header, unit-tested):
    • one trace = one verification session, runs ordered by start_time;
    • agent prose comes only from textual run outputs (string / content / output / result / response, content blocks, generations[].text, serialized chat-message kwargs.content);
    • tool and retriever outputs are never claim sources — they return environment data, mirroring live-claims' rule that tool output is not the agent's words; tool runs ride along as evidence records;
    • run errors are carried as session run-errors.
  4. Verify — the existing live-claims pipeline (createClaimChecker) runs unchanged: test-run claims replay in --cwd, file claims check there; per-session dedup exactly as the live path. No existing subcommand behavior or verdict semantics touched.
  5. Feedback — object-form createFeedback({runId, sessionId, key, score, comment, feedbackSourceType: 'api'}) on the trace's root run: key evalid_claim_verified, score = confirmed/checked (4 dp), comment = per-claim verdict lines with the pipeline's evidence note + the claim's source text. traceId is deliberately not passed so the write is synchronous — a failed write rejects here, is recorded per-trace, and the CLI keeps the local results file (to --out, or a fallback evalid-langsmith-results.json) and exits 1. Traces with no claims get no feedback.
  6. CLI — xflow langsmith verify --project <name> [--limit 20] [--since <iso>] [--cwd <dir>] [--dry-run] [--out <file>] [--json]; --dry-run fetches + verifies + reports the exact would-write payloads, writes nothing. Exit codes: 0 ok · 1 feedback write failed · 2 usage/config · 3 no runs found.

Tests

test/langsmith-bridge.test.js (15 tests) + recorded-shape fixture test/fixtures/langsmith/runs.json, SDK replaced by an injectable fake client:

  • text-extraction shapes and dedup; mapping order/prose-only/tool-evidence/errors;
  • missing-key hard error; injected factory receives key + endpoint; score rule;
  • full chain on fixtures: trace A yields 4 claims → 2 confirmed / 2 breach (real node --test replays + filesystem checks in a temp workspace), score 0.5; dry-run performs zero feedback calls but records would-write payloads; write mode posts exactly one feedback with the standard key on the root run; a throwing fake surfaces the failure with verdicts intact; trace B (errored, claim-free) is skipped as no_claims; empty project is a no-op;
  • CLI spawns: no key → exit 2 naming LANGSMITH_API_KEY; no project → exit 2; bare langsmith → help, exit 0.

Local suite: new file 15/15. Full suite otherwise green except two pre-existing environment failures that reproduce identically on clean main in this VM (pytest-replay cases in test/i6d-acceptance-demo.test.js and test/xflow-audit.test.js, A/B-verified via stash) — CI is the arbiter for those.

Design trade-offs

  • langsmith 0.13 SDK shape: the classic Client now lives under the package's lib/ surface but is still exported from the root; the new Stainless-style resources client is not used. createFeedback's object form requires sessionId (or an agent address) — the bridge takes it from the root run's session_id; if absent, the SDK error surfaces as a recorded write failure rather than a silent skip.
  • Score denominator: unknown counts as not verified (score = confirmed/checked), matching the epic's "已核验声称占比".
  • No live verification in this slice (no API key available), per M17 切片 1: LangSmith 桥接核心(拉取→映射→核验→回写) #216 — fixture chain only; live end-to-end is the epic's acceptance step once a key exists.

…erify → feedback)

New src/core/langsmith-bridge.js + 'xflow langsmith verify' subcommand:
- Official langsmith JS SDK Client; key only from env LANGSMITH_API_KEY
  (missing key is a hard error), optional LANGSMITH_ENDPOINT /
  LANGSMITH_PROJECT.
- listRuns pulls root runs + full traces; each trace maps to one
  verification session (agent prose only — tool/retriever outputs are
  evidence, never claim sources).
- Claims verified by the existing live-claims pipeline, unchanged
  semantics; score = confirmed/checked.
- createFeedback (object form, synchronous) writes key
  evalid_claim_verified + per-claim verdict comment to the root run;
  write failures surface and local results are preserved.
- --dry-run / --limit / --since / --cwd / --out / --json.
- Fixture-driven full-chain tests with an injectable fake SDK client.

Fixes #216
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

M17 切片 1: LangSmith 桥接核心(拉取→映射→核验→回写)

1 participant