Skip to content

refactor: convert Flow to Pydantic BaseModel#5190

Merged
greysonlalonde merged 16 commits intomainfrom
refactor/flow-to-basemodel
Mar 31, 2026
Merged

refactor: convert Flow to Pydantic BaseModel#5190
greysonlalonde merged 16 commits intomainfrom
refactor/flow-to-basemodel

Conversation

@greysonlalonde
Copy link
Copy Markdown
Contributor

@greysonlalonde greysonlalonde commented Mar 31, 2026

Summary

  • FlowMeta inherits ModelMetaclass, Flow inherits BaseModel
  • Flow attrs converted to Field/PrivateAttr with model_validator and model_post_init
  • AgentExecutor uses proper Fields with eager init, removing deferred _ensure_flow_initialized
  • FlowMeta auto-handles unannotated class attrs and mixin TYPE_CHECKING annotations
  • Memory.deepcopy added for unpickleable ThreadPoolExecutor/Lock

Test plan

  • All 189 flow tests pass
  • All 78 agent executor tests pass
  • All memory tests pass
  • Full suite: 3297 passed, 34 pre-existing failures unrelated to this change

Note

High Risk
High risk because it refactors core orchestration (Flow) and execution (AgentExecutor) initialization/state semantics, which can affect persistence/resumption, threading locks, and event emission across many call sites.

Overview
Converts Flow into a Pydantic BaseModel with Field/PrivateAttr definitions, a ModelMetaclass-based FlowMeta, and a new post-init path (model_post_init/_flow_post_init) to initialize state, tracing, memory, and method registration.

Refactors AgentExecutor to be fully Pydantic-initialized (typed Fields + model_validator), removes the deferred _ensure_flow_initialized path, and standardizes on stop_words (fixing a bug in Agent that was setting stop).

Updates flow persistence usage from _persistence to persistence, adds Memory.__deepcopy__ to avoid copying unpickleable executors/locks, rebuilds AgentExecutor forward refs at import time in __init__.py, and adjusts tests to construct executors via model_construct and to use the renamed persistence field.

Written by Cursor Bugbot for commit c0ced12. This will update automatically on new commits. Configure here.

greysonlalonde and others added 2 commits April 1, 2026 01:08
FlowMeta inherits ModelMetaclass. Flow uses Field/PrivateAttr with
model_validator and model_post_init. AgentExecutor uses proper Fields
with eager init, removing deferred _ensure_flow_initialized.
greysonlalonde and others added 6 commits April 1, 2026 01:18
…lures

- _flow_post_init tracks _flow_post_init_done to prevent duplicate
  trace listener setup and event emission from MRO paths
- model_rebuild failure in __init__.py logs a warning instead of
  silently passing
model_rebuild now resolves SystemPromptResult/StandardPromptResult at
runtime, which triggers Pydantic's TypedDict version check.
Restores the original condition so explicit initial_state values are
not silently ignored when _initial_state_t is set. The BaseModel
instance path now wraps with FlowState when id is missing instead of
raising, matching the type-parameter path behavior.
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 4 potential issues.

Fix All in Cursor

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

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.

LGTM — solid refactor converting Flow to Pydantic BaseModel. The stop_words bug fix alone is worth it. Previously reviewed concerns were addressed.

@greysonlalonde greysonlalonde merged commit d6714a0 into main Mar 31, 2026
48 checks passed
@greysonlalonde greysonlalonde deleted the refactor/flow-to-basemodel branch March 31, 2026 19:48
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.

2 participants