diff --git a/libs/checkpoint/src/memory.ts b/libs/checkpoint/src/memory.ts index ad8e45d9..77c7b1a4 100644 --- a/libs/checkpoint/src/memory.ts +++ b/libs/checkpoint/src/memory.ts @@ -171,7 +171,7 @@ export class MemorySaver extends BaseCheckpointSaver { options?: CheckpointListOptions ): AsyncGenerator { // eslint-disable-next-line prefer-const - let { before, limit } = options ?? {}; + let { before, limit, filter } = options ?? {}; const threadIds = config.configurable?.thread_id ? [config.configurable?.thread_id] : Object.keys(this.storage); @@ -209,6 +209,15 @@ export class MemorySaver extends BaseCheckpointSaver { metadataStr )) as CheckpointMetadata; + if ( + filter && + !Object.entries(filter).every( + ([key, value]) => (metadata as unknown as Record)[key] === value + ) + ) { + continue; + } + // Limit search results if (limit !== undefined) { if (limit <= 0) break;