Repository navigation
docs: Add code assistant tutorial - #1386
Rajkumar7633 wants to merge 1 commit into
Conversation
|
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. |
339221f to
c64aa51
Compare
Rajkumar7633
left a comment
There was a problem hiding this comment.
No existing issue. This PR adds:
-
New code assistant tutorial feature
-
Critical code quality improvements (unsafe Optional.get() fixes)
Problem: -
Missing code assistant tutorial for developers
-
Unsafe Optional.get() calls that could cause NoSuchElementException crashes
-
Inconsistent error handling in LLM flow processing
Solution: -
Added new code-assistant tutorial with 4 tools (generate, review, explain, debug code)
-
Replaced unsafe .get() calls with orElseThrow() for better error handling
-
Added meaningful error messages for debugging
-
Removed duplicate condition checks
Testing Plan:
Unit Tests:
- All 24 modules pass successfully (BUILD SUCCESS)
- ./mvnw test completed in 2:23 min with no failures
Manual E2E Tests:
- Tested code assistant tutorial with GOOGLE_API_KEY
- Verified all 4 tools work correctly via web interface
- Tested existing tutorials still work after changes
|
Hi @Rajkumar7633, thank you for your contribution! We appreciate you taking the time to submit this pull request. To proceed with the review, could you please address the following,
|
46ef6dd to
da774e6
Compare
|
@Rajkumar7633, thank you for addressing the feedback and squashing your commits, Currently this PR is under review by our team, we will keep you posted if any additional information is required. thank you |
damianmomotgoogle
left a comment
There was a problem hiding this comment.
Please also keep PR as single commit and update both commit message and PR title to follow conventional commits.
As this looks to be example/tutorial you could use docs: Add code assistant tutorial
| .modelName() | ||
| .orElseThrow( | ||
| () -> | ||
| new IllegalStateException( |
There was a problem hiding this comment.
This looks like behavior change - if needed please contribute it in a separate PR - this one should be limited to code assistant tutorial itself
| .outputSchema() | ||
| .orElseThrow( | ||
| () -> | ||
| new IllegalStateException( |
There was a problem hiding this comment.
Same ask to keep core logic changes to a separate PR
| } | ||
|
|
||
| int finalConfirmationEventIndex = confirmationResult.get().eventIndex(); | ||
| ConfirmationResult result = |
There was a problem hiding this comment.
Same ask to move core logic changes to a separate PR
96fe2b4 to
9ec717b
Compare
9ec717b to
2f2cf0d
Compare
|
All feedback addressed: core changes moved to #1809, PR is now limited to the code assistant tutorial, squashed to a single conventional commit ( |
| <artifactId>google-adk-tutorials-code-assistant</artifactId> | ||
| <name>Agent Development Kit - Tutorial: Code Assistant</name> | ||
| <description>Code Assistant Agent Tutorial</description> | ||
|
|
There was a problem hiding this comment.
Running mvn exec:java from the README currently fails with The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:3.6.3:java are missing or invalid. Please set exec.mainClass like the other tutorials (and drop the spring-boot-maven-plugin block below):
| <properties> | |
| <exec.mainClass>com.google.adk.tutorials.CodeAssistant</exec.mainClass> | |
| </properties> | |
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| <configuration> | ||
| <mainClass>com.google.adk.tutorials.CodeAssistant</mainClass> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> |
There was a problem hiding this comment.
Two things here:
spring-boot-maven-pluginhas no version and is not managed in the parent, so it resolves to whatever is latest today (4.2.0-M2, a milestone). Withexec.mainClassset above, it isn't needed.- This module shouldn't be published to Maven Central. Releases run
./mvnw -Prelease deployacross the whole reactor, so without a skip it ships asgoogle-adk-tutorials-code-assistant.-Dmaven.deploy.skip/<maven.deploy.skip>doesn't work because the rootpom.xmlhard-codes<skip>false</skip>onmaven-deploy-plugin; override the plugin configuration in this module instead:
| <build> | |
| <plugins> | |
| <plugin> | |
| <groupId>org.springframework.boot</groupId> | |
| <artifactId>spring-boot-maven-plugin</artifactId> | |
| <configuration> | |
| <mainClass>com.google.adk.tutorials.CodeAssistant</mainClass> | |
| </configuration> | |
| </plugin> | |
| </plugins> | |
| </build> | |
| <build> | |
| <plugins> | |
| <plugin> | |
| <!-- Tutorial only: keep it out of the Maven Central release. --> | |
| <artifactId>maven-deploy-plugin</artifactId> | |
| <configuration> | |
| <skip>true</skip> | |
| </configuration> | |
| </plugin> | |
| </plugins> | |
| </build> |
With both changes, mvn exec:java starts the server and ./mvnw -Prelease deploy -pl tutorials/code-assistant logs Skipping artifact deployment.
| FunctionTool.create(CodeAssistant.class, "debugCode")) | ||
| .build(); | ||
|
|
||
| public static Map<String, String> generateCode( |
There was a problem hiding this comment.
The four tools don't perform any work: each only echoes its arguments back with a "request received" message while the model does the actual generation, review, and explanation itself. Because the agent would behave the same without them, the tutorial doesn't demonstrate what function tools are for, and the tests only verify that the maps are echoed.
Please give the tools real, deterministic behavior the model can't do on its own.
| public static final BaseAgent ROOT_AGENT = | ||
| LlmAgent.builder() | ||
| .name("code_assistant") | ||
| .model("gemini-2.0-flash") |
There was a problem hiding this comment.
nit: gemini-2.0-flash is an older model; please use a current one (and update the README to match).
2f2cf0d to
6c162d9
Compare
|
Addressed all review feedback:
|
6c162d9 to
73a7073
Compare
|
Polish pass on top of the previous fixes: templates now use Java text blocks via a lookup map (easier to read/extend), all public tool methods are null-safe, diagnostics rules were tightened to avoid false positives, and every line stays within the 100-column style limit. Re-verified end to end: |
Add a new code-assistant tutorial module whose function tools perform real deterministic work: code metrics analysis, static review checks, canonical snippet templates, and rule-based debugging diagnostics. Includes a README and unit tests.
73a7073 to
c28c2d2
Compare
Description
This PR adds a new code assistant tutorial to the
tutorials/modules.New Features
code-assistanttutorial module with 4 function tools that perform real deterministic work the model cannot do on its own:analyzeCode— computes exact structural metrics (line counts, brace balance, TODO markers, long lines, trailing whitespace)reviewCode— runs static checks (System.out usage, empty catch blocks, string==comparisons, unboundedwhile (true)loops)generateSnippet— returns canonical templates for common constructs (hello_world,function,class,main) in Java, Python, and JavaScriptdebugCode— applies rule-based diagnostics for common errors (NullPointerException, IndexOutOfBounds, StackOverflow, syntax errors, etc.)CodeAssistant.javausing thegemini-2.5-flashmodelpom.xmlto include the new moduleexec.mainClass(like other tutorials) and overridesmaven-deploy-pluginwith<skip>true</skip>so it stays out of the Maven Central releaseTesting
Unit Tests
Added
CodeAssistantTest.javawith 12 unit tests covering:analyzeCodemetrics and brace-balance detection (2 tests)reviewCodefindings and clean-code verdict (2 tests)generateSnippettemplates for Java/Python and unsupported constructs (3 tests)debugCodediagnostics for NPE, unmatched errors, and syntax errors (3 tests)ROOT_AGENTvalidation (2 tests)All 12 unit tests pass successfully (
./mvnw test -pl tutorials/code-assistant).Manual E2E Tests
mvn exec:javaboots the ADK web server with thecode_assistantagent registeredmvn deploylogsSkipping artifact deployment