SDK
Telygent SDK overview
The SDK lives in your backend and keeps data operations inside your environment. The sections below walk through how installation, storage, database tool execution, and the Telygent AI service work together.
Backend installation
Install the SDK in your server runtime alongside Redis and Mongo drivers. The SDK is intended for backend-only usage so API keys and data access stay on the server.
Use environment variables for TELYGENT_API_KEY, Redis, and Mongo connections, and initialize the client in your API layer or service container.
Conversation storage
The SDK stores conversation history in your Redis. Each response is written to Redis so you can reload conversations, resume sessions, and power UI timelines without copying data to Telygent.
You control retention with TTL settings, and only the last N messages are sent to Telygent per request to keep prompts efficient.
Database connection
The SDK executes queries locally using your database adapter. The registry controls which fields and filters are allowed.
Required filters are injected from user context, and validation happens before any query runs. This keeps data isolation and permissions enforced in your backend.
Telygent AI service
The SDK communicates with the Telygent AI service for reasoning. Telygent handles planning, prompting, and provider routing so your backend only manages data and permissions.
Responses return text plus optional visualizations, ready for UI rendering or further processing inside your app.
Quickstart
1import { createAiClient, createRedisHistoryStore, createMongoAdapter } from "@telygent/ai-sdk";
2import { MongoClient } from "mongodb";
3
4const historyStore = createRedisHistoryStore({
5 url: process.env.REDIS_URL,
6 ttlSeconds: 3600,
7});
8
9const mongoClient = new MongoClient(process.env.MONGO_URI);
10await mongoClient.connect();
11const mongoDb = mongoClient.db(process.env.MONGO_DB_NAME);
12
13const registry = {
14 Transaction: {
15 collectionName: "transactions",
16 allowedFields: ["amount", "status", "createdAt"],
17 requiredFilters: [{ field: "tenantId", contextKey: "tenantId" }],
18 },
19};
20
21const dbAdapter = createMongoAdapter({ db: mongoDb, registry });
22
23const client = createAiClient({
24 apiKey: process.env.TELYGENT_API_KEY,
25 aiName: "Atlas",
26 registry,
27 historyStore,
28 dbAdapter,
29 log: false,
30});
31
32const response = await client.query({
33 question: "Show me recent transactions",
34 conversationId: "conv_123",
35 userContext: { userId: "user_1", tenantId: "tenant_1" },
36});
37
38console.log(response.content);