Skip to content

fix(libsy): restate the routing instruction after windowed conversation - #520

Open
gburachas wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
gburachas:pr/restate-routing-instruction
Open

fix(libsy): restate the routing instruction after windowed conversation#520
gburachas wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
gburachas:pr/restate-routing-instruction

Conversation

@gburachas

@gburachas gburachas commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Addresses the first of the two changes described in #279. The second, capping the payload size, will be a separate pull request.

What

When an llm_classifier route sets recent_turn_window, one sentence is appended as the last message sent to the judge:

Route the conversation above. Output ONLY the routing JSON object, nothing else.

Nothing changes when recent_turn_window is unset.

Why

The judge is asked to classify a request and reply with a routing JSON object. Its instructions lead the payload, which works while that payload is one short message.

With a window configured, the instructions are followed by assistant turns and tool output. The judge then sometimes answers the conversation rather than classifying it. That reply does not parse as a verdict, so the route falls back to its default target: the turn is served, and the only sign that routing did not happen is a warning in the log.

Example: a request of "check my account balance", with a window containing a long stack trace from a failed tool call. The verdict describes the stack trace.

Scope

Only the windowed path is affected. With recent_turn_window unset, task_messages sends the opening task and the latest user follow-up, with no assistant or tool content between the instruction and the end of the payload.

Tests

Two, in crates/libsy/src/algorithms/llm_class.rs:

  • a_window_restates_the_routing_instruction_last asserts the instruction is the last message, not merely present. Position is the whole mechanism: moving the same message to the front makes this test fail.
  • the_default_path_is_left_unchanged asserts the unwindowed request shape is untouched.

Naming

An earlier draft called this "reinforcement", which reads as reinforcement learning and is unrelated. The constant is TRAILING_ROUTING_INSTRUCTION and the issue has been retitled.

How tested

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace
  • uv run ruff check .
  • Commit signed off per the DCO

One file, 66 lines, of which 45 are the two tests.

Note for anyone reading the CodeRabbit panel: the "Docstring Coverage" check measures Python docstrings and this diff is Rust only.

Summary by CodeRabbit

  • Improvements

    • Windowed capability and custom classification requests now provide clearer routing guidance, resulting in JSON-only routing responses.
    • Requests without windowing retain their existing behavior and format.
  • Tests

    • Added coverage to verify routing guidance appears in the correct position and that default requests remain unchanged.

Signed-off-by: Giedrius Burachas <gburachas@nvidia.com>
@gburachas
gburachas requested a review from a team as a code owner August 21, 2026 21:52
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3b84ccf4-a5f4-4137-bc0b-9a57f44674b5

📥 Commits

Reviewing files that changed from the base of the PR and between 053a61e and 2913f51.

📒 Files selected for processing (1)
  • crates/libsy/src/algorithms/llm_class.rs

Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review.


Walkthrough

Windowed judge inputs now append a final routing-only user instruction. The default no-window path remains unchanged. Tests verify the final message position and the default message shape.

Changes

Windowed routing behavior

Layer / File(s) Summary
Append routing instruction to windowed messages
crates/libsy/src/algorithms/llm_class.rs
TaskInput::build_messages defines and appends TRAILING_ROUTING_INSTRUCTION when recent_turn_window is configured. Tests verify windowed and no-window message sequences.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 2913f

The PR adds a trailing routing instruction only for windowed conversations while preserving the default path; no actionable merge-blocking risk remains after normal checks and review.

Poem

I’m a rabbit with routes in my ear,
A final JSON hop makes the path clear.
Windowed turns line up in a row,
No-window messages stay as they go.
Hop, hop—clean prompts now flow!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main routing-instruction change for windowed conversations.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

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