Skip to content

Comments

Python: Simplify Python memory sample to use session state#4085

Merged
eavanvalkenburg merged 1 commit intomicrosoft:mainfrom
eavanvalkenburg:docs/update-memory-sample
Feb 19, 2026
Merged

Python: Simplify Python memory sample to use session state#4085
eavanvalkenburg merged 1 commit intomicrosoft:mainfrom
eavanvalkenburg:docs/update-memory-sample

Conversation

@eavanvalkenburg
Copy link
Member

Simplifies the 04_memory.py get-started sample:

  • Rename UserNameProviderUserMemoryProvider for clarity
  • Use session state (state dict) instead of instance variables for persistence
  • Use context.extend_instructions() instead of context.instructions.append()
  • Use DEFAULT_SOURCE_ID class attribute (proper pattern)
  • Fix imports to use public agent_framework API
  • Add session state inspection at end of sample

This aligns the sample with the updated docs in MicrosoftDocs/semantic-kernel-pr#880.

- Rename UserNameProvider → UserMemoryProvider
- Use session state (state dict) instead of instance variables
- Use context.extend_instructions() instead of context.instructions.append()
- Use DEFAULT_SOURCE_ID class attribute
- Fix imports to use public agent_framework API
- Add session state inspection at end of sample

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 19, 2026 14:14
@github-actions github-actions bot changed the title Simplify Python memory sample to use session state Python: Simplify Python memory sample to use session state Feb 19, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Python getting-started memory sample (04_memory.py) to demonstrate persisting user info via AgentSession.state using a context provider, aligning the sample with newer session-state guidance.

Changes:

  • Switches imports to the public agent_framework API surface.
  • Reworks the provider to store/read the user name from provider-scoped session state and uses SessionContext.extend_instructions().
  • Adds a final print showing how to inspect stored provider state from the session.

@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Feb 19, 2026
Merged via the queue into microsoft:main with commit f93ceae Feb 19, 2026
31 checks passed
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.

3 participants