feat: Add --dev flag to adk run for watchdog-based hot-reloading#4670
feat: Add --dev flag to adk run for watchdog-based hot-reloading#4670notnotdurgesh wants to merge 8 commits intogoogle:mainfrom
Conversation
Implemented real-time automatic agent reloading during interactive CLI sessions. - Added --dev option to cli_tools_click.py. - Integrated watchdog.events.FileSystemEventHandler in cli.py to monitor .py and .yaml changes. - Refactored un_interactively to multiplex sys.stdin.readline inside a daemon thread alongside �syncio.wait(reload_event.wait()) for non-blocking reload. - Used AgentLoader.remove_agent_from_cache to force module cache flushing and instantly reload logic while preserving session_service context. - Added async unit tests in est_cli.py to cover multiplexing agent transitions.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a --dev flag for hot-reloading, which is a great feature for improving the developer workflow. The implementation correctly uses watchdog for file monitoring and asyncio with a separate thread for non-blocking standard input, which are solid choices.
I've identified a couple of areas for improvement:
- A high-severity bug in the error handling of the hot-reload logic that could crash the interactive session if an agent fails to load.
- A medium-severity issue with a broad exception clause that could hide bugs in the input reading thread.
Addressing these points will make the new feature more robust. The addition of unit tests for the new functionality is also a positive contribution.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a --dev flag for hot-reloading agents, a significant improvement for the developer workflow. The implementation correctly uses watchdog for file monitoring and a threaded, non-blocking approach for terminal input with asyncio. My review includes suggestions to enhance the robustness of the file change detection by handling file deletions and moves, and a minor style improvement in the new unit tests to adhere to PEP 8 guidelines.
There was a problem hiding this comment.
Code Review
This pull request introduces a very useful --dev flag for hot-reloading, which will significantly improve the developer experience. The implementation using watchdog for file monitoring and asyncio with a separate thread for non-blocking input is well-designed. The agent reloading logic appears robust, gracefully handling failures and preserving session state. I have one suggestion to improve the file change detection to make it even more comprehensive.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a --dev flag for hot-reloading, which is a great enhancement for developer experience. The implementation uses watchdog for file monitoring and a combination of threading and asyncio to handle user input without blocking the event loop, which is a solid approach. The code is well-structured, with proper resource management for the file observer. I've identified a potential deadlock issue in the stdin reading thread that could cause the CLI to hang on EOF, and I've provided a suggestion to fix it. I also have a minor suggestion to improve code clarity by refactoring a magic value into a constant.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a --dev flag for hot-reloading, which is a great enhancement for the developer experience. The implementation using watchdog for file monitoring and asyncio with a separate thread for non-blocking input is robust and well-structured. The stateful agent swapping correctly preserves the session context while updating the agent's logic. The addition of a comprehensive unit test proves the reliability of the new functionality. I have one minor suggestion to improve the robustness of the file watching path logic.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a --dev flag for hot-reloading, which is a great feature for improving developer workflow. The implementation is robust, using watchdog for file monitoring and a non-blocking approach with asyncio and threading for handling user input. The stateful agent swapping preserves conversation history, which is a key part of the solution. The changes are well-tested with both unit and manual E2E tests. My feedback includes a couple of suggestions to improve code structure and maintainability by refactoring duplicated code and extracting complex logic into helper functions.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a --dev flag for hot-reloading, which is a great enhancement for the developer experience. The implementation correctly uses watchdog for file monitoring and a combination of threading and asyncio to handle non-blocking standard input and agent reloading. The code is well-structured, with proper resource management for the watchdog observer and graceful handling of reload errors. The new unit test effectively validates the core hot-reloading logic. I have one suggestion to improve code clarity by using nonlocal instead of a list reference.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a --dev flag to adk run for hot-reloading agents, which is a great enhancement for the developer experience. The implementation uses watchdog for file monitoring and cleverly combines asyncio with a separate thread for non-blocking stdin, which is a solid approach. The code is well-structured, with good separation of concerns and proper resource cleanup (like the Observer thread). I have one minor suggestion to improve exception logging for better debuggability.
|
Hi @ryanaiagent, I’ve resolved the previous conflicts and created a new PR with the updated changes. Kindly review it when you have a chance. Thank you! |
Link to Issue or Description of Change
Closes: #3679
Problem:
When developing and debugging agents in the ADK CLI, developers must continuously stop and restart the Python process every time they modify their
.pytool definitions or.yamlprompt instructions. This creates friction and interrupts the flow.Solution:
Implemented a robust
--devhot-reloading functionality modeled identically to standard Node/nodemon web environments.Key features and optimizations include:
DevModeChangeHandlerthat natively monitors the active agent's directory. If any.pyor.yamlfiles change, it triggers an async threading event without restarting the CLI process.sys.stdin.readlineaway from the standardinput()lock. By throwing it onto a daemon thread and pushing lines into anasyncio.Queue,asyncio.wait(FIRST_COMPLETED)successfully multiplexes reading standard terminal input while simultaneously waiting for a watchdog reload event to fire.Runnergracefully closes, andAgentLoader.remove_agent_from_cacheselectively drops all loaded modules corresponding to that agent folder. A new agent instance is instantiated securely alongside the already existingsession_serviceandartifact_servicebindings, resulting in code logic instantly updating midway through an existing chat thread without dropping the historical context.Testing Plan
Unit Tests:
test_run_interactively_dev_reloadintests/unittests/cli/utils/test_cli.pywhich artificially mocks both stdin inputs and watchdog delays to mathematically prove the CLI intercepts the hot-replace loop successfully without losing any queries.pytest tests/unittests/cli/utils/test_cli.pyto confirm all 14 tests, including our file and artifact loader modifications correctly report passes (..............) universally on Windows.Manual End-to-End (E2E) Tests:
adk create my_test_agentinside a sandbox.adk run --dev my_test_agent.Auto-reload enabled - watching for file changes...my_test_agent/agent.pyand saved. Instantly visually validated the CLI safely paused blocking inputs, firedChanges detected, reloading agent..., flushed the Python cache, and correctly resumed listening to the exact same thread id.Checklist
Additional context
N/A