AgentSea

Package

@lov3kaizen/agentsea-prompts

A self-hosted prompt registry.

v1.2.1On npm

01Install

Install from npm into your project.

BASH
pnpm add @lov3kaizen/agentsea-prompts

02Example

TS
import { PromptRegistry, FileStorage } from '@lov3kaizen/agentsea-prompts';

const registry = new PromptRegistry({
  storage: new FileStorage({ path: './prompts' }),
});
await registry.initialize();

await registry.create({
  name: 'customer-support',
  template: 'You are a helpful customer support agent for {{company_name}}.',
  variables: { company_name: { type: 'string', required: true } },
});

const rendered = await registry.render('customer-support', { company_name: 'Acme Corp' });
console.log(rendered.content);

03Key API

PromptRegistry({ storage, defaultEnvironment, environments })
Main class. Methods: create, get, update, render, history, diff, rollback, branch, merge, promote, createABTest.
registry.promote(name, { from, to, version, approver?, message })
Moves a version between environments. approver is required for a protected environment.
FileStorage({ path, format }) and BufferStorage()
File-based storage (format 'json' is shown) and in-memory storage for tests.
PromptClient({ registryUrl, apiKey, environment, cache })
Imported from '@lov3kaizen/agentsea-prompts/client'. Loads prompts at runtime with caching.
PromptProvider({ registry, environment, autoRefresh }).dynamic(name, vars)
Supplies a prompt to an AgentSea Agent as systemPrompt. dynamic() returns an async function, not a string.

04Caveats

  • Only ESM is supported. Requires Node.js 20 or later.
  • File and in-memory storage are implemented. PostgreSQL is marked coming soon. The SQLite and S3 packages are listed as optional dependencies, but no adapter for them is exported.
  • @lov3kaizen/agentsea-core is an optional peer dependency. Install it when you use the AgentSea integration.
  • autoRefresh clears the cached prompt when the registry emits prompt:updated for the same environment. The next call to the dynamic prompt reads the new version.

05Version control

Each update creates a new version. You can read the history, compare two versions, roll back, and work on a branch that merges back into the main line.

TS
await registry.update('customer-support', {
  template: updatedTemplate,
  message: 'Added discount guideline for retention',
});

const diff = await registry.diff('customer-support', { from: 'v1', to: 'v2' });

await registry.rollback('customer-support', { to: 'v1', reason: 'Reverted after review' });

await registry.branch('customer-support', { name: 'experiment/shorter-prompt', from: 'v2' });
await registry.merge('customer-support', { from: 'experiment/shorter-prompt', strategy: 'squash' });

06Environments

Define the environments when you create the registry. Promote a version from one environment to the next. A protected environment needs an approver on promotion.

TS
const registry = new PromptRegistry({
  storage,
  environments: [
    { name: 'development', label: 'Dev', order: 1 },
    { name: 'staging', label: 'Staging', order: 2 },
    { name: 'production', label: 'Prod', protected: true, order: 3 },
  ],
});

await registry.promote('customer-support', {
  from: 'staging',
  to: 'production',
  version: 'v3',
  approver: 'lead-engineer',
  message: 'Approved after QA sign-off',
});

const prodPrompt = await registry.get('customer-support', { environment: 'production' });

07A/B testing

Create a test with two or more prompt versions as variants. Each user is assigned a variant, and you record metrics against it. getResults reports the sample count, significance, the winner and the p-value.

TS
import { ABTest } from '@lov3kaizen/agentsea-prompts';

const test = await registry.createABTest({
  name: 'concise-vs-detailed',
  prompt: 'customer-support',
  variants: [
    { name: 'control', version: 'v1', weight: 0.5 },
    { name: 'treatment', version: 'v2', weight: 0.5 },
  ],
  metrics: ['user_satisfaction', 'resolution_time'],
  confidenceLevel: 0.95,
});

const variant = await test.getVariant({ userId: 'user-123' });
await test.recordMetric('control', 'user_satisfaction', 4.5, { userId: 'user-123' });

const results = await test.getResults();
console.log(results.isSignificant, results.winner, results.pValue);

08SDK client

Import PromptClient from the client subpath to load prompts at runtime from a registry server. It caches results and emits prompt:updated and prompt:loaded events. Set pollInterval to check for changes.

TS
import { PromptClient } from '@lov3kaizen/agentsea-prompts/client';

const client = new PromptClient({
  registryUrl: 'https://prompts.example.com',
  apiKey: process.env.PROMPT_API_KEY,
  environment: 'production',
  cache: { enabled: true, ttl: 300 },
});

client.on('prompt:updated', ({ name, version }) => {
  console.log(`Prompt ${name} updated to ${version}`);
});

const result = await client.render('customer-support', { company_name: 'Acme Corp' });
  • The client also accepts prompts registered locally with client.register, which needs no server.