4242from ...tools .decorator import tool
4343from ...types .content import Message
4444from ...types .tools import ToolContext , ToolResult , ToolResultContent
45- from .storage import InMemoryStorage , Storage
45+ from .storage import Storage
4646
4747if TYPE_CHECKING :
4848 from ...agent .agent import Agent
@@ -88,7 +88,7 @@ class ContextOffloader(Plugin):
8888 max_result_tokens: Offload results whose estimated token count exceeds this threshold.
8989 preview_tokens: Number of tokens to keep as a text preview in context.
9090 include_retrieval_tool: Whether to register the ``retrieve_offloaded_content`` tool.
91- Defaults to False .
91+ Defaults to True .
9292
9393 Example:
9494 ```python
@@ -109,7 +109,7 @@ def __init__(
109109 max_result_tokens : int = _DEFAULT_MAX_RESULT_TOKENS ,
110110 preview_tokens : int = _DEFAULT_PREVIEW_TOKENS ,
111111 * ,
112- include_retrieval_tool : bool | None = None ,
112+ include_retrieval_tool : bool = True ,
113113 ) -> None :
114114 """Initialize the ContextOffloader plugin.
115115
@@ -121,9 +121,7 @@ def __init__(
121121 Uses tiktoken for exact slicing when available, falls back to
122122 chars/4 heuristic. Defaults to ``_DEFAULT_PREVIEW_TOKENS`` (1,000).
123123 include_retrieval_tool: Whether to register the ``retrieve_offloaded_content``
124- tool so the agent can fetch offloaded content. Defaults to True for
125- ``InMemoryStorage`` (where the retrieval tool is the only access
126- method) and False for other backends.
124+ tool so the agent can fetch offloaded content. Defaults to True.
127125
128126 Raises:
129127 ValueError: If max_result_tokens is not positive, preview_tokens is negative,
@@ -136,9 +134,6 @@ def __init__(
136134 if preview_tokens >= max_result_tokens :
137135 raise ValueError ("preview_tokens must be less than max_result_tokens" )
138136
139- if include_retrieval_tool is None :
140- include_retrieval_tool = isinstance (storage , InMemoryStorage )
141-
142137 self ._storage = storage
143138 self ._max_result_tokens = max_result_tokens
144139 self ._preview_tokens = preview_tokens
@@ -278,7 +273,10 @@ async def _handle_tool_result(self, event: AfterToolCallEvent) -> None:
278273 "Use your available tools to selectively access the data you need."
279274 )
280275 if self ._include_retrieval_tool :
281- guidance += "\n You can also use retrieve_offloaded_content with a reference to get the full content."
276+ guidance += (
277+ "\n Only use retrieve_offloaded_content as a fallback"
278+ " if the data cannot be accessed using your existing tools."
279+ )
282280
283281 preview_text = (
284282 f"[Offloaded: { len (content )} blocks, ~{ token_count :,} tokens]\n "
0 commit comments