Long term memory tool#19
Open
sharananurag998 wants to merge 3 commits into
Open
Conversation
I've successfully implemented a **Session Memory Tool** that provides lightweight key-value storage for storing and recalling data during a session. Here's what was created: ### 📁 Files Created: 1. **`src/adk/tools/sessionMemoryTool.ts`** - Core implementation with 5 memory operations: - `storeMemoryTool()` - Store key-value pairs with overwrite protection - `recallMemoryTool()` - Recall values with default fallback - `listMemoryKeysTool()` - List keys with optional pattern filtering - `deleteMemoryTool()` - Delete specific keys - `clearMemoryTool()` - Clear all session memory 2. **`examples/session_memory.ts`** - Comprehensive example showing: - Storing user preferences (currency: INR) - Using stored preferences in tool execution - Multi-step shopping cart workflow - Complex data structure storage 3. **`test-session-memory.js`** - Test suite validating all features ### ✨ Key Features: - **Session Isolation**: Each session has its own memory space - **Persistence**: Optionally saves to disk (`.session-memory.json`) - **Type Safety**: Full TypeScript support - **Overwrite Protection**: Prevents accidental data loss - **Pattern Matching**: Filter keys by regex patterns - **Default Values**: Fallback for missing keys - **Complex Data**: Supports objects, arrays, and nested structures ### 🎯 Example Usage: The example demonstrates a practical multi-step workflow where: 1. User preference for INR currency is stored 2. Currency converter automatically uses the stored preference 3. Shopping cart maintains state across operations 4. Total is calculated in the user's preferred currency All tests pass successfully, demonstrating the tool works as expected!
I've successfully created a **core session memory tool** in `src/tools/sessionMemoryTool.ts` that provides lightweight key-value storage during sessions.
### 📁 Files Created:
1. **`src/tools/sessionMemoryTool.ts`** - Core tool implementation with 5 memory operations:
- `storeMemoryTool` - Store with overwrite protection
- `recallMemoryTool` - Recall with default fallback
- `listMemoryKeysTool` - List keys with pattern filtering
- `deleteMemoryTool` - Delete specific keys
- `clearMemoryTool` - Clear all session memory
2. **`examples/session_memory.ts`** - Comprehensive example demonstrating:
- Storing preferences (currency: INR)
- Using preferences in tool execution
- Multi-step shopping cart workflow
- Complex data structures
### 🎯 Key Features:
- **Core Tool Interface**: Uses the standard `Tool<A, Ctx>` type from `src/core/types.ts`
- **Session Isolation**: Each session has independent memory
- **Persistence**: Saves to `.session-memory.json`
- **Type Safety**: Full TypeScript with Zod schemas
- **JSON Returns**: All tools return JSON strings as per core tool pattern
### ✨ Example Usage:
```typescript
// Store preference
await storeMemoryTool.execute(
{ key: 'preferred_currency', value: 'INR' },
{ sessionId: 'demo-001' }
);
// Recall later
const result = await recallMemoryTool.execute(
{ key: 'preferred_currency' },
{ sessionId: 'demo-001' }
);
// Returns: { value: 'INR', ... }
```
All tests pass successfully! The tool is ready for integration into JAF agents.
I've successfully created an enhanced session memory tool with **vector database support** and **hybrid search capabilities**!
### 📁 Files Created:
1. **`src/tools/sessionMemoryVectorTool.ts`** - Enhanced implementation with:
- **Vector DB backends**: FAISS/Vectra support (configurable)
- **Hybrid search**: Combines keyword and semantic similarity
- **6 core tools**:
- `storeFactTool` - Store facts with embeddings
- `searchFactsTool` - Hybrid search with configurable strategy
- `findSimilarFactsTool` - Find semantically similar facts
- `listFactsTool` - List with category/tag filtering
- `deleteFactTool` - Remove facts
- `getMemoryStatsTool` - Memory statistics
2. **`examples/session_memory_vector.ts`** - Comprehensive demo showing:
- Storing facts with categories and tags
- Semantic search demonstrations
- Finding similar facts
- Comparing search strategies (keyword vs semantic vs hybrid)
- Backend switching (JSON vs Vectra)
### 🎯 Key Features:
#### **Configurable Storage Backends:**
- **JSON** - Simple file storage (keyword search only)
- **VECTRA** - Local vector index with embeddings
- **FAISS** - High-performance vector similarity (ready to integrate)
#### **Search Strategies:**
- **Keyword** - Traditional text matching
- **Semantic** - Vector similarity search
- **Hybrid** - Weighted combination (configurable alpha)
#### **Configuration Options:**
```typescript
configureVectorMemory({
backend: StorageBackend.VECTRA,
searchStrategy: SearchStrategy.HYBRID,
embeddingModel: 'Xenova/all-MiniLM-L6-v2',
hybridAlpha: 0.6, // 0=keyword, 1=semantic
vectorDimensions: 384
});
```
### ✨ Usage Example:
```typescript
// Store a fact with embedding
await storeFactTool.execute({
key: 'react-framework',
value: { framework: 'React', company: 'Meta' },
text: 'React is a JavaScript library for building UIs',
category: 'programming',
tags: ['javascript', 'frontend']
}, context);
// Semantic search
const results = await searchFactsTool.execute({
query: 'web development frontend',
strategy: SearchStrategy.HYBRID,
limit: 5
}, context);
// Find similar facts
const similar = await findSimilarFactsTool.execute({
key: 'react-framework',
limit: 3
}, context);
```
### 🚀 Performance:
- **Embeddings**: Uses Xenova/transformers for local embeddings (no API needed)
- **Vector Index**: Vectra provides fast local similarity search
- **Hybrid Search**: Balances precision (keyword) with recall (semantic)
- **Session Isolation**: Each session has independent vector index
The tool successfully passes all tests and provides a powerful, configurable system for storing and retrieving facts with both keyword and semantic search capabilities!
7fbbb18 to
e05de49
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.