agentlog-sdk
TypeScript client for agentlog - a local-first decision log daemon for agentic workflows.
Installation
npm install agentlog-sdk
Quickstart
import { AgentlogClient } from "agentlog-sdk";
const client = new AgentlogClient();
await client.write({ type: "decision", title: "Use PostgreSQL for persistence" });
const entries = await client.query({ text: "database" });
Requirements
- Node.js 18+
- A running
agentlogd daemon (see the main project README)
Usage
Writing entries
import { AgentlogClient } from "agentlog-sdk";
const client = new AgentlogClient();
await client.write({
type: "decision",
title: "Use Redis for caching",
body: "Redis provides sub-millisecond reads and built-in TTL support.",
tags: ["infrastructure", "caching"],
files: ["config/redis.yaml"],
});
await client.write({ type: "assumption", title: "All users have Node 18+" });
await client.write({ type: "question", title: "Should we use async or sync HTTP client?" });
Searching entries
const results = await client.query({ text: "database migration" });
const filtered = await client.query({ text: "caching", type: "decision", limit: 5 });
Listing entries
const entries = await client.log({ type: "decision" });
const sessionEntries = await client.log({ session: "your-session-id" });
const tagEntries = await client.log({ tag: "infrastructure" });
const recentEntries = await client.log({ since: "1h" });
Getting context for prompts
const context = await client.context({ files: ["internal/auth/jwt.go"] });
console.log(context);
const topicContext = await client.context({ topic: "authentication" });
const combined = await client.context({
files: ["internal/auth/jwt.go", "config/auth.yaml"],
topic: "session tokens",
limit: 5,
});
Configuration
The SDK looks for the daemon socket at ~/.agentlog/agentlogd.sock by default. Override this with:
- The
AGENTLOG_DIR environment variable
- The
agentlogDir constructor option
- The
socketPath constructor option (takes precedence)
const client = new AgentlogClient({ agentlogDir: "/custom/path" });
const client2 = new AgentlogClient({ socketPath: "/tmp/agentlogd.sock" });
Error handling
import {
AgentlogClient,
AgentlogError,
ConnectionError,
DaemonNotRunningError,
} from "agentlog-sdk";
const client = new AgentlogClient();
try {
await client.write({ type: "decision", title: "Test entry" });
} catch (err) {
if (err instanceof DaemonNotRunningError) {
console.log("Start the daemon first: agentlog start");
} else if (err instanceof ConnectionError) {
console.log(`Connection failed: ${err.message}`);
} else if (err instanceof AgentlogError) {
console.log(`Unexpected error: ${err.message}`);
}
}
Development
npm install
npx tsc
npx vitest run
npx vitest run tests/client.test.ts