Skip to content

Fix class-based typed state actions - #863

Draft
FenjuFu wants to merge 1 commit into
apache:mainfrom
FenjuFu:agent/fix-class-based-typed-state
Draft

Fix class-based typed state actions#863
FenjuFu wants to merge 1 commit into
apache:mainfrom
FenjuFu:agent/fix-class-based-typed-state

Conversation

@FenjuFu

@FenjuFu FenjuFu commented Jul 28, 2026

Copy link
Copy Markdown

Summary

  • add identity state-conversion hooks to ActionSchema
  • let PydanticActionSchema convert Burr State values into its input/output models and merge typed updates back into the original state
  • apply schema conversion in synchronous and asynchronous class-based Action execution
  • preserve existing Function/Reducer behavior through DEFAULT_SCHEMA fallback
  • add end-to-end sync and async class-based Pydantic regression tests

Root cause

Class-based actions could expose an ActionSchema, but the application lifecycle only used it to validate intermediate result types. run() and update() still received Burr State objects, so model attribute access such as state.initial_prompt failed even with a Pydantic schema.

Impact

Class-based actions that expose PydanticActionSchema now receive the declared Pydantic input/output models. The typed model returned from update() is merged into the original Burr state, preserving unrelated fields and the application typing system. Existing dict-based actions and schema-less internal reducers keep their current behavior.

Validation

  • python -m pytest tests\core\test_application.py tests\core\test_action.py tests\integrations\test_class_based_pydantic.py tests\integrations\test_burr_pydantic.py -q 鈥?326 passed
  • python -m ruff check burr\core\typing.py burr\core\application.py burr\integrations\pydantic.py tests\integrations\test_class_based_pydantic.py
  • python -m black --check tests\integrations\test_class_based_pydantic.py
  • git diff --check

Closes #400.

Contributed as a member of the iFLYTEK Astron community.

@github-actions github-actions Bot added area/core Application, State, Graph, Actions area/integrations External integrations (LLMs, frameworks) area/typing Mypy, type hints, pydantic labels Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Application, State, Graph, Actions area/integrations External integrations (LLMs, frameworks) area/typing Mypy, type hints, pydantic

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typing State for the class-based API does not work

1 participant