Skip to content

@agentctx/client

A lightweight client library for connecting to a running AgentCTX gateway. Use this when you want to send CTX operations from your application without running the full gateway locally.

Terminal window
npm install @agentctx/client
import { AgentCTXClient } from '@agentctx/client';
const client = new AgentCTXClient({
url: 'http://localhost:3100',
transport: 'sse'
});
await client.connect();
// Search tools
const tools = await client.query('?t github');
// { ok: true, data: { results: [...] } }
// Store a memory
await client.query('+m "decision" #arch "Use PASETO"');
// Search knowledge
const results = await client.query('?k "auth patterns" #code ^3');
// Call a tool
const issues = await client.query('>t github.issues.list state="open" ^5');
// Live memory updates
client.subscribe('?m #team #live', (event) => {
console.log('Memory updated:', event);
});
// Live knowledge changes
client.subscribe('?k #live', (event) => {
console.log('Knowledge updated:', event);
});
await client.disconnect();
interface ClientConfig {
url: string; // Gateway URL
transport: 'sse' | 'http'; // Transport type
auth?: {
token: string; // JWT for authentication
};
timeout?: number; // Request timeout in ms (default: 30000)
retries?: number; // Auto-retry count (default: 3)
}
try {
const result = await client.query('>t invalid.tool');
} catch (err) {
if (err.code === 'TOOL_NOT_FOUND') {
// Handle missing tool
}
}