Skip to content

Commit 55fc882

Browse files
authored
Python: Fix store=False not overriding client default (#4569)
* Fix store=False not overriding client default * Address comments * Fix unit tests * Fix integration tests * Fix tests
1 parent c15f075 commit 55fc882

File tree

3 files changed

+379
-207
lines changed

3 files changed

+379
-207
lines changed

python/packages/core/agent_framework/_agents.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@
3333
from ._mcp import LOG_LEVEL_MAPPING, MCPTool
3434
from ._middleware import AgentMiddlewareLayer, MiddlewareTypes
3535
from ._serialization import SerializationMixin
36-
from ._sessions import AgentSession, BaseContextProvider, BaseHistoryProvider, InMemoryHistoryProvider, SessionContext
36+
from ._sessions import (
37+
AgentSession,
38+
BaseContextProvider,
39+
BaseHistoryProvider,
40+
InMemoryHistoryProvider,
41+
SessionContext,
42+
)
3743
from ._tools import (
3844
FunctionInvocationLayer,
3945
FunctionTool,
@@ -532,7 +538,14 @@ async def agent_wrapper(**kwargs: Any) -> str:
532538

533539
if stream_callback is None:
534540
# Use non-streaming mode
535-
return (await self.run(input_text, stream=False, session=parent_session, **forwarded_kwargs)).text
541+
return (
542+
await self.run(
543+
input_text,
544+
stream=False,
545+
session=parent_session,
546+
**forwarded_kwargs,
547+
)
548+
).text
536549

537550
# Use streaming mode - accumulate updates and create final response
538551
response_updates: list[AgentResponseUpdate] = []
@@ -951,7 +964,9 @@ async def _get_stream() -> ResponseStream[ChatResponseUpdate, ChatResponse[Any]]
951964
**ctx["filtered_kwargs"],
952965
)
953966

954-
def _propagate_conversation_id(update: AgentResponseUpdate) -> AgentResponseUpdate:
967+
def _propagate_conversation_id(
968+
update: AgentResponseUpdate,
969+
) -> AgentResponseUpdate:
955970
"""Eagerly propagate conversation_id to session as updates arrive.
956971
957972
This ensures session.service_session_id is set even when the user
@@ -975,8 +990,8 @@ def _finalizer(updates: Sequence[AgentResponseUpdate]) -> AgentResponse[Any]:
975990
return self._finalize_response_updates(updates, response_format=rf)
976991

977992
return (
978-
ResponseStream # type: ignore[reportUnknownMemberType]
979-
.from_awaitable(_get_stream())
993+
ResponseStream
994+
.from_awaitable(_get_stream()) # type: ignore[reportUnknownMemberType]
980995
.map(
981996
transform=partial(
982997
map_chat_to_agent_update,
@@ -1002,7 +1017,9 @@ def _finalize_response_updates(
10021017
)
10031018

10041019
@staticmethod
1005-
def _extract_conversation_id_from_streaming_response(response: AgentResponse[Any]) -> str | None:
1020+
def _extract_conversation_id_from_streaming_response(
1021+
response: AgentResponse[Any],
1022+
) -> str | None:
10061023
"""Extract conversation_id from streaming raw updates, if present."""
10071024
raw = response.raw_representation
10081025
if raw is None:
@@ -1039,15 +1056,18 @@ async def _prepare_run_context(
10391056

10401057
input_messages = normalize_messages(messages)
10411058

1059+
# `store` in runtime or agent options takes precedence over client-level storage
1060+
# indicators. An explicit `store=False` forces local (in-memory) history injection,
1061+
# even if the client is configured to use service-side storage by default.
1062+
store_ = opts.get("store", self.default_options.get("store", getattr(self.client, "STORES_BY_DEFAULT", False)))
10421063
# Auto-inject InMemoryHistoryProvider when session is provided, no context providers
10431064
# registered, and no service-side storage indicators
10441065
if (
10451066
session is not None
10461067
and not self.context_providers
10471068
and not session.service_session_id
10481069
and not opts.get("conversation_id")
1049-
and not opts.get("store")
1050-
and not (getattr(self.client, "STORES_BY_DEFAULT", False) and opts.get("store") is not False)
1070+
and not store_
10511071
):
10521072
self.context_providers.append(InMemoryHistoryProvider())
10531073

0 commit comments

Comments
 (0)