-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add CLI coding agent sample #4253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LiamConnell
wants to merge
1
commit into
google:main
Choose a base branch
from
LiamConnell:add-cli-coding-agent-sample
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+951
β0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| **/__pycache__/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # ADK CLI Coding Agent | ||
|
|
||
| An AI coding assistant built with Google ADK featuring file system operations, task planning, and colorful interactive CLI output. | ||
|
|
||
| **This is a toy example! It is not meant to be a replacement for fully featured products like the Gemini CLI or Claude Code.** | ||
|
|
||
|
|
||
|  | ||
|
|
||
| ## Features | ||
|
|
||
|
|
||
| **File System Tools** | ||
| - `read_file` - Read file contents with metadata | ||
| - `write_file` - Create or overwrite files | ||
| - `update_file` - Replace text within files | ||
| - `list_directory` - List files/directories with glob patterns | ||
|
|
||
| **Task Planning** | ||
| - `create_plan` - Break down complex tasks into steps | ||
| - `update_plan` - Mark tasks as completed | ||
| - `get_plan` - View current plan and progress | ||
| - `reset_plan` - Clear completed plan | ||
|
|
||
| **Colorful Terminal UI** | ||
| - Interactive CLI with color-coded output | ||
| - Progress tracking with visual task lists | ||
| - Concise/verbose output modes | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. **Navigate to this sample directory:** | ||
| ```bash | ||
| cd contributing/samples/cli_coding_agent | ||
| ``` | ||
|
|
||
| 2. **Install dependencies:** | ||
| ```bash | ||
| uv pip install -r requirements.txt | ||
| ``` | ||
|
|
||
| 3. **Authenticate with Google Cloud:** | ||
| ```bash | ||
| gcloud auth application-default login | ||
| ``` | ||
|
|
||
| 4. **Run the agent:** | ||
| ```bash | ||
| uv run python -m agent | ||
| ``` | ||
|
|
||
| Or use ADK's built-in web interface: | ||
| ```bash | ||
| adk web agent | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| The agent automatically creates plans for multi-step tasks (3+ steps) and tracks progress: | ||
|
|
||
| ``` | ||
| [You]: Help me refactor this codebase | ||
|
|
||
| π PLAN: Refactor Codebase | ||
| Progress: [ββββββββββββ] 2/3 (67%) | ||
| β [0] Analyze current structure | ||
| β [1] Extract common utilities | ||
| β [2] Update imports and tests | ||
|
|
||
| π§ update_file(file_path=utils.py, old_text=...) | ||
| β update_file | ||
| ``` | ||
|
|
||
| **Commands:** | ||
| - `exit/quit` - Exit the assistant | ||
| - `verbose` - Toggle verbose tool output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """Coding agent package for file system operations with ADK.""" | ||
|
|
||
| import logging | ||
| from pathlib import Path | ||
| import sys | ||
|
|
||
| from dotenv import load_dotenv | ||
|
|
||
| # Load environment variables | ||
| load_dotenv() | ||
|
|
||
|
|
||
| def setup_logging( | ||
| level=logging.INFO, log_file='coding_agent.log', quiet_adk=True | ||
| ): | ||
| """Configure logging for the coding agent package. | ||
|
|
||
| Args: | ||
| level: Logging level (default: INFO) | ||
| log_file: Path to log file (default: 'coding_agent.log') | ||
| quiet_adk: If True, set ADK loggers to WARNING level (default: True) | ||
| """ | ||
| # Create formatters | ||
| detailed_formatter = logging.Formatter( | ||
| '%(asctime)s - %(name)s - %(levelname)s - %(message)s', | ||
| datefmt='%Y-%m-%d %H:%M:%S', | ||
| ) | ||
|
|
||
| # Console handler (simple format) | ||
| console_handler = logging.StreamHandler(sys.stdout) | ||
| console_handler.setLevel(level) | ||
| console_handler.setFormatter(detailed_formatter) | ||
|
|
||
| # File handler (detailed format) | ||
| log_path = Path(log_file) | ||
| file_handler = logging.FileHandler(log_path) | ||
| file_handler.setLevel(logging.DEBUG) # Log everything to file | ||
| file_handler.setFormatter(detailed_formatter) | ||
|
|
||
| # Configure root logger | ||
| root_logger = logging.getLogger() | ||
| root_logger.setLevel(logging.DEBUG) | ||
| root_logger.addHandler(console_handler) | ||
| root_logger.addHandler(file_handler) | ||
|
|
||
| # Quiet down noisy libraries | ||
| if quiet_adk: | ||
| logging.getLogger('google_adk').setLevel(logging.WARNING) | ||
| logging.getLogger('google.genai').setLevel(logging.WARNING) | ||
| logging.getLogger('google_genai.types').setLevel(logging.ERROR) | ||
| logging.getLogger('httpx').setLevel(logging.WARNING) | ||
| logging.getLogger('httpcore').setLevel(logging.WARNING) | ||
| logging.getLogger('google_genai.models').setLevel(logging.WARNING) | ||
|
|
||
| return logging.getLogger(__name__) | ||
|
|
||
|
|
||
| # Initialize logging | ||
| logger = setup_logging() | ||
| logger.info('Coding agent package initialized') | ||
|
|
||
| # Import agent after logging is configured | ||
| from . import agent | ||
|
|
||
| __all__ = ['agent', 'logger', 'setup_logging'] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Configuring the root logger directly can be risky. If
setup_loggingis called multiple times (e.g., during tests or reloads), it will add duplicate handlers, leading to repeated log messages. It's safer to clear any existing handlers before adding new ones to make the function idempotent.