Skip to content

Turn State fixes and auto saving in application layer#107

Merged
axelsrz merged 2 commits intomainfrom
users/axsuarez/turn-state-fixes
Sep 4, 2025
Merged

Turn State fixes and auto saving in application layer#107
axelsrz merged 2 commits intomainfrom
users/axsuarez/turn-state-fixes

Conversation

@axelsrz
Copy link
Member

@axelsrz axelsrz commented Aug 29, 2025

This pull request introduces several changes to state management and middleware handling in the agent hosting core. The main updates include refactoring how state is cleared and saved, standardizing method signatures to consistently require turn_context, and correcting logic in middleware execution. These changes improve code clarity, consistency, and ensure proper context is passed throughout the state lifecycle.

State Management Improvements:

  • Updated clear methods in conversation_state.py, temp_state.py, and turn_state.py to consistently require turn_context, ensuring state operations have the necessary context. The turn_state.py method now clears all scopes if none is specified. [1] [2] [3]
  • Added an async save method to temp_state.py to support saving state asynchronously.

Middleware Logic Adjustments:

  • Fixed the logic in _on_turn to save state only if after-turn middleware succeeds, correcting the previous conditional.
  • Standardized calls to state.save in both before-turn and after-turn middleware to remove the explicit storage parameter, relying on context instead. [1] [2]

Code Consistency:

  • Improved the default value handling in agent_state.py by explicitly checking for None before invoking the factory, making the code more robust.

@axelsrz axelsrz requested a review from rodrigobr-msft August 29, 2025 22:15
@axelsrz axelsrz merged commit 9b813cc into main Sep 4, 2025
5 checks passed
@cleemullins cleemullins deleted the users/axsuarez/turn-state-fixes branch October 2, 2025 21:05
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.

2 participants

Comments