mirror of
https://github.com/usestrix/strix.git
synced 2026-08-22 19:09:37 +02:00
fix(context): bound native filesystem tool output in Responses mode
Chat-completions mode converts filesystem CustomTools to FunctionTools (which bounds their result), but the Responses-API path kept them native and unbounded, so a large read_file could still exhaust the context window. Always configure the Filesystem capability to head+tail bound tool output in both modes.
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
from typing import Any, cast
|
||||
|
||||
import pytest
|
||||
from agents.tool import FunctionTool
|
||||
from agents.tool import CustomTool, FunctionTool
|
||||
|
||||
from strix.agents import factory
|
||||
from strix.config import load_settings
|
||||
@@ -77,3 +78,35 @@ async def test_wrap_exec_command_preserves_explicit_shell(shell: str) -> None:
|
||||
)
|
||||
|
||||
assert json.loads(captured["raw_input"])["shell"] == shell
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_responses_filesystem_custom_tool_output_is_bounded() -> None:
|
||||
# In Responses-API mode filesystem tools stay native CustomTools; a large
|
||||
# read must still be head+tail bounded before it enters history.
|
||||
async def invoke(_ctx: Any, _inp: str) -> str:
|
||||
return "line\n" * 50_000
|
||||
|
||||
toolset = SimpleNamespace(
|
||||
read_file=CustomTool(name="read_file", description="read", on_invoke_tool=invoke)
|
||||
)
|
||||
factory._configure_filesystem_tools(toolset, chat_completions=False)
|
||||
|
||||
assert isinstance(toolset.read_file, CustomTool)
|
||||
result = await toolset.read_file.on_invoke_tool(cast("Any", None), "{}")
|
||||
|
||||
assert "truncated" in result
|
||||
assert len(result) < len("line\n" * 50_000)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_chat_completions_filesystem_custom_tool_becomes_function_tool() -> None:
|
||||
async def invoke(_ctx: Any, _inp: str) -> str:
|
||||
return "ok"
|
||||
|
||||
toolset = SimpleNamespace(
|
||||
read_file=CustomTool(name="read_file", description="read", on_invoke_tool=invoke)
|
||||
)
|
||||
factory._configure_filesystem_tools(toolset, chat_completions=True)
|
||||
|
||||
assert isinstance(toolset.read_file, FunctionTool)
|
||||
|
||||
Reference in New Issue
Block a user