Skip to content

Commit 448be01

Browse files
committed
Only detect the suported slash command in the natural language
1 parent 0eca2df commit 448be01

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

dspy_code/commands/nl_command_router.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -508,18 +508,32 @@ def route(
508508
slash_command_pattern = r'\b/(?:save|run|validate|connect|mcp-|init|help|status|clear|exit|optimize|eval|explain|model|models|data|examples|adapters|retrievers|demo|session)'
509509
has_slash_command = re.search(slash_command_pattern, user_input_lower) is not None
510510

511-
# For now, we are conservative: only attempt NL routing when the
512-
# user *explicitly* references slash commands, otherwise
513-
# we treat the input as a normal LLM request.
514-
if not has_slash_command:
511+
# Also check for natural language command patterns (without "/")
512+
# This allows commands like "list mcp servers" to be routed
513+
has_nl_command_pattern = False
514+
for cmd_name, cmd_info in self.command_mappings.items():
515+
for pattern in cmd_info.get("patterns", []):
516+
if re.search(pattern, user_input_lower, re.IGNORECASE):
517+
has_nl_command_pattern = True
518+
break
519+
if has_nl_command_pattern:
520+
break
521+
522+
# Route if either:
523+
# 1. User explicitly references a slash command (and it's not a file path)
524+
# 2. User's input matches a natural language command pattern
525+
if not has_slash_command and not has_nl_command_pattern:
515526
logger.debug(
516-
f"No explicit slash command reference in NL input, treating as normal LLM input: '{user_input}'"
527+
f"No command pattern match in NL input, treating as normal LLM input: '{user_input}'"
517528
)
518529
return None
519530

520-
# If the user mentions a specific slash command in natural language,
531+
# If the user mentions a command (either slash or natural language),
521532
# allow the LLM router to decide whether to dispatch it.
522-
logger.debug(f"Using LLM reasoning for explicit slash command reference: '{user_input}'")
533+
if has_slash_command:
534+
logger.debug(f"Using LLM reasoning for explicit slash command reference: '{user_input}'")
535+
else:
536+
logger.debug(f"Using LLM reasoning for natural language command pattern: '{user_input}'")
523537
return self._route_with_llm(user_input, context, pattern_matches=None)
524538

525539
def _route_with_llm(

0 commit comments

Comments
 (0)