Skip to content

v0.2.0: queued retains and Hindsight::fake()

Choose a tag to compare

@skybleak333 skybleak333 released this 06 Nov 10:37
· 15 commits to main since this release

Agent memory that waits out an outage of the Hindsight API, and memory you can test without a server.

// Store each exchange from a queue worker, with retries that never store it twice.
Memory::bank("user-{$this->user->id}")->queue();

// In tests
Hindsight::fake(['user-1' => ['Alice is on the Pro plan']]);
Hindsight::assertRetained('user-1', fn (string $content) => str_contains($content, 'renews'));

Tested in CI on PHP 8.2–8.5, Laravel 12 and 13, Laravel AI SDK 1.0 and 1.3, and real Hindsight 1.1.0 and 1.2.0 servers.

Added

  • Hindsight::fake() and Fedoseev\Hindsight\Testing\HindsightFake: an in-memory server for tests, with assertRetained(), assertNotRetained(), assertNothingRetained(), assertRecalled(), assertNotRecalled() and assertReflected(). It follows the server where tests depend on it: a bank nobody wrote to answers 404, tag filters select the same memories, a retain with a document ID replaces the document, an async retain repeated with the same operation ID stores nothing new, and invalid operation IDs, timestamps, tags, metadata values and update modes are rejected with the server's status. unavailable() simulates an outage, respondTo() stubs other endpoints.
  • RetainMemory job and Memory::queue(): store memories from a queue worker, retried with backoff while the Hindsight API is unavailable (six attempts over about 36 minutes by default; earlier attempts log a warning, only a failure on the last attempt is reported). Every attempt sends the operation ID the job got when it was dispatched, so a retry never stores a memory twice, and the dispatch time as the memory's timestamp. Errors a retry cannot fix fail the job at once and are reported.
  • queue section in config/hindsight.php: connection, queue, tries, backoff and payload encryption.
  • Bank aliases: listBankAliases(), addBankAlias(), setPrimaryBankAlias() and removeBankAlias(), on the client and the facade.
  • retryOperation() to queue a failed or cancelled operation again.
  • CI also runs the integration suite against Hindsight 1.2.0, and compares the fake with real 1.1.0 and 1.2.0 servers.

Changed

  • Hindsight is no longer final, so HindsightFake can stand in for it. Other subclasses are not supported.