Skip to content

feat(client+langgraph): raw filter strings and EpisodeType normalization - #1403

Merged
malatewang merged 3 commits into
MemMachine:mainfrom
sscargal:rescue/1349-raw-filter-and-episode-type
May 13, 2026
Merged

feat(client+langgraph): raw filter strings and EpisodeType normalization#1403
malatewang merged 3 commits into
MemMachine:mainfrom
sscargal:rescue/1349-raw-filter-and-episode-type

Conversation

@sscargal

Copy link
Copy Markdown
Contributor

Summary

Rescues the substantive work from @haosenwang1018's 9-commit stack (#1341#1349) by cherry-picking the 3 commits that contain real feature code onto a fresh branch from current main, with lint and type fixes applied. The prefix-style doc and test commits in the original stack are not included here because main already absorbed them via #1352 and #1311.

This PR adds:

  1. Memory.search(filter=...) and Memory.list(filter=...) — accept an optional raw filter string alongside filter_dict. When both are provided they are combined with AND. The raw filter passes through to the v2 SearchMemoriesSpec.filter / ListMemoriesSpec.filter API fields unchanged.
  2. MemMachineTools.search_memory(filter=...) — pipes the raw filter through the LangGraph search-memory tool wrapper.
  3. MemMachineTools.add_memory(episode_type=...) — accepts 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.

Tests for all three additions are included.

Original commits (preserved as the squash commit author)

Changes vs. originals

  • One trivial rebase conflict resolved in langgraph.py docstring (merged main's updated filter_dict prefix wording with the new filter parameter doc).
  • Added # noqa: A002 at three filter: parameter sites with a comment pointing at the matching SearchMemoriesSpec.filter / ListMemoriesSpec.filter API field name. Same trade-off the API spec already makes.
  • Updated create_add_memory_tool's Callable[...] return-type annotation to include the new EpisodeType | str | None parameter introduced by 53b489e5.

Test plan

  • uv run ruff check packages/client/ — clean
  • uv run ty check packages/client/ — clean
  • uv run pytest packages/client/client_tests/test_memory.py packages/client/client_tests/test_langgraph.py — 151 passed
  • GitHub Actions matrix once the PR opens

Closes

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

Co-authored-by: Steve Scargall steve.scargall@gmail.com

@sscargal
sscargal requested a review from Copilot May 13, 2026 20:35
@sscargal sscargal added this to the v0.3.9 milestone May 13, 2026
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 <steve.scargall@gmail.com>
Signed-off-by: Steve Scargall <37674041+sscargal@users.noreply.github.com>
@sscargal
sscargal force-pushed the rescue/1349-raw-filter-and-episode-type branch from 2f95f4f to b0ad41c Compare May 13, 2026 21:08
@sscargal sscargal added the priority: high Issue is urgent or highly impactful. Needs to be addressed as soon as possible. label May 13, 2026
@malatewang
malatewang merged commit 3b9c404 into MemMachine:main May 13, 2026
44 checks passed
connectsudhindra-gif pushed a commit to connectsudhindra-gif/MemMachine that referenced this pull request Aug 15, 2026
…" string

MemMachineMemory.add() called memory.add(episode_type="text", ...), but
Memory.add() expects an EpisodeType enum and calls episode_type.value
internally, raising AttributeError: 'str' object has no attribute 'value'.
"text" was also never a valid EpisodeType value (only MESSAGE="message"
exists), so this crashed on every call. Same failure mode as the LangGraph
integration bug fixed in MemMachine#1403 (issue MemMachine#1002).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: high Issue is urgent or highly impactful. Needs to be addressed as soon as possible.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants