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:
require_per_service_call_history_persistence=True plus external HistoryProvider should force local/external persistence or set store=False for OpenAI automatically.
- The SDK should raise a configuration error when OpenAI service-side storage and external per-service-call history persistence conflict.
- 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.
Summary
When using the Python SDK with
OpenAIChatClient, an externalHistoryProvidersuch asCosmosHistoryProvider, andrequire_per_service_call_history_persistence=True, external history can be silently skipped unless callers explicitly setstore=FalseinChatOptions.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
Observed without
store=False:CosmosHistoryProviderwrites zero rows.Observed with
store=False:Suspected cause
OpenAIChatClient.STORES_BY_DEFAULT=True. InAgent._resolve_per_service_call_history_providers(...), service-side storage means no per-service-call history middleware is installed. Later,_run_after_providers(...)still skipsHistoryProviderinstances becauserequire_per_service_call_history_persistenceis true. The combination results in no external history writes.Expected behavior
At least one of these should happen:
require_per_service_call_history_persistence=Trueplus externalHistoryProvidershould force local/external persistence or setstore=Falsefor OpenAI automatically.Silent zero-row external history is hard to diagnose in production.
Workaround
Set
store=Falsein OpenAIChatOptionswhen external SDK history is the source of truth.Thanks.