Skip to content

fix: show a readable code language in verbose debug output - #8179

Open
takayoshi-makabe wants to merge 1 commit into
google:mainfrom
takayoshi-makabe:fix/debug-output-code-language
Open

takayoshi-makabe wants to merge 1 commit into
google:mainfrom
takayoshi-makabe:fix/debug-output-code-language

Conversation

@takayoshi-makabe

@takayoshi-makabe takayoshi-makabe commented Nov 16, 2026 •

Copy link
Copy Markdown

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

Problem: With Runner.run_debug(verbose=True), the shared event printer formats ExecutableCode.language, a types.Language enum, straight into the line. On Python 3.11+ (the minimum ADK supports) this renders the class name, and a part without a language falls back to 'code', which doubles the word:

code_agent > [Executing Language.PYTHON code...]
code_agent > [Executing code code...]
code_agent > [Executing Language.LANGUAGE_UNSPECIFIED code...]

The existing unit tests locked in Executing code code... and only loosely asserted the language line, so neither issue was caught.

Solution: Print the enum's value, and show code (language unknown) when the language is missing or LANGUAGE_UNSPECIFIED. LANGUAGE_UNSPECIFIED is produced in practice, e.g. by the Interactions API conversion in models/interactions_utils.py for non-Python code.

code_agent > [Executing PYTHON code...]
code_agent > [Executing code (language unknown)...]
code_agent > [Executing code (language unknown)...]

The change is limited to print_event() in utils/_debug_output.py, which only run_debug uses. adk run has its own printer in cli/cli.py and is not affected. Events returned by run_debug are unchanged.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All relevant unit tests pass locally.

The two existing executable-code tests are replaced by one parameterized test that asserts the exact line for an enum language, a missing language, and LANGUAGE_UNSPECIFIED.

pytest tests/unittests/utils/test_debug_output.py tests/unittests/test_runners.py -k 'print_event or run_debug' -q

Result: 21 passed, 242 deselected. On the base revision, test_debug_output.py has 3 failed, 15 passed: all three new cases fail. The full ADK suite was not run.

Manual End-to-End (E2E) Tests:

A deterministic BaseAgent yields three events with executable_code parts:
Language.PYTHON, no language, and LANGUAGE_UNSPECIFIED. It runs through the public InMemoryRunner.run_debug('run', verbose=True) entry point, with no model calls. The output before and after the change is shown above.

Script
import asyncio
from typing import AsyncGenerator

from google.adk.agents.base_agent import BaseAgent
from google.adk.agents.invocation_context import InvocationContext
from google.adk.events.event import Event
from google.adk.runners import InMemoryRunner
from google.genai import types


class CodeAgent(BaseAgent):
  async def _run_async_impl(
      self, ctx: InvocationContext
  ) -> AsyncGenerator[Event, None]:
    for language in (
        types.Language.PYTHON,
        None,
        types.Language.LANGUAGE_UNSPECIFIED,
    ):
      yield Event(
          author=self.name,
          invocation_id=ctx.invocation_id,
          content=types.Content(
              role='model',
              parts=[
                  types.Part(
                      executable_code=types.ExecutableCode(
                          code='x = 1', language=language
                      )
                  )
              ],
          ),
      )


asyncio.run(
    InMemoryRunner(agent=CodeAgent(name='code_agent')).run_debug(
        'run', verbose=True
    )
)

All repository pre-commit hooks pass on the changed files. Tested on macOS with Python 3.11.4.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • Relevant new and existing unit tests pass locally with my changes.
  • I have tested the change through the public runner end-to-end.
  • There are no dependent downstream changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants