Skip to content

Commit ff3a937

Browse files
committed
feat: enable retrieval tool by default, update tool spec prompt
1 parent 19bb6d4 commit ff3a937

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

src/strands/vended_plugins/context_offloader/plugin.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from ...tools.decorator import tool
4343
from ...types.content import Message
4444
from ...types.tools import ToolContext, ToolResult, ToolResultContent
45-
from .storage import InMemoryStorage, Storage
45+
from .storage import Storage
4646

4747
if 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 += "\nYou can also use retrieve_offloaded_content with a reference to get the full content."
276+
guidance += (
277+
"\nOnly 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"

tests/strands/vended_plugins/context_offloader/test_plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,14 @@ def test_retrieval_tool_registered_when_enabled(self, plugin):
468468
tool_names = [t.tool_name for t in plugin.tools]
469469
assert "retrieve_offloaded_content" in tool_names
470470

471-
def test_retrieval_tool_registered_by_default_for_inmemory(self):
471+
def test_retrieval_tool_registered_by_default(self):
472472
plugin = ContextOffloader(storage=InMemoryStorage())
473473
plugin.init_agent(MagicMock())
474474
tool_names = [t.tool_name for t in plugin.tools]
475475
assert "retrieve_offloaded_content" in tool_names
476476

477-
def test_retrieval_tool_not_registered_by_default_for_file_storage(self, tmp_path):
478-
plugin = ContextOffloader(storage=FileStorage(artifact_dir=str(tmp_path)))
477+
def test_retrieval_tool_not_registered_when_disabled(self):
478+
plugin = ContextOffloader(storage=InMemoryStorage(), include_retrieval_tool=False)
479479
plugin.init_agent(MagicMock())
480480
tool_names = [t.tool_name for t in plugin.tools]
481481
assert "retrieve_offloaded_content" not in tool_names

0 commit comments

Comments
 (0)