Skip to content

feat(ask): add LLM-based routing classification#4

Open
rafeegnash wants to merge 4 commits intocf-agentfrom
fix/llm-routing-classification
Open

feat(ask): add LLM-based routing classification#4
rafeegnash wants to merge 4 commits intocf-agentfrom
fix/llm-routing-classification

Conversation

@rafeegnash
Copy link
Copy Markdown

Summary

  • Add LLM-based routing classification to prevent generic terms from incorrectly routing to Cloudflare
  • Simplify cloudflareKeywords to only match explicit Cloudflare mentions ("cloudflare", "wrangler", "cloudflared")
  • LLM classification is triggered when multiple services are detected or Cloudflare is inferred
  • Fallback to keyword-based inference if LLM classification fails

Changes

  • Added getRoutingClassificationPrompt() function for LLM routing prompt
  • Added classifyQueryWithLLM() function for LLM-based service classification
  • Modified routing flow to use LLM verification for ambiguous queries
  • Simplified cloudflareKeywords to prevent false positives

Test plan

  • Build passes (make build)
  • Tests pass (make test-short)
  • AWS routing works for generic terms like "cache", "cdn"
  • Cloudflare routing works when "cloudflare" is explicitly mentioned
  • K8s routing works for "list pods"
  • LLM fallback to keyword inference when classification fails

nash added 4 commits January 26, 2026 21:50
Replace keyword-based routing with LLM classification for ambiguous
queries. The LLM analyzes query context to determine which service
(AWS, Cloudflare, K8s, GCP) the user is asking about.

This prevents generic terms like "cache", "cdn", "worker" from
incorrectly routing to Cloudflare when the user means AWS.

LLM classification is triggered when:
- Multiple services are detected by keyword matching
- Cloudflare keywords are detected (to verify intent)

Fallback: If LLM classification fails, keyword-based inference is used.
Explicit flags (--cloudflare, --aws, --k8s) bypass LLM classification.
Add tests to verify:
- Cloudflare only triggers on explicit mentions (cloudflare, wrangler, cloudflared)
- Generic terms (cache, cdn, worker, waf, rate limit) do not trigger Cloudflare
- AWS routing works for ec2, lambda, dns
- K8s routing works for pods, kubernetes, kubectl
Move query routing classification logic from cmd/ask.go to
internal/routing package for better testability and code organization.

Changes:
- Create internal/routing/routing.go with InferContext, ClassifyWithLLM,
  NeedsLLMClassification, ApplyLLMClassification, GetClassificationPrompt
- Create internal/routing/routing_test.go with comprehensive tests
- Update cmd/ask.go to use the routing package
- Remove duplicate inferContext, classifyQueryWithLLM, and contains functions
- Delete cmd/ask_routing_test.go (tests moved to internal/routing)
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