Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

TypeScript SDK

The official TypeScript client for LocusGraph — store events, retrieve knowledge, and generate insights from your wisdom graph.

Installation

npm install @locusgraph/client

Configuration

import { LocusGraphClient } from '@locusgraph/client';
 
const client = new LocusGraphClient({
  serverUrl: 'https://api.locusgraph.com',  // optional, default
  agentSecret: 'your-agent-secret',
  graphId: 'default',  // optional default graph
});

Set LOCUSGRAPH_SERVER_URL and LOCUSGRAPH_AGENT_SECRET as environment variables to avoid hardcoding credentials. The client reads these automatically when no explicit values are provided.

Store Event

Use storeEvent to add knowledge to your wisdom graph. Each event captures a fact, action, decision, or observation.

const response = await client.storeEvent({
  graph_id: 'default',
  event_kind: 'fact',
  source: 'onboarding-flow',
  context_id: 'user-preferences',
  payload: 'User prefers dark mode and weekly email digests.',
  reinforces: ['ctx-abc123'],
  extends: [],
  contradicts: [],
  related_to: ['ctx-def456'],
  timestamp: '2025-01-15T10:30:00Z',
});
 
// Response
// {
//   eventId: 'evt-789',
//   contextId: 'user-preferences',
//   status: 'stored'
// }
FieldRequiredDescription
graph_idYesTarget graph identifier
event_kindYesEvent type: fact, action, decision, observation, feedback
payloadYesThe knowledge content
sourceNoOrigin of the event
context_idNoGroup events under a context
reinforcesNoArray of context IDs this event reinforces
extendsNoArray of context IDs this event extends
contradictsNoArray of context IDs this event contradicts
related_toNoArray of related context IDs
timestampNoISO 8601 timestamp string

Retrieve Knowledge

Use retrieveMemories to run semantic search across your wisdom graph.

const result = await client.retrieveMemories({
  graphId: 'default',
  query: 'What are the user preferences for notifications?',
  limit: 5,
  contextIds: ['user-preferences'],
  contextTypes: ['fact', 'decision'],
});
 
// Response
// {
//   memories: [
//     {
//       contextId: 'user-preferences',
//       content: 'User prefers weekly email digests.',
//       score: 0.92,
//       contextType: 'fact',
//       timestamp: '2025-01-15T10:30:00Z'
//     }
//   ]
// }
FieldRequiredDescription
graphIdNoUses default from config if omitted
queryYesNatural language search query
limitNoMax results to return
contextIdsNoFilter by specific context IDs
contextTypesNoFilter by context types

Get Context

Fetch a single context by its ID. Throws Error('Context not found') on 404.

try {
  const context = await client.getContext({
    context_id: 'user-preferences',
    graph_id: 'default',
  });
 
  // Response
  // {
  //   contextId: 'user-preferences',
  //   contextType: 'fact',
  //   content: 'User prefers dark mode and weekly email digests.',
  //   createdAt: '2025-01-15T10:30:00Z',
  //   updatedAt: '2025-01-15T10:30:00Z'
  // }
} catch (err) {
  console.error(err.message); // 'Context not found'
}

List Contexts

Browse context types, list contexts by type, or search by name.

// List all context types
const types = await client.listContexts({ graph_id: 'default' });
 
// List contexts by type
const facts = await client.listContexts({
  graph_id: 'default',
  context_type: 'fact',
});
 
// Search contexts by name
const results = await client.listContexts({
  graph_id: 'default',
  query: 'preferences',
});

Generate Insights

Use generateInsights to reason over your wisdom graph and produce synthesized answers.

const insight = await client.generateInsights({
  graphId: 'default',
  task: 'Summarize this user preferences and suggest personalization strategies.',
  locusQuery: 'user preferences and settings',
  limit: 10,
  contextIds: ['user-preferences'],
  contextTypes: ['fact', 'decision'],
});
 
// Response
// {
//   insight: 'Based on stored knowledge, the user prefers dark mode...',
//   sources: ['ctx-abc123', 'ctx-def456'],
//   confidence: 0.89
// }
FieldRequiredDescription
graphIdNoUses default from config if omitted
taskYesThe reasoning task or question
locusQueryNoOptional query to scope relevant knowledge
limitNoMax source contexts to consider
contextIdsNoFilter by specific context IDs
contextTypesNoFilter by context types

Environment Variables

VariableDescription
LOCUSGRAPH_SERVER_URLAPI server URL (default: https://api.locusgraph.com)
LOCUSGRAPH_AGENT_SECRETYour agent secret key

Next

Python SDK
Use LocusGraph with Python.
LangChain Integration
Connect LocusGraph to LangChain agents.