Skip to content

An opensource LLM-powered intent router for your website!

License

Notifications You must be signed in to change notification settings

lucas-oma/fantastic-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

🌟 Fantastic Router

Fantastic Router

⚠️ Warning: Fantastic Router is still in active development. Expect rapid changes, incomplete features, and the occasional bug while we build toward a stable release.

An LLM-powered intent router for your website!

Transform natural language queries into precise navigation actions. Instead of forcing users to navigate complex menus, let them simply say what they want: "show me James Smith's monthly income" β†’ /landlords/james-smith-123/financials

πŸš€ What It Does

Fantastic Router uses Large Language Models to understand user intent and automatically route them to the right pages in your web application. It's like having an intelligent assistant that knows your entire application structure.

Key Features

  • 🧠 LLM-Powered: Uses GPT-4, Claude, or local models to understand natural language
  • πŸ” Smart Entity Resolution: Finds the right database records contextually
  • πŸ›£οΈ Pattern-Based Routing: Flexible route patterns that adapt to any application
  • πŸ”’ RBAC Integration: Role-based access control built-in
  • πŸ”Œ Pluggable Architecture: Works with any database, LLM provider, or vector store
  • πŸ“Š Domain Agnostic: Property management, e-commerce, CRM, healthcare - works anywhere

🎯 Use Cases

Perfect for applications with:

  • Complex navigation hierarchies (enterprise software, admin panels)
  • Deep data relationships (CRM systems, property management)
  • User experience bottlenecks (users can't find what they need)
  • Search limitations (traditional search isn't contextual enough)

πŸ—οΈ Architecture

User Query: "show me James Smith's income"
    ↓
🧠 Intent Parser (LLM) β†’ Understands: action=NAVIGATE, entity=James Smith, view=income
    ↓
πŸ” Entity Resolver β†’ Finds: james-smith-123 in landlords table
    ↓
πŸ›£οΈ Route Matcher (LLM) β†’ Matches: /{entity_type}/{entity_id}/{view_type}
    ↓
πŸ“ Action Plan β†’ Result: /landlords/james-smith-123/financials

πŸš€ Quick Start

Option 1: Try it Now with Docker (Recommended)

The fastest way to test Fantastic Router is with our Docker setup that includes a real database and sample data:

# 1. Clone the repository
git clone https://github.com/yourusername/fantastic-router
cd fantastic-router

# 2. Set up everything (database, sample data, dependencies)
make setup

# 3. Add your OpenAI API key
cp docker/.env.example docker/.env
# Edit docker/.env and add your OpenAI API key

# 4. Test with mock data (works without API key)
make test

# 5. Test with real database and LLM
make test-real

Available Make Commands:

make help        # Show all available commands
make up          # Start all services (app + database)
make up-db       # Start only the database
make test        # Run test with mock data
make test-real   # Run test with real database + LLM
make test-db     # Check database connection and data
make shell       # Open shell in app container
make db-shell    # Open PostgreSQL shell
make clean       # Clean up containers and volumes

Option 2: Manual Installation (still testing this, proceed with caution)

# Core library
pip install fantastic-router-core

# With OpenAI support
pip install fantastic-router-core[openai]

# With PostgreSQL support  
pip install fantastic-router-core[postgres]

# Everything
pip install fantastic-router-core[all]

Basic Usage

import asyncio
from fantastic_router_core import FantasticRouter
from fantastic_router_core.adapters.llm.openai import OpenAILLMClient
from fantastic_router_core.adapters.db.postgres import PostgreSQLDatabaseClient

async def main():
    # Set up LLM client
    llm_client = OpenAILLMClient(api_key="your-openai-key")
    
    # Set up database client
    db_client = PostgreSQLDatabaseClient(
        connection_string="postgresql://user:pass@localhost/db"
    )
    
    # Load configuration
    router = await FantasticRouter.from_config(
        config_path="routes.json",
        llm_client=llm_client,
        db_client=db_client
    )
    
    # Route a query
    action = await router.plan("show me James Smith's income")
    print(f"Route: {action.route}")  # /landlords/james-smith-123/financials
    print(f"Confidence: {action.confidence}")  # 0.94

πŸ§ͺ Docker Development Environment

The included Docker setup provides:

  • PostgreSQL database with realistic sample data
  • Automatic schema setup with users, landlords, tenants, properties
  • pgAdmin interface for database management (http://localhost:8080)
  • Live code reloading for development
  • Mock LLM responses when no API key is provided

Sample data includes:

  • James Smith (landlord with $4,500 monthly income)
  • Sarah Johnson (landlord with $3,200 monthly income)
  • John Doe, Emily Davis, Michael Brown (tenants)
  • Real properties with addresses and lease agreements

βš™οΈ Configuration

Create a routes.json file:

{
  "domain": "property_management",
  "base_url": "https://myapp.com",
  "route_patterns": [
    {
      "pattern": "/{entity_type}/{entity_id}/{view_type}",
      "name": "entity_detail_view",
      "description": "View specific details for an entity",
      "intent_patterns": [
        "show {entity} {view_data}",
        "view {entity} {view_data}",
        "see {entity} {view_data}"
      ],
      "parameters": {
        "entity_type": {
          "type": "string",
          "description": "Type of entity (landlords, tenants, properties)",
          "examples": ["landlords", "tenants", "properties"]
        },
        "entity_id": {
          "type": "string", 
          "description": "Unique identifier for the entity"
        },
        "view_type": {
          "type": "string",
          "description": "Type of data to view",
          "examples": ["financials", "contact", "overview"]
        }
      }
    }
  ],
  "entities": {
    "person": {
      "table": "users",
      "search_fields": ["name", "email"],
      "display_field": "name"
    }
  },
  "database_schema": {
    "tables": {
      "users": {
        "columns": [
          {"name": "id", "type": "uuid"},
          {"name": "name", "type": "varchar"},
          {"name": "email", "type": "varchar"}
        ]
      },
      "landlords": {
        "columns": [
          {"name": "id", "type": "uuid"},
          {"name": "user_id", "type": "uuid"},
          {"name": "monthly_income", "type": "decimal"}
        ]
      }
    },
    "relationships": {
      "landlords.user_id": "users.id"
    }
  }
}

🎨 Example Queries

Once configured, your router understands queries like:

# Navigation
await router.plan("show me James Smith's monthly income")
# β†’ /landlords/james-smith-123/financials

await router.plan("view tenant contact info for John Doe") 
# β†’ /tenants/john-doe-456/contact

# CRUD operations
await router.plan("create new property")
# β†’ /properties/create

await router.plan("edit Sarah's information")
# β†’ /users/sarah-wilson-789/edit

# Listing and search
await router.plan("show all properties")
# β†’ /properties

await router.plan("search for properties in downtown")
# β†’ /properties/search?q=downtown

πŸ”§ Advanced Features

Custom LLM Providers

from fantastic_router_core.planning.intent_parser import LLMClient

class CustomLLMClient:
    async def analyze(self, prompt: str, temperature: float = 0.1):
        # Your custom LLM implementation
        return {"action_type": "NAVIGATE", "entities": ["James Smith"]}

router = FantasticRouter(
    llm_client=CustomLLMClient(),
    db_client=db_client,
    config=config
)

Database Adapters

from fantastic_router_core.retrieval.vector import DatabaseClient

class CustomDatabaseClient:
    async def search(self, query: str, tables: List[str], fields: List[str]):
        # Your custom database search implementation
        return [{"id": "123", "name": "James Smith"}]

RBAC Integration (work in progress)

action = await router.plan(
    "show sensitive financial data", 
    user_role="admin"  # Only admins can access certain routes
)

🀝 Contributing

We welcome contributions!

Development Setup

Quick Setup with Docker:

git clone https://github.com/yourusername/fantastic-router
cd fantastic-router
make setup          # Sets up everything
make test-real      # Run tests

Manual Setup:

git clone https://github.com/yourusername/fantastic-router
cd fantastic-router
pip install -e "packages/fantastic_router_core[dev]"
pytest

Useful Development Commands:

make shell          # Open development shell
make db-shell       # Access database directly
make logs           # View application logs
make clean          # Reset everything

πŸ“„ License

GNU General Public License v3 (GPLv3) - see LICENSE for details.

πŸ™‹β€β™‚οΈ Support


Made with ❀️ by developers who believe navigation should be intuitive.

About

An opensource LLM-powered intent router for your website!

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published