Files
Eduard van Valkenburg 28389df805 Python: Move SessionStore to core and persist Foundry Responses sessions (#7306)
* Python: Move session persistence into core

Move SessionStore and durable msgspec-backed storage into core, restore sessions in Foundry Responses hosting with per-user isolation, and document the serialization design.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Python: Address session persistence review feedback

Harden scoped file paths and corruption recovery, preserve session serialization compatibility, clarify dependency placement, and add reproducible benchmark evidence.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Python: Preserve session snapshot compatibility

Deep-copy in-memory session writes and retain existing Telegram session keys so stored conversations continue resolving.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Python: Simplify Foundry session isolation

Add experimental FoundrySessionStore backed by Agent Server request context, remove resolver plumbing, and centralize v2 user isolation for sessions, checkpoints, and approvals.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Python: Reduce Foundry session helper layering

Inline the single-use request user accessor while keeping separate context validation, fingerprint, and directory helpers for their distinct callers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Python: Clarify Foundry request context validation

Separate fail-fast request validation from context retrieval so Responses no longer appears to discard a returned context.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Python: Share Foundry request context helpers

Move protocol validation and user-scope derivation into a dedicated request-context module, leaving the session-store module focused on storage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Restore Foundry checkpoint storage paths

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Simplify Foundry session storage paths

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Persist Foundry sessions under hosted home

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Make hosted path test platform independent

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Address session persistence review feedback

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Isolate Foundry session path handling

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Clarify Foundry session path terminology

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Align Foundry sessions with Responses continuity

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Finalize Foundry Responses session persistence

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Add session store feature usage telemetry

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

* Fix hosted per-call history persistence

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c

---------

Copilot-Session: 3e5c81ad-75e8-4e92-a883-8bbd676c6c8c
2026-07-30 13:04:08 +00:00
..
2026-07-14 06:44:26 +00:00

Conversation & Session Management Samples

These samples demonstrate different approaches to managing conversation history and session state in Agent Framework.

Samples

File Description
suspend_resume_session.py Suspend and resume conversation sessions, comparing service-managed sessions (Microsoft Foundry) with in-memory sessions (OpenAI).
custom_history_provider.py Implement a custom history provider by extending HistoryProvider, enabling conversation persistence in your preferred storage backend.
file_history_provider.py Use the experimental FileHistoryProvider with FoundryChatClient and a function tool so the local JSON Lines file shows the full tool-calling loop.
file_history_provider_conversation_persistence.py Persist a tool-driven weather conversation with FileHistoryProvider, inspect the stored JSONL records, and continue with another city.
cosmos_history_provider.py Use Azure Cosmos DB as a history provider for durable conversation storage with CosmosHistoryProvider.
cosmos_history_provider_conversation_persistence.py Persist and resume conversations across application restarts using CosmosHistoryProvider — serialize session state, restore it, and continue with full Cosmos DB history.
cosmos_history_provider_messages.py Direct message history operations — retrieve stored messages as a transcript, clear session history, and verify data deletion.
cosmos_history_provider_sessions.py Multi-session and multi-tenant management — per-tenant session isolation, list_sessions() to enumerate, switch between sessions, and resume specific conversations.
redis_history_provider.py Use Redis as a history provider for persistent conversation history storage across sessions.

Prerequisites

For suspend_resume_session.py:

  • FOUNDRY_PROJECT_ENDPOINT: Your Microsoft Foundry project endpoint (service-managed session)
  • FOUNDRY_MODEL: The Foundry model deployment name
  • OPENAI_API_KEY: Your OpenAI API key (in-memory session)
  • Azure CLI authentication (az login)

For custom_history_provider.py:

  • OPENAI_API_KEY: Your OpenAI API key

For file_history_provider.py:

  • FOUNDRY_PROJECT_ENDPOINT: Your Microsoft Foundry project endpoint
  • FOUNDRY_MODEL: The Foundry model deployment name
  • Azure CLI authentication (az login)
  • The sample writes plaintext JSONL conversation logs to disk; use a trusted local directory and avoid treating the history files as secure secret storage

For file_history_provider_conversation_persistence.py:

  • FOUNDRY_PROJECT_ENDPOINT: Your Microsoft Foundry project endpoint
  • FOUNDRY_MODEL: The Foundry model deployment name
  • Azure CLI authentication (az login)
  • The sample writes plaintext JSONL conversation logs to disk; use a trusted local directory and avoid treating the history files as secure secret storage

For Cosmos DB samples (cosmos_history_provider*.py):

  • FOUNDRY_PROJECT_ENDPOINT: Your Microsoft Foundry project endpoint
  • FOUNDRY_MODEL: The Foundry model deployment name
  • AZURE_COSMOS_ENDPOINT: Your Azure Cosmos DB account endpoint
  • AZURE_COSMOS_DATABASE_NAME: The database that stores conversation history
  • AZURE_COSMOS_CONTAINER_NAME: The container that stores conversation history
  • Either AZURE_COSMOS_KEY or Azure CLI authentication (az login)

For redis_history_provider.py:

  • OPENAI_API_KEY: Your OpenAI API key
  • A running Redis server — default URL is redis://localhost:6379
    • Override via the REDIS_URL environment variable for remote or authenticated instances
    • Quickstart with Docker: docker run -d --name redis-stack -p 6379:6379 redis/redis-stack-server:latest