Skip to content

feat(flow): support custom persistence key in @persist#5649

Merged
lucasgomide merged 6 commits intomainfrom
iris/persist-custom-key
Apr 29, 2026
Merged

feat(flow): support custom persistence key in @persist#5649
lucasgomide merged 6 commits intomainfrom
iris/persist-custom-key

Conversation

@lucasgomide
Copy link
Copy Markdown
Contributor

@lucasgomide lucasgomide commented Apr 28, 2026

Adds a key parameter to @persist so flows can use any state attribute (e.g. conversation_id) as the persistence key instead of always falling back to state.id. When the named attribute is missing or falsy, raises a clear ValueError identifying the missing key.


Note

Medium Risk
Changes core persistence key selection and error handling, which can affect how existing flows are saved/loaded if users adopt key or rely on prior error messages.

Overview
@persist now accepts an optional key parameter to choose which state attribute (Pydantic/object) or dict key is used as the persistence identifier, defaulting to the existing state.id behavior.

Persistence now raises a clear ValueError when the custom key is missing or falsy, and tests were added to cover Pydantic, dict-based states, and the failure path. Documentation across EN/AR/KO/PT-BR was updated with examples and behavior notes for custom persistence keys.

Reviewed by Cursor Bugbot for commit 9efe193. Bugbot is set up for automated code reviews on this repo. Configure here.

Allows users to specify which state attribute to use as the
persistence key instead of always defaulting to state.id.

Usage: @persist(key='conversation_id')

Falls back to state.id when key is not provided (no breaking change).
Raises ValueError if the specified key is missing or falsy on state.
@iris-clawd iris-clawd force-pushed the iris/persist-custom-key branch from 480e4be to 6ddfaaf Compare April 28, 2026 22:35
@github-actions github-actions Bot added size/L and removed size/M labels Apr 28, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6f1f907. Configure here.

Comment thread lib/crewai/src/crewai/flow/persistence/decorators.py
Copy link
Copy Markdown
Contributor

@iris-clawd iris-clawd left a comment

Choose a reason for hiding this comment

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

Looks good 👍

Code:

  • Clean threading of key through all wrapper paths (sync, async, class-level, method-level) — nothing missed.
  • Good separation between custom-key ValueError and the default id-missing error, so existing flows are unaffected.
  • The str(e) or LOG_MESSAGES["id_missing"] fix in the except (TypeError, ValueError) block correctly preserves the custom key error message instead of swallowing it.

Tests:

  • Pydantic, dict, and missing-key error cases all covered. The assertion that load_state(flow.state.id) is None in the Pydantic test is a nice touch — proves the custom key was actually used as the lookup, not just ignored.

Docs:

  • Consistent examples across all 4 languages, all 3 doc pages.

One minor note (non-blocking): if someone passes key="id" explicitly, it would behave identically to omitting it — which is fine, but might be worth a one-liner in the docstring mentioning it's a no-op in that case. Totally optional.

💬 259

@lucasgomide lucasgomide merged commit e2deac5 into main Apr 29, 2026
55 checks passed
@lucasgomide lucasgomide deleted the iris/persist-custom-key branch April 29, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants