Skip to content

feat(langgraph): support raw filter strings - #1343

Closed
haosenwang1018 wants to merge 3 commits into
MemMachine:mainfrom
haosenwang1018:feat/langgraph-raw-filter
Closed

haosenwang1018 wants to merge 3 commits into
MemMachine:mainfrom
haosenwang1018:feat/langgraph-raw-filter

Conversation

@haosenwang1018

Copy link
Copy Markdown
Contributor

Purpose of the change

Extend the LangGraph-oriented Python client wrapper so it can pass through raw filter strings, matching the new Python client search() / list() capability.

Description

Follow-up to #1310

This change updates MemMachineTools.search_memory() in packages/client/src/memmachine_client/langgraph.py to accept an optional raw filter string in addition to filter_dict.

Behavior:

  • existing filter_dict behavior remains unchanged
  • callers can now pass filter='metadata.category = "work"'
  • the wrapper forwards both filter_dict and filter through to memory.search(...)

Also added test coverage in packages/client/client_tests/test_langgraph.py for:

  • default passthrough still including filter=None
  • raw filter string passthrough into memory.search(...)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g., code style improvements, linting)
  • Documentation update
  • Project Maintenance (updates to build scripts, CI, etc., that do not affect the main project)
  • Security (improves security without changing functionality)

How Has This Been Tested?

  • Unit Test
  • Integration Test
  • End-to-end Test
  • Test Script (please provide)
  • Manual verification (list step-by-step instructions)

Test command:

  • cd packages/client && PYTHONPATH=/home/node/.openclaw/workspace/MemMachine/packages/client/src:/home/node/.openclaw/workspace/MemMachine/packages/common/src python -m pytest client_tests/test_langgraph.py -q

Checklist

  • I have signed the commit(s) within this pull request
  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own code
  • I have commented my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • Confirmed all checks passed
  • Contributor has signed the commit(s)
  • Reviewed the code
  • Run, Tested, and Verified the change(s) work as expected

@sscargal
sscargal requested a review from Copilot April 17, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for passing raw (string) filters through the LangGraph client wrapper and core Python client methods, aligning wrapper behavior with the updated client search() / list() API.

Changes:

  • Extend Memory.search() and Memory.list() to accept a raw filter string and AND-combine it with existing built-in and filter_dict filters.
  • Update LangGraph MemMachineTools.search_memory() to accept and forward the raw filter argument.
  • Add/adjust unit and integration tests to cover raw filter passthrough and updated filter_dict key conventions (metadata. prefix).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/client/src/memmachine_client/memory.py Adds filter parameter and combines raw + dict filters into a single request filter string.
packages/client/src/memmachine_client/langgraph.py Extends tool wrapper to accept and forward filter.
packages/client/client_tests/test_memory.py Adds tests for raw filter strings and updates filter_dict expectations to include metadata. prefixes.
packages/client/client_tests/test_langgraph.py Adds test for raw filter passthrough and updates expected calls to include filter=None.
packages/client/client_tests/test_integration_complete.py Updates integration test to use metadata.-prefixed keys in filter_dict.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 459 to 468
def list(
self,
memory_type: MemoryType = MemoryType.Episodic,
page_size: int = 100,
page_num: int = 0,
filter_dict: dict[str, str] | None = None,
filter: str | None = None,
set_metadata: dict[str, JsonValue] | None = None,
timeout: int | None = None,
) -> ListResult:
Comment on lines +418 to +424
dict_filter_str = self._dict_to_filter_string(merged_filters) if merged_filters else ""
explicit_filter = filter.strip() if filter else ""

if dict_filter_str and explicit_filter:
filter_str = f"{dict_filter_str} AND ({explicit_filter})"
else:
filter_str = dict_filter_str or explicit_filter
if there are key conflicts.
timeout: Request timeout in seconds (uses client default if not provided)
filter: Optional raw filter string. If provided together with built-in or
`filter_dict` filters, all filters are combined with AND.
Comment on lines +421 to +424
if dict_filter_str and explicit_filter:
filter_str = f"{dict_filter_str} AND ({explicit_filter})"
else:
filter_str = dict_filter_str or explicit_filter
@sscargal sscargal added this to the v0.3.9 milestone May 13, 2026
malatewang added a commit that referenced this pull request May 13, 2026
…ion (#1403)

* feat(client+langgraph): raw filter strings and EpisodeType normalization

Add three small features to the Python client and its LangGraph wrapper
so callers can pass structured filter expressions and either-enum-or-string
episode types directly.

1. `Memory.search(filter=...)` and `Memory.list(filter=...)`
   Accept an optional raw filter string alongside `filter_dict`. When both
   are provided, the two are combined with `AND`. The raw filter is passed
   through to the v2 `SearchMemoriesSpec.filter` / `ListMemoriesSpec.filter`
   fields unchanged.

2. `MemMachineTools.search_memory(filter=...)`
   Pipes the same raw filter through the LangGraph search-memory tool.

3. `MemMachineTools.add_memory(episode_type=...)`
   Accept either an `EpisodeType` enum or its string value
   (e.g. `"message"`), normalizing strings via `EpisodeType(...)` before
   delegating to `Memory.add`. The factory tool's return-type annotation
   was widened to match.

The `filter` parameter shadows the Python builtin, which is the same
trade-off `memmachine_common.api.SearchMemoriesSpec` already made for
its `filter:` field — keeping the parameter name aligned with the API
field. `# noqa: A002` is applied at the three call sites with a comment
pointing at the API spec.

This commit consolidates the substantive work from haosenwang1018's
9-commit stack (#1341 → #1349) into a single rebased+linted commit
against current `main`. The original stack's prefix-style doc and test
changes have been omitted because they have already landed on `main`
via #1352 and #1311. The original commits authored by haosenwang1018:

  - 921b55f feat(client): support raw filter strings
  - e0849bb feat(langgraph): support raw filter strings
  - 53b489e fix(langgraph): normalize episode type strings

Closes #1341, #1342, #1343, #1344, #1345, #1346, #1347, #1348, #1349

Co-authored-by: Steve Scargall <[email protected]>
Signed-off-by: Steve Scargall <[email protected]>

* docs(langgraph): document filter and episode type support

---------

Signed-off-by: Steve Scargall <[email protected]>
Co-authored-by: haosenwang1018 <[email protected]>
Co-authored-by: Shu Wang <[email protected]>
@sscargal

Copy link
Copy Markdown
Contributor

Closed by #1403

@sscargal sscargal closed this May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants