Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.xhipai.com/llms.txt

Use this file to discover all available pages before exploring further.

In-Memory Storage

InMemoryStorage is the simplest storage driver. It keeps all data in a JavaScript Map—no external dependencies, no disk I/O. Data is lost when the process restarts. Use it for development, testing, or ephemeral workloads.

When to Use

Development

Fast iteration. No database setup required.

Testing

Isolated tests. No shared state between runs.

Demos

Quick prototypes. No infrastructure needed.

Not for Production

Data is lost on restart. Use Sqlite, Postgres, or MongoDB for persistence.

Installation

No additional packages required. InMemoryStorage is included in @agentium/core.

Usage

import { InMemoryStorage } from "@agentium/core";

const storage = new InMemoryStorage();

// No initialize() needed—ready to use immediately
await storage.set("namespace", "key", { foo: "bar" });
const value = await storage.get<{ foo: string }>("namespace", "key");
console.log(value); // { foo: "bar" }

const items = await storage.list("namespace", "k");
console.log(items); // [{ key: "key", value: { foo: "bar" } }]

await storage.delete("namespace", "key");
await storage.close();

With Agent

When you don’t provide a storage option, Agentium defaults to InMemoryStorage:
import { Agent, openai } from "@agentium/core";

// Explicit (same as default)
const agent = new Agent({
  name: "Assistant",
  model: openai("gpt-4o"),
  storage: new InMemoryStorage(),
});

// Implicit—InMemoryStorage is used automatically
const agent2 = new Agent({
  name: "Assistant",
  model: openai("gpt-4o"),
});

With Memory

import { Agent, Memory, InMemoryStorage, openai } from "@agentium/core";

const storage = new InMemoryStorage();
const memory = new Memory({
  storage,
  maxShortTermMessages: 50,
  enableLongTerm: false,
});

const agent = new Agent({
  name: "Assistant",
  model: openai("gpt-4o"),
  memory,
});

// Session data lives in memory until process exits
await agent.run("Hello!", { sessionId: "user-123" });

Limitations

LimitationDescription
No persistenceAll data is lost when the Node.js process exits.
Single processNot shared across multiple server instances.
Memory boundLarge datasets consume RAM.
No backupNo built-in snapshot or export.

API Reference

MethodSignatureDescription
getget<T>(namespace, key) => Promise<T | null>Get value by key.
setset<T>(namespace, key, value) => Promise<void>Store value (JSON-serialized).
deletedelete(namespace, key) => Promise<void>Remove key.
listlist<T>(namespace, prefix?) => Promise<Array<{key, value}>>List keys, optionally with prefix.
closeclose() => Promise<void>Clears the in-memory store.