Skip to main content

Paperclip

Persistent memory for Paperclip AI agents using Hindsight.

Paperclip agents start every heartbeat cold — no memory of prior sessions, decisions, or patterns. The @vectorize-io/hindsight-paperclip package gives them long-term memory that persists across heartbeats and sessions.

Quick Start

npm install @vectorize-io/hindsight-paperclip
import { recall, retain, loadConfig } from '@vectorize-io/hindsight-paperclip'

const config = loadConfig() // reads HINDSIGHT_API_URL, HINDSIGHT_API_TOKEN

// Before the heartbeat — inject context from prior sessions
const memories = await recall({
companyId,
agentId,
query: `${task.title}\n${task.description}`,
}, config)

if (memories) {
systemPrompt = `Past context:\n${memories}\n\n${systemPrompt}`
}

// After the heartbeat — store what the agent did
await retain({
companyId,
agentId,
content: agentOutput,
documentId: runId,
}, config)

Get an API key at Hindsight Cloud.

How It Works

Paperclip Heartbeat


recall() ← Query Hindsight for prior context


Agent executes ← Prompt enriched with memories


retain() ← Store output for future heartbeats

Memory is isolated per company and agent by default (paperclip::{companyId}::{agentId}), matching Paperclip's multi-tenant model.

HTTP Adapter Integration

For agents running as HTTP webhook servers, use the Express middleware:

import express from 'express'
import { createMemoryMiddleware, loadConfig } from '@vectorize-io/hindsight-paperclip'
import type { HindsightRequest } from '@vectorize-io/hindsight-paperclip'

const app = express()
app.use(express.json())
app.use(createMemoryMiddleware(loadConfig()))

app.post('/heartbeat', async (req, res) => {
const { memories } = (req as HindsightRequest).hindsight
const { context } = req.body

const prompt = memories
? `Past context:\n${memories}\n\nCurrent task: ${context.taskDescription}`
: `Task: ${context.taskDescription}`

const output = await runYourAgent(prompt)
res.json({ output }) // output is auto-retained by middleware
})

The middleware reads agentId, companyId, runId, and context.taskDescription from Paperclip's HTTP adapter request body, then auto-retains the agent's output field after each response.

Process Adapter Integration

For agents running as scripts via Paperclip's Process adapter:

import { recall, retain, loadConfig } from '@vectorize-io/hindsight-paperclip'

const config = loadConfig()
const { PAPERCLIP_AGENT_ID, PAPERCLIP_COMPANY_ID, PAPERCLIP_RUN_ID } = process.env

const memories = await recall({
agentId: PAPERCLIP_AGENT_ID!,
companyId: PAPERCLIP_COMPANY_ID!,
query: process.env.TASK_DESCRIPTION ?? '',
}, config)

if (memories) {
console.log(`[Memory Context]\n${memories}`)
}

// ... agent executes ...

await retain({
agentId: PAPERCLIP_AGENT_ID!,
companyId: PAPERCLIP_COMPANY_ID!,
content: agentOutput,
documentId: PAPERCLIP_RUN_ID!,
}, config)

Bank ID Isolation

By default, each company+agent pair gets its own memory bank:

SettingBank ID format
Defaultpaperclip::{companyId}::{agentId}
Company-onlypaperclip::{companyId}
Agent-onlypaperclip::{agentId}
Custom prefix{prefix}::{companyId}::{agentId}
// Shared memory across all agents in a company
loadConfig({ bankGranularity: ['company'] })

// Agent's global memory across all companies
loadConfig({ bankGranularity: ['agent'] })

// Custom prefix
loadConfig({ bankIdPrefix: 'myapp' })

Configuration

OptionEnv VariableDefaultDescription
hindsightApiUrlHINDSIGHT_API_URLRequiredHindsight server URL
hindsightApiTokenHINDSIGHT_API_TOKENAPI token for Hindsight Cloud
bankGranularity['company', 'agent']Which IDs to include in the bank ID
bankIdPrefix'paperclip'Prefix for bank IDs
recallBudget'mid'Search depth: low, mid, or high
recallMaxTokens1024Max tokens in recalled memory block
retainContext'paperclip'Provenance label stored with memories
timeoutMs15000Request timeout in milliseconds

Skill File

A markdown skill file is included at src/skills/hindsight.md. Inject it into your agent's system prompt to give the agent direct access to Hindsight's REST API via curl for mid-task recall and retention.

Requirements

  • Node.js 20+ (uses native fetch, no external HTTP dependencies)
  • Hindsight server (self-hosted or Hindsight Cloud)