Skip to content

Repository files navigation

ActiveHarness

ActiveHarness

Gem Version

⚠️ Work in progress. The API is under active development and may change between versions without notice.

📛 Naming note. As of v0.3.0, ActiveHarness::Agent was renamed to ActiveHarness::Request — it's a single resilient LLM call (model chain, fallback, retry, hooks), not an autonomous entity, and Request describes that more accurately. The Agent name is reserved for a future, separate abstraction — something that uses a model to decide and take actions — which doesn't exist in this gem yet.

Running a single LLM call is easy. Running a reliable, observable, cost-controlled AI system is not.

ActiveHarness is a Ruby framework for building production-grade LLM pipelines — with deep observability, consensus-based decisions, automatic fallbacks, and real-time cost and timing control. Made for Rails, works in plain Ruby too.

ActiveHarness gem gives you the scaffolding to build multi-step pipelines where every request is under full control: its inputs are directed, its outputs are observed, its errors are retried, and its cost is tracked. You define the logic; ActiveHarness handles the infrastructure.

What is a "Harness"?

A harness in software is scaffolding that keeps a component under control — directing its inputs, observing its outputs, and enforcing rules around it. ActiveHarness does exactly that for LLM requests.

Build AI-Based Pipelines!

Build multi-step, trackable, cost-effective, and reliable AI flows with a clean, Rails-native DSL.

Pipeline Flow

Build Nested AI Pipelines!

Group related steps into reusable sub-pipelines, and compose complex workflows from smaller ones. Each pipeline is just another step, with its own stop conditions, context forwarding, and execution time tracking.

Nested Pipelines

Compose Hybrid Pipelines!

Orchestrate deterministic and AI steps together.

Image

Control the Cost of Your AI Calls!

With ActiveHarness you can track time, tokens, and dollars for every request call, pipeline step, and tribunal.

Cost Control
Cost in Application Provider's Cost
Image Image

Use Consensus-Based Decisions!

Use Tribunals to run multiple requests in parallel and make Verdicts based on their agreement — improving reliability and reducing biases and hallucinations.

Tribunal Diagram

Tribunals

Provide Event Tracing & Observability!

Use power of event hooks to log and trace every step of your AI flows, from individual request calls to multi-step pipelines and parallel tribunals.

Event Tracing Architecture Grafana Dashboard
Event Tracing Grafana Metrics

Backend Agnostic — Built on OpenTelemetry, ready for any collector (Jaeger, Datadog, Honeycomb, or custom).

Use Memory to make your requests stateful!

Store conversation history in JSON, SQLite and PostgreSQL. Inject memory into prompts to make requests that remember past interactions.

Memory

Visualize Models' Cost and Type

Pricing

Add Streaming (SSE)!

Rails App Console
Streaming Streaming

Evaluate & Moderate Content with Jev!

Not every request needs a chat model. Use provider: :vercel to reach Jev, TypeSafe AI's "System One" evaluation model, via Vercel AI Gateway — ask typed score/choice/noul questions in one call and get back typed, probabilistic answers instead of free text. A natural fit for classification, routing, and content moderation.

Jev Evaluation Demo

See docs/JEV.md for the full request/response schema and use-case examples (ticket triage, refund detection, tool-call risk gating, content moderation).

Key Capabilities

Capability What it means
Multi-step Pipelines Chain requests sequentially, with per-step stop conditions and context forwarding
Tribunal Consensus Run multiple requests in parallel and accept the result only if they agree (unanimous, majority, or custom)
Automatic Fallbacks If a model fails, the next one in the chain takes over — zero extra code
Retry Policy Exponential backoff per model, globally configurable or per-request
Full Observability Lifecycle hooks on every request event: before_call, after_call, retry, failure — log, stream, or act
Real-time Streaming SSE-ready token streaming from any request into your Rails response
Execution Time Tracking Per-request and per-pipeline timing built in
Token  Cost Tracking Know exactly what each call cost in tokens and dollars
Rails-native DSL Clean file structure, Railtie integration, generator support
Event Tracing OpenTelemetry integration for distributed tracing of requests, tribunals, and pipelines

File Structure

File structure for Ruby and Ruby on Rails applications:

Place all of your AI-related code in app/ai to keep it organized and separate from your core application logic. You can further organize it into subdirectories for prompts, requests, tribunals, pipelines, and memory.

app/
├── models/
├── controllers/
├── views/
└── ai/
    ├── prompts/      # system prompt classes
    ├── requests/       # request classes
    ├── tribunals/    # parallel verdict panels
    ├── pipelines/    # multi-step pipelines
    └── memory/       # custom memory classes

Prompt Documentation

Request Documentation

Pipeline Documentation

Nested Pipelines Documentation

Tribunal Documentation

Memory Documentation

Installation and Configuration

Tracing and Observability

License

MIT © the-teacher

Packages

Contributors

Languages