Skip to content
This repository was archived by the owner on Jun 21, 2025. It is now read-only.

Commit 90e3b1b

Browse files
authored
chore: Update software engineer prompts (#19)
* chore: Update software engineer prompts * Completed tuning for now * Fix linter * Fix linter
1 parent 1417194 commit 90e3b1b

31 files changed

Lines changed: 1091 additions & 628 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ test-unit:
3838
test-integration:
3939
@echo "pytest -m integration tests/
4040

41+
test-e2e:
42+
@echo "Running end-to-end tests..."
43+
./scripts/run_e2e_tests.sh
44+
4145
test-coverage:
4246
@echo "Running tests with coverage..."
4347
uv run pytest tests/ --cov=code_agent --cov-config=pyproject.toml --cov-report=term --cov-report=html --cov-fail-under=80
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Choose Model Backend: 0 -> ML Dev, 1 -> Vertex
2+
GOOGLE_GENAI_USE_VERTEXAI=YOUR_VALUE_HERE
3+
# ML Dev backend config, ignore if using Vertex.
4+
GOOGLE_API_KEY=YOUR_VALUE_HERE
5+
6+
# Vertex backend config
7+
GOOGLE_CLOUD_PROJECT=YOUR_VALUE_HERE
8+
GOOGLE_CLOUD_LOCATION=YOUR_VALUE_HERE
9+
10+
# Places API
11+
GOOGLE_PLACES_API_KEY=YOUR_API_KEY_HERE
12+
13+
# GCS Storage Bucket name - for Agent Engine deployment test
14+
GOOGLE_CLOUD_STORAGE_BUCKET=YOUR_BUCKET_NAME_HERE
15+
16+
# Sample Scenario Path - Default is an empty itinerary
17+
# This will be loaded upon first user interaction.
18+
#
19+
# Uncomment one of the two, or create your own.
20+
#
21+
# TRAVEL_CONCIERGE_SCENARIO=eval/itinerary_seattle_example.json
22+
TRAVEL_CONCIERGE_SCENARIO=eval/itinerary_empty_default.json

code_agent/agent/software_engineer/README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ This sample demonstrates the use of Agent Development Kit to create an AI-powere
77
The Software Engineer Agent consists of multiple specialized sub-agents, each responsible for a specific aspect of software development:
88

99
1. **Code Review Agent**: Reviews code, identifies issues, and suggests improvements
10-
2. **Design Pattern Agent**: Recommends design patterns for specific problems
11-
3. **Testing Agent**: Helps generate test cases and testing strategies
12-
4. **Debugging Agent**: Assists with debugging issues
13-
5. **Documentation Agent**: Helps create documentation
14-
6. **DevOps Agent**: Provides guidance on CI/CD, deployment
10+
2. **Code Quality Agent**: Performs static analysis and provides detailed code quality improvements
11+
3. **Design Pattern Agent**: Recommends design patterns for specific problems
12+
4. **Testing Agent**: Helps generate test cases and testing strategies
13+
5. **Debugging Agent**: Assists with debugging issues
14+
6. **Documentation Agent**: Helps create documentation
15+
7. **DevOps Agent**: Provides guidance on CI/CD, deployment
1516

1617
## Agent Details
1718

@@ -30,6 +31,7 @@ The Software Engineer Agent uses a hierarchical architecture with a root agent o
3031
```
3132
root_agent
3233
├── code_review_agent
34+
├── code_quality_agent
3335
├── design_pattern_agent
3436
├── testing_agent
3537
├── debugging_agent
@@ -41,13 +43,16 @@ root_agent
4143

4244
* **Agents:**
4345
* `code_review_agent` - Reviews code, identifies issues, and suggests improvements
46+
* `code_quality_agent` - Performs static analysis and provides detailed code quality metrics and improvements
4447
* `design_pattern_agent` - Recommends design patterns for specific problems
4548
* `testing_agent` - Helps generate test cases and testing strategies
4649
* `debugging_agent` - Assists with debugging issues
4750
* `documentation_agent` - Helps create documentation
4851
* `devops_agent` - Provides guidance on CI/CD, deployment
4952
* **Tools:**
50-
* `code_analysis_tool` - Analyzes code for patterns, complexity, and potential issues
53+
* `analyze_code_tool` - Analyzes code for patterns, complexity, and potential issues using multiple static analysis engines
54+
* `get_analysis_issues_by_severity_tool` - Filters code issues by severity level
55+
* `suggest_code_fixes_tool` - Suggests specific fixes for identified code issues
5156
* `memory_tool` - Stores and retrieves information about the project context
5257
* **AgentTools:**
5358
* `pattern_recommendation_tool` - Recommends design patterns for specific problems
@@ -100,16 +105,21 @@ root_agent
100105
poetry install
101106
```
102107

103-
3. Set up environment variables:
108+
3. Install code analysis tool dependencies:
109+
```bash
110+
pip install -r code_analysis_requirements.txt
111+
```
112+
113+
4. Set up environment variables:
104114
- Copy `.env.example` to `.env`
105115
- Set the required environment variables
106116

107-
4. Authenticate your GCloud account:
117+
5. Authenticate your GCloud account:
108118
```bash
109119
gcloud auth application-default login
110120
```
111121

112-
5. Activate the virtual environment:
122+
6. Activate the virtual environment:
113123
```bash
114124
poetry shell
115125
```
@@ -143,6 +153,8 @@ adk web
143153

144154
Example usage:
145155
- "Can you review my code for potential issues?"
156+
- "Analyze the code quality in this file"
157+
- "Check this file for security vulnerabilities"
146158
- "I need help implementing a factory pattern in Python"
147159
- "Generate unit tests for this function"
148160
- "Help me debug this error"

code_agent/agent/software_engineer/pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ pydantic = "^2.10.6"
1919
python-dotenv = "^1.0.1"
2020
google-genai = "^1.9.0"
2121
google-adk = ">=0.0.2"
22+
pylint = ">=2.17.0" # Required for code analysis
23+
flake8 = ">=6.0.0" # Required for code analysis
24+
radon = ">=6.0.0" # Required for code analysis
25+
bandit = ">=1.7.5" # Required for code analysis
26+
eslint = ">=8.40.0" # Required for code analysis
2227

2328
[tool.poetry.group.dev]
2429
optional = true

code_agent/agent/software_engineer/software_engineer/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,4 @@
77
testing, debugging, documentation, and DevOps.
88
"""
99

10-
# Importing root_agent here causes circular dependency when structure is refactored for adk run
11-
# from ..agent import root_agent
12-
13-
# __all__ = ["root_agent"]
14-
15-
# NOTE: SWITCH TO ADK WEB or COMMENT OUT FOR ADK RUN
1610
from . import agent

code_agent/agent/software_engineer/software_engineer/agent.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,55 @@
22

33
# NOTE: SWITCH TO ADK WEB or COMMENT OUT FOR ADK RUN
44

5+
import logging
6+
57
from google.adk.agents import Agent
68

79
# from google.adk.runtime.executors import SequentialExecutor
810
# from google.adk.runtime.planner import SequentialPlanner
911
# Use relative imports from the 'software_engineer' sibling directory
1012
from . import prompt
13+
from .sub_agents.code_quality.agent import code_quality_agent
1114
from .sub_agents.code_review.agent import code_review_agent
1215
from .sub_agents.debugging.agent import debugging_agent
1316
from .sub_agents.design_pattern.agent import design_pattern_agent
1417
from .sub_agents.devops.agent import devops_agent
1518
from .sub_agents.documentation.agent import documentation_agent
1619
from .sub_agents.testing.agent import testing_agent
20+
21+
# Import the code search tool from the new location
22+
from .tools import codebase_search_tool
23+
from .tools.filesystem import (
24+
configure_approval_tool as configure_edit_approval_tool,
25+
)
1726
from .tools.filesystem import (
18-
configure_approval_tool,
1927
edit_file_tool,
2028
list_dir_tool,
2129
read_file_tool,
2230
)
31+
32+
# Import memory tools
33+
# from .tools.memory import forget_tool, memorize_list_tool, memorize_tool
2334
from .tools.project_context import load_project_context
2435
from .tools.search import google_search_grounding
2536

2637
# Updated import for shell command tools
2738
from .tools.shell_command import (
28-
check_shell_command_safety,
29-
configure_shell_approval,
30-
configure_shell_whitelist,
31-
execute_vetted_shell_command,
39+
check_command_exists_tool,
40+
check_shell_command_safety_tool,
41+
configure_shell_approval_tool,
42+
configure_shell_whitelist_tool,
43+
execute_vetted_shell_command_tool,
3244
)
33-
from .tools.system_info import check_command_exists, get_os_info
45+
from .tools.system_info import get_os_info_tool
46+
47+
logger = logging.getLogger(__name__)
48+
49+
# Note: Using custom ripgrep-based codebase search in tools/code_search.py
3450

3551
# REF: https://ai.google.dev/gemini-api/docs/rate-limits
3652
root_agent = Agent(
37-
model="gemini-2.5-flash-preview-04-17", # "gemini-2.5-pro-exp-03-25", #"gemini-2.0-flash-001",
53+
model="gemini-2.5-flash-preview-04-17",
3854
name="root_agent",
3955
description="An AI software engineer assistant that helps with various software development tasks",
4056
instruction=prompt.ROOT_AGENT_INSTR,
@@ -45,19 +61,25 @@
4561
debugging_agent,
4662
documentation_agent,
4763
devops_agent,
64+
code_quality_agent,
4865
],
4966
tools=[
50-
google_search_grounding,
5167
read_file_tool,
5268
list_dir_tool,
5369
edit_file_tool,
54-
configure_approval_tool,
55-
get_os_info,
56-
check_command_exists,
57-
configure_shell_approval,
58-
configure_shell_whitelist,
59-
check_shell_command_safety,
60-
execute_vetted_shell_command,
70+
configure_edit_approval_tool,
71+
check_command_exists_tool,
72+
check_shell_command_safety_tool,
73+
configure_shell_approval_tool,
74+
configure_shell_whitelist_tool,
75+
execute_vetted_shell_command_tool,
76+
google_search_grounding,
77+
codebase_search_tool,
78+
get_os_info_tool,
79+
# memorize_tool,
80+
# memorize_list_tool,
81+
# forget_tool,
6182
],
6283
before_agent_callback=load_project_context,
84+
output_key="software_engineer",
6385
)

code_agent/agent/software_engineer/software_engineer/prompt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
## Sub-Agent Delegation:
4444
- First, try to delegate the request to the most relevant sub-agent based on the descriptions below.
4545
- Inform the user that you are delegating the request to the sub-agent and the reason for the delegation.
46-
- If the user asks for code review or code quality improvements, transfer to the agent `code_review_agent`
46+
- If the user asks for code review, transfer to the agent `code_review_agent`
47+
- If the user asks for code quality analysis, static analysis, or quality improvements, transfer to the agent `code_quality_agent`
4748
- If the user asks about design patterns or architecture, transfer to the agent `design_pattern_agent`
4849
- If the user asks about testing, test generation, or test strategies, transfer to the agent `testing_agent`
4950
- If the user asks for help with debugging or fixing errors, transfer to the agent `debugging_agent`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Code quality sub-agent for analyzing code and suggesting improvements."""
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Code quality agent implementation."""
2+
3+
from google.adk.agents import Agent
4+
from google.genai.types import GenerateContentConfig
5+
6+
from ...tools.code_analysis import (
7+
analyze_code_tool,
8+
get_analysis_issues_by_severity_tool,
9+
suggest_code_fixes_tool,
10+
)
11+
from ...tools.filesystem import list_dir_tool, read_file_tool
12+
from . import prompt
13+
14+
code_quality_agent = Agent(
15+
model="gemini-2.5-flash-preview-04-17",
16+
name="code_quality_agent",
17+
description="Analyzes code for quality issues and suggests improvements",
18+
instruction=prompt.CODE_QUALITY_AGENT_INSTR,
19+
tools=[
20+
analyze_code_tool,
21+
get_analysis_issues_by_severity_tool,
22+
suggest_code_fixes_tool,
23+
read_file_tool,
24+
list_dir_tool,
25+
],
26+
generate_content_config=GenerateContentConfig(
27+
temperature=0.1,
28+
top_p=0.95,
29+
max_output_tokens=4096,
30+
),
31+
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ruff: noqa
2+
"""Prompts for the code quality sub-agent."""
3+
4+
CODE_QUALITY_AGENT_INSTR = """
5+
You are a Code Quality Expert specialized in analyzing code for quality issues, technical debt, and suggesting improvements.
6+
7+
Your primary responsibilities include:
8+
9+
1. Analyzing code using static analysis tools to identify issues like bugs, code smells, style violations,
10+
security vulnerabilities, and complexity problems.
11+
12+
2. Categorizing and prioritizing issues based on severity (critical, error, warning, info).
13+
14+
3. Explaining detected issues in a way that helps developers understand the problem and how to fix it.
15+
16+
4. Suggesting specific code improvements and refactorings to address identified issues.
17+
18+
5. Providing actionable recommendations to improve overall code quality.
19+
20+
6. Identifying patterns of issues that might indicate deeper architectural or design problems.
21+
22+
7. Highlighting security vulnerabilities and suggesting secure coding practices.
23+
24+
8. Analyzing code complexity and suggesting ways to simplify complicated code.
25+
26+
When a user asks you to analyze code:
27+
1. Use the analyze_code_tool to perform static analysis on the specified file
28+
2. Review the issues and metrics returned by the analysis
29+
3. Use get_analysis_issues_by_severity_tool to retrieve issues filtered by severity if needed
30+
4. Use suggest_code_fixes_tool to generate suggestions for fixing identified issues
31+
5. Provide a concise summary of the code quality assessment
32+
6. Focus on the most critical issues first, then errors, warnings, and finally informational issues
33+
7. Include specific, actionable recommendations for improving the code
34+
35+
Remember that your goal is to help developers write better, cleaner, more maintainable code.
36+
You should be thorough in your analysis but also practical in your recommendations.
37+
38+
## Context:
39+
40+
Current project context:
41+
<project_context>
42+
{project_context}
43+
</project_context>
44+
"""

0 commit comments

Comments
 (0)