Skip to content

Python: OpenAI store=True can silently bypass external HistoryProvider persistence #5798

@rg-ve

Description

@rg-ve

Summary

When using the Python SDK with OpenAIChatClient, an external HistoryProvider such as CosmosHistoryProvider, and require_per_service_call_history_persistence=True, external history can be silently skipped unless callers explicitly set store=False in ChatOptions.

This is surprising because the agent is configured with an external history provider and asks for per-service-call persistence, but no provider rows are written and no warning/error is surfaced.

Repro shape

from agent_framework import Agent, AgentSession, ChatOptions
from agent_framework.openai import OpenAIChatClient
from agent_framework_azure_cosmos import CosmosHistoryProvider

history = CosmosHistoryProvider(...valid endpoint/db/container/credential...)
client = OpenAIChatClient(api_key=..., model="gpt-5.5-pro")

async with history:
    async with Agent(
        client=client,
        name="HistoryRepro",
        instructions="Answer briefly.",
        context_providers=[history],
        require_per_service_call_history_persistence=True,
        default_options=ChatOptions(
            model="gpt-5.5-pro",
            max_tokens=512,
            reasoning={"effort": "high"},
            # store=False fixes the issue. Omitting it writes no external rows.
        ),
    ) as agent:
        session = AgentSession(session_id="debug-openai-history")
        async for _ in agent.run("Remember BLUE-COSMOS-913. Reply ok.", stream=True, session=session):
            pass

Observed without store=False:

  • The model call succeeds.
  • A second turn with the same in-process session may recall successfully.
  • CosmosHistoryProvider writes zero rows.
  • There is no warning that external history was bypassed.

Observed with store=False:

  • Cosmos rows are written as expected.
  • A second turn can recall from SDK/Cosmos history.

Suspected cause

OpenAIChatClient.STORES_BY_DEFAULT=True. In Agent._resolve_per_service_call_history_providers(...), service-side storage means no per-service-call history middleware is installed. Later, _run_after_providers(...) still skips HistoryProvider instances because require_per_service_call_history_persistence is true. The combination results in no external history writes.

Expected behavior

At least one of these should happen:

  1. require_per_service_call_history_persistence=True plus external HistoryProvider should force local/external persistence or set store=False for OpenAI automatically.
  2. The SDK should raise a configuration error when OpenAI service-side storage and external per-service-call history persistence conflict.
  3. The SDK should log a clear warning that external HistoryProvider persistence is disabled because service-side OpenAI storage is active.

Silent zero-row external history is hard to diagnose in production.

Workaround

Set store=False in OpenAI ChatOptions when external SDK history is the source of truth.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions