org.llm4s.agent.encryption

Members list

Type members

Classlikes

@Experimental
final class EncryptingCheckpointer extends Checkpointer

A Checkpointer that encrypts what inner stores, with keys from keys (#2449; spec docs/superpowers/specs/2026-11-22-checkpoint-encryption-design.md). It works over any store - it is CheckpointerContract that checks it - so give it to every runtime and worker in place of the store, and wrap the store's run queue with EncryptingRunQueue over the same keys:

A Checkpointer that encrypts what inner stores, with keys from keys (#2449; spec docs/superpowers/specs/2026-11-22-checkpoint-encryption-design.md). It works over any store - it is CheckpointerContract that checks it - so give it to every runtime and worker in place of the store, and wrap the store's run queue with EncryptingRunQueue over the same keys:

for
 store <- CheckpointerConfigLoader.open()            // llm4s.agent.checkpointer
 queue <- store.runQueue
 key   <- EncryptionKey.fromBase64(KeyId("2026-11"), keyFromYourSecretStore)
 keys         = StaticKeySource(key)
 checkpointer = MeteredCheckpointer(EncryptingCheckpointer(store.checkpointer, keys), metrics)
 agent  <- Agent.builder("assistant", client).withRuntime(new GraphRuntime(checkpointer)).build()
 worker <- AgentWorker(EncryptingRunQueue(queue, keys), checkpointer, Seq(QueuedAgent(agent)), metrics = metrics)
yield worker

'''What is encrypted''' - every value the application's codecs wrote: a checkpoint's state values, its pending tasks' inputs and replayed routes, and its parked questions; a pending write's updates, route payloads and question; a custom event's payload; and an effect record's outcome and presumed outcome.

'''What stays in plain''', because the store orders, fences, lists or prunes by it: thread, run, checkpoint, task, node, state-key, interrupt and tenant ids; statuses, outcomes and timestamps; the graph's id, version, fingerprint and shape; fencing tokens and sequence numbers; thread metadata; trace contexts; lineages, effect keys and the digests recorded beside a value (an unkeyed digest lets someone who can guess a value confirm the guess); the built-in events, which hold ids, counts, token usage and failure messages; and the size of every encrypted value.

Each value is sealed on its own with AES-256-GCM under a subkey of its thread, bound to its key id, its thread and its place - for a checkpoint's values, the tenant and checkpoint id too - so one moved to another thread, tenant, checkpoint or field does not open. A read that cannot open a value is a Left (EncryptionError): it never returns the stored value in its place. A thread's key is its tenant's (EncryptionKeySource.current), taken from the commit's checkpoint, or for a commit with none from the thread's latest one.

Stack MeteredCheckpointer outside it, as above: it then times commits with their encryption, and reads the child-task events it counts before they are sealed.

Attributes

Companion
object
Source
EncryptingCheckpointer.scala
Supertypes
trait Checkpointer
class Object
trait Matchable
class Any
@Experimental

Attributes

Companion
class
Source
EncryptingCheckpointer.scala
Supertypes
class Object
trait Matchable
class Any
Self type
@Experimental
final class EncryptingRunQueue extends RunQueue

A RunQueue that encrypts the inputs inner stores, with keys from keys (#2449): the companion of EncryptingCheckpointer for a store's queue, which is a separate SPI and so is not covered by wrapping the checkpointer. Give it to every RunSubmitter and AgentWorker in place of the store's queue.

A RunQueue that encrypts the inputs inner stores, with keys from keys (#2449): the companion of EncryptingCheckpointer for a store's queue, which is a separate SPI and so is not covered by wrapping the checkpointer. Give it to every RunSubmitter and AgentWorker in place of the store's queue.

'''What is encrypted''': a Start input and each answer of a Resume, under the key of the submission's tenant, bound to the tenant, the thread, the agent and - for an answer - its interrupt. The store issues an entry's id as it inserts it, so an input is not bound to its entry: someone who can write to the database can exchange the inputs of two entries of one thread, tenant and agent, and nothing else.

'''What stays in plain''': everything the queue orders, leases, scopes and reports by - entry, thread, agent, tenant and run ids, the submission key, the policy, attempts and lease holders, timestamps, trace contexts, an input's kind and its interrupt ids - and an entry's outcome, with the failure message or cancel note it carries: close and cancel name an entry by its lease or id alone, without the tenant a key is chosen by.

A retried submission under a SubmissionKey still gets the first one's ticket. The store compares what it holds, and two encryptions of one input differ, so it reports the key as reused; this queue then reads that entry, opens it and compares the submissions itself.

An entry whose input cannot be opened fails the call that read it (EncryptionError) - after inner has acted: a take has leased it, a cancel has cancelled it. Such an entry stays at the head of its thread's queue, leased again as each lease expires, until its key is supplied or the entry is cancelled.

Attributes

Companion
object
Source
EncryptingRunQueue.scala
Supertypes
trait RunQueue
class Object
trait Matchable
class Any
@Experimental

Attributes

Companion
class
Source
EncryptingRunQueue.scala
Supertypes
class Object
trait Matchable
class Any
Self type
@Experimental
sealed trait EncryptionError extends LLMError

Why a payload of the checkpoint store could not be encrypted or read (#2449). Every case is non-recoverable - the same call fails the same way until the keys or the stored row change - and none carries key material, plaintext or ciphertext: only which thread, which field and which key id.

Why a payload of the checkpoint store could not be encrypted or read (#2449). Every case is non-recoverable - the same call fails the same way until the keys or the stored row change - and none carries key material, plaintext or ciphertext: only which thread, which field and which key id.

Attributes

Companion
object
Source
EncryptionError.scala
Supertypes
trait LLMError
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
@Experimental

Attributes

Companion
trait
Source
EncryptionError.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
@Experimental
final class EncryptionKey

A 256-bit AES key and its KeyId (#2449). The key material is held privately: nothing reads it back, toString prints the id and ***, and no error names it. Two keys are equal only if they are the same instance.

A 256-bit AES key and its KeyId (#2449). The key material is held privately: nothing reads it back, toString prints the id and ***, and no error names it. Two keys are equal only if they are the same instance.

A key is never used directly. Each thread's payloads are encrypted under a subkey derived from it and the thread's id (HKDF-Expand, RFC 5869, with HMAC-SHA-256), so the bound on random nonces under one AES-GCM key applies per thread, not per store.

Attributes

Companion
object
Source
EncryptionKey.scala
Supertypes
class Object
trait Matchable
class Any
@Experimental
object EncryptionKey

Attributes

Companion
class
Source
EncryptionKey.scala
Supertypes
class Object
trait Matchable
class Any
Self type
@Experimental

Where EncryptingCheckpointer and EncryptingRunQueue get their keys (#2449): the application's, never the store's. Implement it over a KMS or a secret manager; StaticKeySource holds keys the application loaded itself.

Where EncryptingCheckpointer and EncryptingRunQueue get their keys (#2449): the application's, never the store's. Implement it over a KMS or a secret manager; StaticKeySource holds keys the application loaded itself.

Both methods are called on the store's hot paths - current once per commit or submission that writes a payload, key once per key id per read - so an implementation over a remote service caches what it fetched. Rotation is current answering a key with a new KeyId while key still answers the old ones: every ciphertext names the key that wrote it, new writes use the new key, and old rows stay readable until they are pruned.

Implementations must be safe to call from several threads, and must never put key material in an error.

Attributes

Source
EncryptionKeySource.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
@Experimental
final case class EncryptionSettings

How EncryptingCheckpointer and EncryptingRunQueue behave beyond their keys (#2449).

How EncryptingCheckpointer and EncryptingRunQueue behave beyond their keys (#2449).

Value parameters

plaintextReads

whether a payload stored in plain is read as it is. Off by default: an unencrypted payload fails the read (EncryptionError.NotEncrypted), so nobody with write access to the database can swap a ciphertext for a plaintext of their own. Turn it on to switch encryption on over a store that already holds threads - their rows are read in plain, and everything written from then on is encrypted - and off again once retention has pruned the old rows. Writes are always encrypted, whatever this is.

Attributes

Companion
object
Source
EncryptionSettings.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
@Experimental

Attributes

Companion
class
Source
EncryptionSettings.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
@Experimental
object KeyId

Attributes

Source
EncryptionKey.scala
Supertypes
class Object
trait Matchable
class Any
Self type
KeyId.type
@Experimental
final class StaticKeySource extends EncryptionKeySource

Keys held in memory (#2449): one for every thread, or one per tenant, with retired keys kept for reading.

Keys held in memory (#2449): one for every thread, or one per tenant, with retired keys kept for reading.

for key <- EncryptionKey.fromBase64(KeyId("2026-11"), fromSecretStore)
yield StaticKeySource(key)                  // one key for every thread
 .withTenantKey(TenantId("acme"), acmeKey) // acme's own
 .withRetiredKey(lastYearsKey)             // still read, never written with

Every key needs an id of its own: adding a second key under an id already held throws IllegalArgumentException (the same key again is accepted). toString lists key ids only.

Attributes

Companion
object
Source
EncryptionKeySource.scala
Supertypes
class Object
trait Matchable
class Any
@Experimental

Attributes

Companion
class
Source
EncryptionKeySource.scala
Supertypes
class Object
trait Matchable
class Any
Self type

Types

opaque type KeyId

The name of an EncryptionKey, stored in plain with every ciphertext the key wrote so the reader knows which key opens it (#2449): 1 to 64 of A-Z a-z 0-9 _ -. It names a key and is never derived from one.

The name of an EncryptionKey, stored in plain with every ciphertext the key wrote so the reader knows which key opens it (#2449): 1 to 64 of A-Z a-z 0-9 _ -. It names a key and is never derived from one.

Attributes

Source
EncryptionKey.scala