$ account CultivateLabs
Raif (Ruby AI Framework) is a Rails engine/gem that provides a comprehensive, opinionated framework for integrating large language models (LLMs) into Rails applications. It abstracts over multiple LLM providers (OpenAI, Anthropic, Google Gemini, AWS Bedrock, xAI, OpenRouter) with a unified interface for chat completions, streaming, tool calling, structured outputs, and batch inference. The system persists every LLM interaction as `ModelCompletion` records with full token/cost accounting, supports conversation management with tool call validation and retry loops, and provides a task system for running parameterized LLM prompts with caching and temperature control. A key differentiator is its built-in evaluation framework (`Raif::Evals`) that enables dataset-driven evals with LLM-as-a-judge, statistical comparison (bootstrap CI95, sign test, Fisher exact), and regression gating for CI/CD pipelines. Architecturally, Raif is a mountable Rails engine with its own models, migrations, controllers, background jobs, and admin UI. It uses Single Table Inheritance extensively for extensibility (tasks, agents, model completion batches, LLM judges). The system includes a declarative model manifest DSL for defining model capabilities, pricing, and lifecycle, a data retention/archiving subsystem with pluggable storage adapters, and a Prompt Studio for A/B testing prompts across models. The eval framework supports concurrent execution via forked worker processes with per-worker databases, live HTML reports, and resumable run logs. External dependencies include Faraday for HTTP, ActiveJob for background processing, and provider-specific SDKs (AWS SDK for Bedrock). Key entry points include `Raif::Llm#chat` for direct LLM calls, `Raif::Task#run` for task execution, `Raif::Conversation` for multi-turn conversations, `Raif::Agents::NativeToolCallingAgent` for ReAct-style agent loops, and the CLI (`raif evals`, `raif evals:compare`, `raif evals:report`) for running evaluations. The admin web interface provides full CRUD for tasks, conversations, agents, model completions, and batch inference jobs. Background jobs handle archive/cull operations, batch polling, and cost event repair. The system is designed for production use with features like advisory locks for concurrency control, transient retry with exponential backoff, and configurable data retention policies. While primarily an application framework, Raif has strong data/research characteristics through its evaluation framework, model manifest with pricing/capability tracking, and smoke-testing infrastructure for live API verification. The eval framework produces detailed metrics (pass rates, scores, token usage, costs, confidence intervals) and supports comparison reports with regression gates, making it suitable for systematic LLM evaluation in CI/CD workflows. The model manifest serves as a machine-readable catalog of supported models with lifecycle management, enabling automated capability detection and cost estimation.