@spokest/langchain
v1.0.0
Published
LangChain memory integration for Spokest Brain
Maintainers
Readme
@spokest/langchain
LangChain memory integration for Spokest Brain. Give your LangChain chains persistent, associative memory powered by the Spokest Brain API.
Install
npm install @spokest/langchain @langchain/coreUsage
import { ChatOpenAI } from '@langchain/openai';
import { ConversationChain } from 'langchain/chains';
import { SpokestMemory } from '@spokest/langchain';
const memory = new SpokestMemory({
apiKey: 'sk-your-spokest-api-key',
baseUrl: 'https://brain-api.spokest.com', // optional, this is the default
});
const llm = new ChatOpenAI({ model: 'gpt-4o' });
const chain = new ConversationChain({ llm, memory });
const response = await chain.invoke({ input: 'What did we discuss about the product launch?' });
console.log(response.response);Configuration
| Parameter | Default | Description |
|-----------|---------|-------------|
| apiKey | (required) | Your Spokest Brain API key |
| baseUrl | https://brain-api.spokest.com | Brain API base URL |
| memoryKey | memories | Key used in the chain's memory variables |
How it works
loadMemoryVariables-- Calls/v1/memory/recallwith the current user input to retrieve relevant memories. Returns them formatted as a bulleted list under the configuredmemoryKey.saveContext-- Calls/v1/memory/storewith the full conversation turn (user input + assistant output) after each chain invocation.
License
MIT
