fix: hide internal reasoning in progress
This commit is contained in:
@@ -202,19 +202,9 @@ class AgentLoop:
|
|||||||
|
|
||||||
if response.has_tool_calls:
|
if response.has_tool_calls:
|
||||||
if on_progress:
|
if on_progress:
|
||||||
# Only show stripped content and thinking blocks in progress, not reasoning_content
|
thought = self._strip_think(response.content)
|
||||||
# reasoning_content is internal thinking and should not be shown to users
|
if thought:
|
||||||
thoughts = [
|
await on_progress(thought)
|
||||||
self._strip_think(response.content),
|
|
||||||
*(
|
|
||||||
f"Thinking [{b.get('signature', '...')}]:\n{b.get('thought', '...')}"
|
|
||||||
for b in (response.thinking_blocks or [])
|
|
||||||
if isinstance(b, dict) and "signature" in b
|
|
||||||
),
|
|
||||||
]
|
|
||||||
combined_thoughts = "\n\n".join(filter(None, thoughts))
|
|
||||||
if combined_thoughts:
|
|
||||||
await on_progress(combined_thoughts)
|
|
||||||
await on_progress(self._tool_hint(response.tool_calls), tool_hint=True)
|
await on_progress(self._tool_hint(response.tool_calls), tool_hint=True)
|
||||||
|
|
||||||
tool_call_dicts = [
|
tool_call_dicts = [
|
||||||
|
|||||||
@@ -86,6 +86,36 @@ class TestMessageToolSuppressLogic:
|
|||||||
assert result is not None
|
assert result is not None
|
||||||
assert "Hello" in result.content
|
assert "Hello" in result.content
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_progress_hides_internal_reasoning(self, tmp_path: Path) -> None:
|
||||||
|
loop = _make_loop(tmp_path)
|
||||||
|
tool_call = ToolCallRequest(id="call1", name="read_file", arguments={"path": "foo.txt"})
|
||||||
|
calls = iter([
|
||||||
|
LLMResponse(
|
||||||
|
content="Visible<think>hidden</think>",
|
||||||
|
tool_calls=[tool_call],
|
||||||
|
reasoning_content="secret reasoning",
|
||||||
|
thinking_blocks=[{"signature": "sig", "thought": "secret thought"}],
|
||||||
|
),
|
||||||
|
LLMResponse(content="Done", tool_calls=[]),
|
||||||
|
])
|
||||||
|
loop.provider.chat = AsyncMock(side_effect=lambda *a, **kw: next(calls))
|
||||||
|
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||||
|
loop.tools.execute = AsyncMock(return_value="ok")
|
||||||
|
|
||||||
|
progress: list[tuple[str, bool]] = []
|
||||||
|
|
||||||
|
async def on_progress(content: str, *, tool_hint: bool = False) -> None:
|
||||||
|
progress.append((content, tool_hint))
|
||||||
|
|
||||||
|
final_content, _, _ = await loop._run_agent_loop([], on_progress=on_progress)
|
||||||
|
|
||||||
|
assert final_content == "Done"
|
||||||
|
assert progress == [
|
||||||
|
("Visible", False),
|
||||||
|
('read_file("foo.txt")', True),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class TestMessageToolTurnTracking:
|
class TestMessageToolTurnTracking:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user