Skip to main content

Install

npm install agnostai

Integrate

import * as agnost from 'agnostai';

agnost.init('your-org-id');
Get your org ID from app.agnost.ai.

Track interactions

const interaction = agnost.begin({ userId: 'u-123', agentName: 'my-agent', input: '...' });
// ... your AI call ...
interaction.end('...');
Latency is auto-calculated. For errors:
interaction.end('Error: timeout', false);

Group into conversations

const conversationId = crypto.randomUUID();

const t1 = agnost.begin({ userId: 'u-123', agentName: 'my-agent', input: 'Hello', conversationId });
t1.end('Hi!');

const t2 = agnost.begin({ userId: 'u-123', agentName: 'my-agent', input: 'Follow-up', conversationId });
t2.end('Sure!');

Identify users

agnost.identify('u-123', { name: 'Alice', email: 'alice@example.com', plan: 'pro' });

Custom properties

const interaction = agnost.begin({ userId: 'u-123', agentName: 'my-agent', input: '...' });
interaction.setProperties({ model: 'gpt-4', tokens: '150' });
interaction.end('...');

Retrieve an interaction by ID

Useful when you need to complete an interaction from a different function or callback:
agnost.begin({ userId: 'u-123', agentName: 'my-agent', input: '...', interactionId: 'req-1' });

// elsewhere...
const interaction = agnost.getInteraction('req-1');
interaction?.end('...');

Configuration

agnost.init('your-org-id', { endpoint: 'https://api.agnost.ai', debug: true });
OptionTypeDefaultDescription
endpointstringhttps://api.agnost.aiAPI endpoint
debugbooleanfalseEnable debug logging

Cleanup

await agnost.shutdown(); // flushes and cleans up