Skip to content

Commit 48298b7

Browse files
fix on skip greeting response when query contains a substantive question (buerokratt#378)
* remove unwanted file * updated changes * fixed requested changes * fixed issue * service workflow implementation without calling service endpoints * fixed requested changes * fixed issues * protocol related requested changes * fixed requested changes * update time tracking * added time tracking and reloacate input guardrail before toolclassifiier * fixed issue * fixed issue * added hybrid search for the service detection * update tool classifier * fixing merge conflicts * fixed issue * optimize first user query response generation time * fixed pr reviewed issues * service integration * context based response generation flow * fixed pr review suggested issues * removed service project layer * fixed issues * delete unnessary files * added requested changes * fix on skip greeting response when query contains a substantive question --------- Co-authored-by: Thiru Dinesh <56014038+Thirunayan22@users.noreply.github.com>
1 parent 399d1a3 commit 48298b7

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/tool_classifier/context_analyzer.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,19 @@ class ContextAnalysisSignature(dspy.Signature):
3939
This signature instructs the LLM to:
4040
1. Detect greetings in multiple languages (Estonian, English)
4141
2. Check if query references conversation history
42-
3. Generate appropriate responses or extract answers from history
42+
3. Generate appropriate responses based on context
4343
4444
Supported greeting types:
4545
- hello: Tere, Hello, Hi, Hei, Hey, Moi, Good morning, Good afternoon, Good evening
4646
- goodbye: Nägemist, Bye, Goodbye, See you, Good night
4747
- thanks: Tänan, Aitäh, Thank you, Thanks, Much appreciated
4848
- casual: Tervist, Tšau, Moikka
4949
50+
IMPORTANT — Greeting + Question distinction:
51+
- A message is a greeting ONLY if it contains NOTHING beyond the greeting itself.
52+
- If the message contains a greeting AND a substantive question or request,
53+
set is_greeting to FALSE so the question is answered properly.
54+
5055
The LLM should respond in the SAME language as the user's query.
5156
"""
5257

@@ -139,6 +144,15 @@ class ContextDetectionSignature(dspy.Signature):
139144
- thanks: Tänan, Aitäh, Thank you, Thanks, Much appreciated
140145
- casual: Tervist, Tšau, Moikka
141146
147+
IMPORTANT — Greeting + Question distinction:
148+
- A message is a greeting ONLY if it contains NOTHING beyond the greeting itself
149+
(e.g. "Hello!", "Tere!", "Thanks!", "Aitäh!").
150+
- If the message contains a greeting AND a substantive question or request
151+
(e.g. "Hello, how to show uninterest to a policy?",
152+
"Tere, mis on sünnitoetus?", "Hi, what are the tax benefits?"),
153+
set is_greeting to FALSE. The question must be answered via RAG, not a greeting template.
154+
- When in doubt, prefer is_greeting=false so the user's question is answered.
155+
142156
Do NOT generate the answer here — only detect and extract a relevant context snippet.
143157
"""
144158

@@ -152,7 +166,8 @@ class ContextDetectionSignature(dspy.Signature):
152166
'greeting_type must be one of: "hello", "goodbye", "thanks", "casual" — '
153167
'set it only when is_greeting is true, defaulting to "hello" otherwise. '
154168
"context_snippet should contain the relevant excerpt from history if can_answer_from_context is true, "
155-
"or null otherwise. Do NOT generate the final answer — only detect and extract."
169+
"or null otherwise. Do NOT generate the final answer — only detect and extract. "
170+
"CRITICAL: is_greeting must be false when the message contains a question or request alongside the greeting."
156171
)
157172

158173

src/tool_classifier/workflows/context_workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import dspy
66
from loguru import logger
77

8-
from models.request_models import OrchestrationRequest, OrchestrationResponse
8+
from src.models.request_models import OrchestrationRequest, OrchestrationResponse
99
from tool_classifier.base_workflow import BaseWorkflow
1010
from tool_classifier.context_analyzer import ContextAnalyzer, ContextDetectionResult
1111
from tool_classifier.workflows.service_workflow import LLMServiceProtocol

src/utils/language_detector.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ def detect_language(text: str) -> LanguageCode:
8383
"nagu",
8484
"oli",
8585
"mis",
86+
# Estonian greeting words
87+
"tere",
88+
"hei",
89+
"tervist",
90+
"tänan",
91+
"aitäh",
92+
"nägemist",
93+
"moi",
8694
]
8795

8896
# Tokenize and check for Estonian markers

0 commit comments

Comments
 (0)