The Problem

The project addresses the need for fast, multilingual decision-making in applications like ticket routing, email classification, or structured data analysis. Traditional NLP approaches, which rely on text generation and parsing, are slow and prone to hallucinations—especially in low-latency environments. Laya solves this by operating as a non-autoregressive System 1 decision engine, evaluating typed questions in a single forward pass (33 ms per query) with reinforcement learning calibration.

What This Does

Laya is a Python library designed for high-speed, multilingual decision workflows. It supports three typed question formats (choice, score, noul) and routes requests to one of three pre-trained checkpoints based on language and context. The core functionality is implemented in laya/__init__.py, laya/agent.py, and laya/router.py.

The Router (defined in laya/router.py) is the primary entry point. It preloads checkpoints into memory and dispatches queries to the optimal model—either laya, laya-multilingual, or laya-typed-decisions—based on the input state. The models are fine-tuned with reinforcement learning against strictly proper scoring rules (RLCD), ensuring calibrated decisions.

The project includes benchmarks (in research/scripts/) comparing Laya to alternatives like TypeSafe Jev, demonstrating superior speed, accuracy, and calibration. The assets/ folder contains visualizations of these benchmarks.

How It Is Wired

Execution begins at setup.py, which defines the entry points. The key workflow is:

  1. Routing: The Router in laya/router.py evaluates the input state and dispatches to the appropriate checkpoint.
  2. Decision Engine: The selected checkpoint processes the query in a single forward pass, returning a decision without text generation.
  3. Output: Results are returned directly, avoiding parsing overhead.

Dependencies are declared in pyproject.toml, but there is no lockfile (pyproject.lock or similar), making builds non-reproducible. Tests are located in tests/, covering core functionality like test_router.py and test_decision_model.py.

The project uses GitHub Actions for CI/CD (.github/workflows/), with workflows for testing, security scanning, and releases.

How To Use It

  1. Installation: ``bash pip install laya ``
  1. Configuration: No additional config files are required beyond installation.
  1. Running It: ```python import laya from laya import Router

# Preload checkpoints for faster routing router = Router(preload=True)

# Define a state and questions state = {"from": "user@acme.com", "subject": "Duplicate charge", "body": "Hi, we were billed twice..."} questions = { "department": {"type": "choice", "instructions": "Which department should handle this?"} }

# Route and evaluate decisions = router.evaluate(state, questions) print(decisions)


## Real-World Use

Laya is useful in applications requiring fast, multilingual decision-making, such as:
- **Ticket Routing**: Classifying support tickets by department or priority.
- **Email Filtering**: Categorizing emails (e.g., spam, high-priority).
- **Structured Data Analysis**: Extracting decisions from JSON documents.

Example workflow:
```python
from laya import Router

# Initialize router (preload recommended for production)
router = Router(preload=True)

# Evaluate a ticket
ticket = {"title": "Login issue", "description": "Can't log in..."}
decisions = router.evaluate(ticket, {
    "department": {"type": "choice", "instructions": "Which team handles this?"}
})

Code Health & Issues

  • Low/Risk: Dependencies declared without a lockfile (pyproject.toml). This can lead to non-reproducible builds.
  • Low/Risk: No explicit .env or config.yaml for environment variables, though none appear required.

The Bottom Line

Laya is a specialized, high-performance decision engine for multilingual workflows. It excels in low-latency applications but has limited use cases outside of structured decision-making. The lack of a lockfile is a minor concern for reproducibility. Use it for fast, calibrated decisions in ticket routing, email classification, or similar tasks.