fix(colang): preserve comments above bot say as instructions#1925
fix(colang): preserve comments above bot say as instructions#1925adityasingh2400 wants to merge 1 commit into
Conversation
…ructions (closes NVIDIA-NeMo#1322) Signed-off-by: Aditya Singh <adisin650@gmail.com>
Greptile SummaryThis PR fixes a long-standing Colang 1.0 bug where a
|
| Filename | Overview |
|---|---|
| nemoguardrails/actions/llm/generation.py | Single-line guard added to bypass the predefined-utterance short-circuit when the BotIntent carries instructions; logic is correct for the common path but instructions are still silently ignored when single_call mode is active. |
| tests/test_bot_message_instructions.py | Three well-structured regression tests covering the new instruction path, end-to-end prompt propagation, and backward-compat shortcut preservation; uses established call.task filtering pattern. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[generate_bot_message called] --> B{BotIntent has instructions?}
B -- "bool(event.get('instructions')) → True" --> C[bot_intent_has_instructions = True]
B -- "False / None / empty string" --> D[bot_intent_has_instructions = False]
C --> E{bot_intent in config.bot_messages AND NOT bot_intent_has_instructions?}
D --> E
E -- "True (no instructions, predefined exists)" --> F[Use predefined utterance, skip_output_rails = True]
E -- "False (has instructions OR no predefined)" --> G{bot_intent starts with '$' and var in context?}
G -- "True" --> H[Use context variable, Ignores instructions]
G -- "False" --> I{single_call.enabled?}
I -- "True" --> J[Use pre-computed single-call message, Instructions still ignored]
I -- "False" --> K[Call LLM, Instruction in BotIntent event reaches render_task_prompt]
F --> L[Return bot utterance]
H --> L
J --> L
K --> L
Comments Outside Diff (1)
-
nemoguardrails/actions/llm/generation.py, line 810-866 (link)Instructions silently ignored when
single_callmode is activeWhen
rails.dialog.single_call.enabledisTrue, theelsebranch is entered correctly (the new guard works), but the very first thing it does is check whether the pre-computed single-call bot-message matches the current intent and, if so, returns that pre-computed text immediately — before reaching the normal LLM-generation code at the bottom of theelseblock. The pre-computed message was produced by the single-call LLM prompt, which was assembled before the BotIntent'sinstructionsfield existed in the event stream, so those instructions are never incorporated. Users who configuresingle_call.enabled: trueand add comment instructions abovebot <name>will see this PR's fix have no effect in their setup.Prompt To Fix With AI
This is a comment left during a code review. Path: nemoguardrails/actions/llm/generation.py Line: 810-866 Comment: **Instructions silently ignored when `single_call` mode is active** When `rails.dialog.single_call.enabled` is `True`, the `else` branch is entered correctly (the new guard works), but the very first thing it does is check whether the pre-computed single-call bot-message matches the current intent and, if so, returns that pre-computed text immediately — before reaching the normal LLM-generation code at the bottom of the `else` block. The pre-computed message was produced by the single-call LLM prompt, which was assembled before the BotIntent's `instructions` field existed in the event stream, so those instructions are never incorporated. Users who configure `single_call.enabled: true` and add comment instructions above `bot <name>` will see this PR's fix have no effect in their setup. How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
nemoguardrails/actions/llm/generation.py:810-866
**Instructions silently ignored when `single_call` mode is active**
When `rails.dialog.single_call.enabled` is `True`, the `else` branch is entered correctly (the new guard works), but the very first thing it does is check whether the pre-computed single-call bot-message matches the current intent and, if so, returns that pre-computed text immediately — before reaching the normal LLM-generation code at the bottom of the `else` block. The pre-computed message was produced by the single-call LLM prompt, which was assembled before the BotIntent's `instructions` field existed in the event stream, so those instructions are never incorporated. Users who configure `single_call.enabled: true` and add comment instructions above `bot <name>` will see this PR's fix have no effect in their setup.
Reviews (1): Last reviewed commit: "fix(colang): preserve comments above bot..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR fixes comment instructions in Colang bot message flows. When a BotIntent carries instructions (from comments), predefined sample utterances are now skipped, allowing the LLM generation path to apply those instructions. The fix adds instruction detection in ChangesBot Message Instructions
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Closes #1322.
In Colang 1.0, the documentation describes comments above a
bot say <name>line as natural-language instructions that shape the LLM's generated response. In practice the runtime did attach the comment to the BotIntent event asinstructions, butgenerate_bot_messageshort-circuited with the predefined sample utterance wheneverbot_intentappeared inconfig.bot_messages, so the comment never reached the model and the bot ignored it.This change keeps the existing short-circuit for the common case (no comment, predefined utterance used verbatim) but skips it when the BotIntent carries
instructions, so the LLM is invoked with the colang history that already includes the# ...instruction. Behavior without a comment is unchanged.Added regression tests in
tests/test_bot_message_instructions.pycovering three cases: the comment is attached to the BotIntent, the comment reaches the prompt sent to the LLM, and the predefined-utterance shortcut is preserved when no comment is present.Summary by CodeRabbit
Bug Fixes
Tests