Skip to content

fix(cli): enable arrow-key history and line editing in adk run - #8023

Open
Stephnn0 wants to merge 2 commits into
google:mainfrom
Stephnn0:fix/cli-input-history
Open

Stephnn0 wants to merge 2 commits into
google:mainfrom
Stephnn0:fix/cli-input-history

Conversation

@Stephnn0

@Stephnn0 Stephnn0 commented Nov 7, 2026

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
adk run reads user input with input(), which only supports arrow keys and history once readline is imported. The CLI never imported it, so pressing arrow up printed ^[[A and sent the raw escape sequence to the agent.

Solution:
Add _enable_line_editing(), which imports readline and is called at the start of run_interactively. Where readline is unavailable (Windows), it does nothing.

Testing Plan

Unit Tests:

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

Added three tests in tests/unittests/cli/utils/test_cli.py:

  • test_enable_line_editing_imports_readline
  • test_enable_line_editing_without_readline
  • test_run_interactively_enables_line_editing
$ pytest tests/unittests/cli -n auto
1654 passed, 5 skipped, 1 xfailed

With the fix removed, test_enable_line_editing_imports_readline and test_run_interactively_enables_line_editing fail.

Manual End-to-End (E2E) Tests:

Ran the CLI input path in a pseudo-terminal: typed hello + Enter, then arrow up + Enter, and printed the two values input() returned.

before fix -> 'hello' '\x1b[A'
after fix  -> 'hello' 'hello'

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.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

adk run --reload_agents reads input through sys.stdin.readline() in a background thread, so it is not covered by this change. It can be handled in a follow-up if wanted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SXKq7AVswkhFGAQZqanCsM

@google-cla

google-cla Bot commented Nov 7, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

input() only supports arrow keys and history once the readline module
is imported, and the CLI never imported it. Pressing arrow up in
`adk run` printed `^[[A` instead of recalling the previous message.

Import readline when the interactive session starts. Skip it where
readline is unavailable, such as Windows.
@Stephnn0
Stephnn0 force-pushed the fix/cli-input-history branch from d2720f7 to 4772120 Compare November 12, 2026 10:10
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.

adk run does not support arrow keys or input history

2 participants