Skip to content

fix(langchain): enable PreRouter by default to match Python behavior#91

Merged
saschabuehrle merged 1 commit intomainfrom
fix/langchain-enable-pre-router-default
Nov 24, 2025
Merged

fix(langchain): enable PreRouter by default to match Python behavior#91
saschabuehrle merged 1 commit intomainfrom
fix/langchain-enable-pre-router-default

Conversation

@saschabuehrle
Copy link
Copy Markdown
Collaborator

Problem

TypeScript LangChain integration had enablePreRouter: false by default, which meant:

  • ALL queries went through drafter first
  • Only quality-based cascading happened (after drafter generated response)
  • No pre-analysis to skip drafter for very complex queries

This was inconsistent with Python's enable_pre_router=True default.

Solution

Changed TypeScript default to enablePreRouter: true to match Python behavior.

What This Fixes

Complex queries analyzed BEFORE sending to drafter

  • HARD/EXPERT complexity queries skip drafter entirely
  • Go straight to verifier for very complex queries
  • Saves latency by avoiding unnecessary drafter attempts

Matches Python behavior exactly

  • Python: enable_pre_router=True (default)
  • TypeScript: enablePreRouter: true (now default)
  • n8n: useComplexityRouting: true (already correct)

Changes

  1. packages/langchain-cascadeflow/src/wrapper.ts:60
    • Changed enablePreRouter ?? falseenablePreRouter ?? true
  2. packages/langchain-cascadeflow/src/types.ts:47
    • Updated docs from @default false@default true

Testing

  • ✅ All 62 TypeScript tests passing
  • ✅ n8n integration already has correct default
  • ✅ Behavior now consistent across Python and TypeScript

Related

**Problem**: TypeScript LangChain integration had `enablePreRouter: false` by default,
causing ALL queries to go through drafter first, relying only on quality-based cascading.

**Solution**: Changed default to `enablePreRouter: true` to match Python's behavior.

**What this fixes**:
- Complex queries (HARD/EXPERT) are now analyzed BEFORE sending to drafter
- Very complex queries skip drafter entirely and go straight to verifier
- Saves latency by avoiding unnecessary drafter attempts on complex queries
- Matches Python LangChain integration behavior (enable_pre_router=True)

**Changes**:
1. `wrapper.ts:60` - Changed `enablePreRouter ?? false` to `enablePreRouter ?? true`
2. `types.ts:47` - Updated documentation from `@default false` to `@default true`

**Verification**:
- ✅ All 62 TypeScript tests passing
- ✅ n8n integration already has correct default (useComplexityRouting: true)
- ✅ Behavior now consistent across Python and TypeScript
@saschabuehrle saschabuehrle merged commit 5489f51 into main Nov 24, 2025
19 checks passed
@saschabuehrle saschabuehrle deleted the fix/langchain-enable-pre-router-default branch November 24, 2025 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant