Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/google/adk/utils/_debug_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def flush_text() -> None:
text_buffer.clear()

for part in event.content.parts:
# Text parts are always shown regardless of verbose setting
if part.thought and not verbose:
continue

# Response text is shown regardless of verbose setting
# because they contain the actual agent responses users expect
if part.text:
text_buffer.append(part.text)
Expand Down
28 changes: 28 additions & 0 deletions tests/unittests/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,34 @@ async def test_run_debug_passes_get_session_config():
assert events[0].author == "test_agent"


@pytest.mark.parametrize("verbose", [False, True])
async def test_run_debug_hides_thoughts_unless_verbose(capsys, verbose):
"""Console verbosity does not remove thoughts from the returned events."""

class ThoughtAgent(BaseAgent):

async def _run_async_impl(self, ctx):
yield Event(
invocation_id=ctx.invocation_id,
author=self.name,
content=types.Content(
role="model",
parts=[
types.Part(text="thinking ", thought=True),
types.Part(text="answer"),
],
),
)

runner = runners.InMemoryRunner(agent=ThoughtAgent(name="test_agent"))

events = await runner.run_debug("hello", verbose=verbose)

expected = "thinking answer" if verbose else "answer"
assert capsys.readouterr().out == f"test_agent > {expected}\n"
assert events[0].content.parts[0].thought is True


@pytest.mark.asyncio
async def test_get_session_config_limits_events():
"""Verify that num_recent_events actually limits loaded events."""
Expand Down
23 changes: 23 additions & 0 deletions tests/unittests/utils/test_debug_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ def test_print_event_prints_text_with_author_prefix(capsys):
assert _lines(capsys) == ['agent > hello']


def test_print_event_hides_thought_text_when_not_verbose(capsys):
"""Thoughts are not concatenated into the final answer."""
print_event(
_event(
types.Part(text='thinking', thought=True),
types.Part(text='answer'),
)
)
assert _lines(capsys) == ['agent > answer']


def test_print_event_with_only_thoughts_prints_nothing(capsys):
"""An event containing only thoughts has no final answer to display."""
print_event(_event(types.Part(text='thinking', thought=True)))
assert _lines(capsys) == []


def test_print_event_keeps_thought_text_when_verbose(capsys):
"""Verbose output retains thought text for debugging."""
print_event(_event(types.Part(text='thinking', thought=True)), verbose=True)
assert _lines(capsys) == ['agent > thinking']


def test_print_event_coalesces_consecutive_text_parts_into_one_line(capsys):
# A streamed answer arrives as several text parts; repeating the author
# prefix per part would fragment one sentence across many lines.
Expand Down
Loading