Use this file to discover all available pages before exploring further.
AG-Kit’s memory system is designed to seamlessly integrate with AI agents, providing automatic context management, persistent knowledge storage, and intelligent memory operations. This guide covers integration patterns, framework-specific implementations, and best practices.
import { ChatOpenAI } from '@langchain/openai';import { ConversationChain } from 'langchain/chains';import { TDAIChatHistory } from '@ag-kit/adapter-langchain';// Create TDAI-based chat historyconst chatHistory = new TDAIChatHistory({ sessionId: 'user-123', apiKey: process.env.TDAI_API_KEY!, baseURL: process.env.TDAI_BASE_URL});// Use with LangChainconst model = new ChatOpenAI();const chain = new ConversationChain({ llm: model, memory: chatHistory});const response = await chain.call({ input: 'Hello, I am building a chatbot'});
// ❌ Wrong: Memory instance not sharedconst agent1 = new Agent({ memory: new InMemoryMemory() });const agent2 = new Agent({ memory: new InMemoryMemory() });// ✅ Correct: Shared memory instanceconst sharedMemory = new InMemoryMemory();const agent1 = new Agent({ memory: sharedMemory });const agent2 = new Agent({ memory: sharedMemory });
Session Isolation Issues
// ❌ Wrong: Same session for different usersconst agent = new Agent({ memory, sessionId: 'default' });// ✅ Correct: Unique session per userconst agent = new Agent({ memory, sessionId: `user-${userId}`});