Skip to content

🪶 feat: Add Light Decisions and Rerank Subpath Exports - #623

Draft
danny-avila wants to merge 2 commits into
mainfrom
feat/light-decisions-subpaths
Draft

danny-avila wants to merge 2 commits into
mainfrom
feat/light-decisions-subpaths

Conversation

@danny-avila

@danny-avila danny-avila commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

What this unblocks

Importing anything from @librechat/agents today loads the root barrel. That barrel pulls in LangChain and the provider SDKs, even when the caller only wants the HTTP decision model or the System One reranker. src/rerank/systemone.ts also imported @/decisions, and that barrel reaches LangChain through the structured-chat adapter. So even a deep import of the reranker loaded about 289 modules.

This blocks two consumers:

  • codegraph, a separate code-intelligence daemon, keeps its own copies of the decision client and rerankers because it cannot afford LangChain in its process. It needs a light entry point before it can depend on the SDK instead.
  • LibreChat backends that only need decisions or reranking would load the full agent runtime to get them.

What changes

The package gains two entry points. Neither loads a third-party package at runtime.

Subpath Exports Modules loaded (ESM and CJS)
@librechat/agents/decisions decision types, questions, presets, createHttpDecisionModel, parseEnvelope, toWireQuestion/readAnswer, createTransport/failureForStatus/retryAfterMs, withDecisionDeadline 8, zero third-party
@librechat/agents/rerank Reranker types, createSystemOneReranker 5, zero third-party
src/decisions/core.ts   new: light barrel (everything except structuredChat)
src/decisions/index.ts  re-exports core + createStructuredChatDecisionModel
src/rerank/core.ts      new: light barrel (types + System One)
src/rerank/index.ts     re-exports core + createWebSearchReranker
src/rerank/systemone.ts imports decision leaf modules, not the @/decisions barrel
package.json            ./decisions and ./rerank in exports and typesVersions
config/light-entries.*  new guard: loads each subpath and fails on any third-party resolution

The root entry still exports everything it exported before. failureForStatus, retryAfterMs and withDecisionDeadline are now exported too, because hosts that build their own retry or breaker layer need the SDK's own status mapping. createStructuredChatDecisionModel binds a LangChain chat model, and createWebSearchReranker extends the search tool's reranker. Both stay on the root entry only.

How it was tested

  • npm run test:light-entries (new, node --test). For each subpath it starts a fresh process, loads the built ESM and CJS outputs through the package exports map, and records every module resolution with a loader hook. The test fails if any non-built-in package is reached, if a declaration import resolves outside the package, or if the manifest's exports, typesVersions or build entries fall out of sync. A control case checks that the probe does catch @langchain/core on ./langchain/messages. Result: 8/8 pass, with 8 modules for decisions and 5 for rerank. CI runs it in the validate job after the circular-dependency check.
  • Fix removal: I restored src/rerank/systemone.ts from main and rebuilt. Both ./rerank loads without third-party packages tests (esm and cjs) then fail. With the fix back in place, all 8 pass.
  • npx jest src/decisions src/rerank: 5 suites, 135 tests pass.
  • npx tsc --noEmit and npx tsc -p tsconfig.build.json pass.
  • npm run build passes.
  • npm run check:circular-deps passes.
  • eslint and prettier are clean on the touched files.

Stack

This is the base of a 4-PR stack that lets codegraph depend on the SDK's decisions and rerank modules:

  1. 🪶 feat: Add Light Decisions and Rerank Subpath Exports #623: light ./decisions and ./rerank subpaths (base main). This PR.
  2. 🎯 fix: Accept Two-Decimal Rounding and Quota Failures in System One Decisions #624: wire fidelity: two-decimal rounding bounds and the quota failure.
  3. 🔌 feat: Add Decision Credentials, a Breaker, and a Readiness Probe #625: credential, breaker, probe and redaction hooks.
  4. 🎚️ feat: Add Never-Throwing Rerank Outcomes With Per-Document System One, Cross-Encoder, BM25, and Fallback Chains #630: rerank parity: per-document System One, cross-encoder, BM25 and a never-throwing fallback chain.

The later PRs build on this branch and will be opened as drafts against it.

Expose @librechat/agents/decisions and @librechat/agents/rerank as built entries that load no third-party package. The System One reranker now imports decision leaf modules instead of the barrel that pulls LangChain through the structured-chat adapter. The root entry still exports everything.
Load the built decisions and rerank subpaths through the package exports map in a fresh process for ESM and CJS, record every resolution with a module hook, and fail when any non-built-in package is reached or a declaration import leaves the package. CI runs it after the circular dependency check.
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T15:14:28.835736Z 2e75b99 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 2e75b993ee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This branch has not been deployed

No deployments
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.

1 participant