Skip to content

Issue: State Persistence Failure for Custom Attributes in TurnState #288

@Anilalkg

Description

@Anilalkg

Hi Experts,

Could you please help me with this issue ?


Issue: State Persistence Failure for Custom Attributes in TurnState

Description

In a multi-turn conversation (specifically when handling Adaptive Card Submit actions), custom attributes defined on an AppTurnState subclass do not persist across turns. While the conversation bucket is successfully saved to storage, standard Python class attributes are lost when the AgentApplication creates a new instance of the state for the next turn.

Environment

  • SDK: microsoft-agents Python
  • Hosting: hosting.core
  • Storage: MemoryStorage (or any storage where code reloads/new turns occur)

Code Snippet: The Current State Definition

The state is currently defined as a standard class attribute:

class AppTurnState(TurnState):
    """Extended TurnState with job requisition draft."""
    # This attribute is ephemeral and does not map to the persistent conversation bucket
    job_draft: Optional[JobRequisitionDraft] = None

The Failure Flow

  1. Turn 1 (Message Received):
# Logic creates a draft and saves state
_state.job_draft = JobRequisitionDraft(job_title="AI Developer", department="Azure")
await _state.save(context) 
# Logs show: DEBUG: Save complete. Conversation ID: 4AUjYs...
  1. Turn 2 (Adaptive Card Action/Next Message):
# Context/Conversation ID matches Turn 1
# Attempting to access the data
print(_state.job_draft) # Result: AttributeError: 'TurnState' object has no attribute 'job_draft'
# OR
draft_dict = await _state.conversation.load(context) # Result: {}

Logs

ACTION-- submit_update_choice
Card Data-- {'action': 'submit_update_choice', 'jobTitle': 'Ai Developer', 'department': 'Azure'}
DEBUG: Loading state for ID: 4AUjYsFG2rGHyh5El9deRB-us
532-- {}
AttributeError: 'TurnState' object has no attribute 'job_draft'

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions