Title
Integrate Memory History Tracking with Existing Memory Tools
Description
Update existing memory tools (extract-knowledge.ts, memory_operation.ts) to automatically track memory
operations in the history storage service. This integration should be seamless and maintain backward
compatibility.
Background
The memory tools currently handle memory operations but don't track operation history. We need to integrate
history tracking without breaking existing functionality or requiring changes to existing tool calls.
Requirements
- Maintain backward compatibility with existing tool calls
- Automatic history tracking for all memory operations
- Support for custom metadata propagation
- Graceful degradation if history service is unavailable
- Minimal performance impact on existing operations
Implementation Details
Files to Modify
- src/core/brain/tools/definitions/memory/extract_and_operate_memory.ts
- src/core/brain/tools/definitions/memory/memory_operation.ts
- src/core/brain/tools/definitions/memory/index.ts
- Update Tool Parameter Schema
Add new parameter to the tool definition:
memoryMetadata: {
type: 'object',
description: 'Custom metadata to attach to created memories (projectId, userId, teamId, etc.)',
additionalProperties: true,
properties: {
projectId: { type: 'string', description: 'Project identifier for scoped memory' },
userId: { type: 'string', description: 'User identifier for personalized memory' },
teamId: { type: 'string', description: 'Team identifier for team-scoped memory' },
environment: { type: 'string', description: 'Environment (dev, staging, prod)' },
source: { type: 'string', description: 'Source of the memory (cli, api, web)' },
name: { type: 'string', description: 'Descriptive name for the memory operation' }
}
}
- Update Memory Payload Structure
Modify payload creation to include history tracking:
const payload = {
id: action.id,
text: action.text,
tags: action.tags,
confidence: action.confidence,
reasoning: action.reasoning,
event: action.event,
timestamp: new Date().toISOString(),
metadata: {
// Priority: explicit memoryMetadata > context fields > defaults
...args.memoryMetadata,
sessionId: args.context?.sessionId || payload.metadata?.sessionId,
userId: args.context?.userId || payload.metadata?.userId,
projectId: args.context?.projectId || payload.metadata?.projectId,
conversationTopic: args.context?.conversationTopic
}
};
// NEW: Record operation in history
await recordMemoryOperation({
operation: action.event,
memoryId: action.id,
projectId: payload.metadata.projectId,
userId: payload.metadata.userId,
name: args.memoryMetadata?.name || Memory ${action.event},
tags: action.tags,
metadata: payload.metadata,
success: true
});
- Update MemoryOperationArgs Interface
Add to MemoryOperationArgs interface:
export interface MemoryOperationArgs {
extractedFacts: string[];
existingMemories?: {
id: string;
text: string;
metadata?: Record<string, any>;
}[];
context?: {
sessionId?: string;
userId?: string;
projectId?: string;
conversationTopic?: string;
recentMessages?: string[];
sessionMetadata?: Record<string, any>;
};
memoryMetadata?: Record<string, any>; // NEW: Custom metadata
options?: {
// ... existing options
};
}
Acceptance Criteria
- Tool accepts memoryMetadata parameter with flexible schema
- Memory operations are automatically tracked in history
- Backward compatibility maintained (existing calls work without changes)
- Graceful degradation when history service unavailable
- Metadata is properly merged with context
- All memory operations (ADD, UPDATE, DELETE) are tracked
- Error scenarios are properly recorded
- Performance impact is minimal (<10ms overhead)
Testing Requirements
- Unit tests for tool parameter validation
- Unit tests for metadata merging logic
- Integration tests with history service
- Test backward compatibility with existing calls
- Error handling tests (history service unavailable)
- Performance tests for operation overhead
bring your own logics if you find it is necessary
Title
Integrate Memory History Tracking with Existing Memory Tools
Description
Update existing memory tools (extract-knowledge.ts, memory_operation.ts) to automatically track memory
operations in the history storage service. This integration should be seamless and maintain backward
compatibility.
Background
The memory tools currently handle memory operations but don't track operation history. We need to integrate
history tracking without breaking existing functionality or requiring changes to existing tool calls.
Requirements
Implementation Details
Files to Modify
Add new parameter to the tool definition:
memoryMetadata: {
type: 'object',
description: 'Custom metadata to attach to created memories (projectId, userId, teamId, etc.)',
additionalProperties: true,
properties: {
projectId: { type: 'string', description: 'Project identifier for scoped memory' },
userId: { type: 'string', description: 'User identifier for personalized memory' },
teamId: { type: 'string', description: 'Team identifier for team-scoped memory' },
environment: { type: 'string', description: 'Environment (dev, staging, prod)' },
source: { type: 'string', description: 'Source of the memory (cli, api, web)' },
name: { type: 'string', description: 'Descriptive name for the memory operation' }
}
}
Modify payload creation to include history tracking:
const payload = {
id: action.id,
text: action.text,
tags: action.tags,
confidence: action.confidence,
reasoning: action.reasoning,
event: action.event,
timestamp: new Date().toISOString(),
metadata: {
// Priority: explicit memoryMetadata > context fields > defaults
...args.memoryMetadata,
sessionId: args.context?.sessionId || payload.metadata?.sessionId,
userId: args.context?.userId || payload.metadata?.userId,
projectId: args.context?.projectId || payload.metadata?.projectId,
conversationTopic: args.context?.conversationTopic
}
};
// NEW: Record operation in history
await recordMemoryOperation({
operation: action.event,
memoryId: action.id,
projectId: payload.metadata.projectId,
userId: payload.metadata.userId,
name: args.memoryMetadata?.name ||
Memory ${action.event},tags: action.tags,
metadata: payload.metadata,
success: true
});
Add to MemoryOperationArgs interface:
export interface MemoryOperationArgs {
extractedFacts: string[];
existingMemories?: {
id: string;
text: string;
metadata?: Record<string, any>;
}[];
context?: {
sessionId?: string;
userId?: string;
projectId?: string;
conversationTopic?: string;
recentMessages?: string[];
sessionMetadata?: Record<string, any>;
};
memoryMetadata?: Record<string, any>; // NEW: Custom metadata
options?: {
// ... existing options
};
}
Acceptance Criteria
Testing Requirements
bring your own logics if you find it is necessary