Documentation

Core Concepts

Janus is a durable agent task broker. It sits between agents and reliably delivers tasks with governance, routing, and observability.

📡
Producer
Agent
Janus
Broker
🤖
Consumer
Agent
🗄️
PostgreSQL + NATS
Durable Store

Architecture Overview

Janus is layered into four planes. External clients enter through protocol gateways; stateless core services own the task lifecycle, governance, and background workers; all durable state is externalized. Every layer scales independently.

The ingress plane only adapts protocols. Core services own state machines and governance. PostgreSQL is the source of truth; NATS carries deliveries and events; Redis holds only heartbeats and rate counters.

The ingress plane does only protocol adaptation and authentication — it holds no business logic. The core services own the task state machine, policy enforcement, budget accounting, and audit; they are stateless and scale horizontally. Background workers (outbox publisher, event projector, lease scanner, heartbeat sweep) run independently and coordinate through database leases and idempotency keys, so multiple replicas never double-deliver.

PostgreSQL is the source of truth for task state, the transactional outbox, budgets, and audit projections. NATS JetStream carries task deliveries and domain events through durable streams and per-mailbox consumers. Redis holds only agent heartbeats and short-window rate counters — never durable facts.

Business services never write to the mailbox directly. Task enqueue always goes through the transactional outbox, so a crash between accepted and queued never loses a task.

Task

The fundamental unit of work. A task carries an opaque payload (the envelope) from a source agent to a target consumer. Every task has a unique ID, a tenant scope, and a lifecycle state:

pending → claimed → in_progress → completed
                                        → failed
                                        → nacked → pending (retry)
                                                  → dlq

Mailbox

A named queue where tasks are delivered. Agents pull tasks from a mailbox they own. Mailboxes are durable — if an agent crashes, tasks remain until the agent comes back and pulls them.

Key properties:

Lease

When an agent pulls a task, it receives a time-bound lease. The lease prevents other agents from claiming the same task. If the agent crashes without ACKing:

Envelope

The payload wrapper. Contains:

Routing & Capability Resolution

Janus routes every task to the right agent through five target types:

Governance

Every task dispatch passes through policy and budget checks:

Protocol Gateways

Janus speaks multiple agent communication protocols natively:

Durability Model

Tasks are dual-written to PostgreSQL (source of truth) and NATS JetStream (fast delivery). If the broker process crashes mid-flight:

Tenant Isolation

Every task, mailbox, and artifact is scoped to a tenant. Cross-tenant access is automatically denied. All audit events are tagged with tenant ID.

Janus uses dual-write persistence (PG + NATS) for durability. The broker survives agent crashes, network partitions, and its own restarts without losing tasks.