Skip to content

Add ADK to TestLLM#937

Merged
rapids-bot[bot] merged 4 commits intoNVIDIA:release/1.3from
zhongxuanwang-nv:zxw_googleadk2testllm
Oct 7, 2025
Merged

Add ADK to TestLLM#937
rapids-bot[bot] merged 4 commits intoNVIDIA:release/1.3from
zhongxuanwang-nv:zxw_googleadk2testllm

Conversation

@zhongxuanwang-nv
Copy link
Member

@zhongxuanwang-nv zhongxuanwang-nv commented Oct 7, 2025

Description

Closes

This is a small PR that adds the test_llm as a LLM Client for Google ADK, with related tests.

Since in NAT we use ADK's LiteLLM, I did check what public functions/fields were implemented by LiteLLM and overrode them properly. [LiteLLM code source]

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

Summary by CodeRabbit

  • New Features

    • Added a Google ADK–compatible LLM client for NAT test utilities, providing deterministic, scriptable async responses for integration scenarios.
  • Tests

    • Added ADK-based integration tests validating ADK-driven function execution and deterministic outputs across single and repeated invocations.

Signed-off-by: Daniel Wang <daniewang@nvidia.com>
@zhongxuanwang-nv zhongxuanwang-nv self-assigned this Oct 7, 2025
@zhongxuanwang-nv zhongxuanwang-nv added improvement Improvement to existing functionality non-breaking Non-breaking change labels Oct 7, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 7, 2025

Walkthrough

Adds an ADK-backed test LLM client and registers it as an ADK LLM wrapper, plus two ADK-based integration tests that build and invoke a NAT function using that test LLM and assert deterministic outputs.

Changes

Cohort / File(s) Summary
ADK LLM wrapper
packages/nvidia_nat_test/src/nat/test/llm.py
Adds test_llm_adk(config: TestLLMConfig, builder: Builder) registered via @register_llm_client(..., wrapper_type=LLMFrameworkEnum.ADK). Introduces ADK import handling, _ResponseChooser, ADKTestLLM (subclass of BaseLlm) with generate_content_async producing LlmResponse, a no-op connect, and returns an instance configured with model="nat_test_llm".
Integration tests
packages/nvidia_nat_test/tests/test_test_llm.py
Adds two tests (test_adk_function_integration_returns_deterministic_text, test_adk_function_integration_multiple_invokes_cycle) that skip if google.adk is unavailable; each constructs an ADK-backed NAT function via ADKFunctionConfig/LLMRef, invokes it through the builder, and asserts deterministic single-call and repeated-call outputs.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Test
  participant Builder
  participant ADKLLM as ADKTestLLM
  participant Chooser as _ResponseChooser

  Test->>Builder: build function (ADKFunctionConfig, LLMRef)
  Builder->>ADKLLM: instantiate(model="nat_test_llm")
  Test->>Builder: invoke function
  Builder->>ADKLLM: generate_content_async(prompt, options)
  ADKLLM->>Chooser: request next response
  Chooser-->>ADKLLM: deterministic text
  ADKLLM-->>Builder: LlmResponse(content=text)
  Builder-->>Test: return function result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

feature request

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “Add ADK to TestLLM” clearly summarizes the main change by indicating that ADK support is being added to the TestLLM component, uses imperative mood, and is concise and under the character limit.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 21a5d51 and ec460f7.

📒 Files selected for processing (1)
  • packages/nvidia_nat_test/tests/test_test_llm.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nvidia_nat_test/tests/test_test_llm.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zhongxuanwang-nv
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Oct 7, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai bot added the feature request New feature or request label Oct 7, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 232e740 and 5f0bca2.

📒 Files selected for processing (2)
  • packages/nvidia_nat_test/src/nat/test/llm.py (1 hunks)
  • packages/nvidia_nat_test/tests/test_test_llm.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*

⚙️ CodeRabbit configuration file

**/*: # Code Review Instructions

  • Ensure the code follows best practices and coding standards. - For Python code, follow
    PEP 20 and
    PEP 8 for style guidelines.
  • Check for security vulnerabilities and potential issues. - Python methods should use type hints for all parameters and return values.
    Example:
    def my_function(param1: int, param2: str) -> bool:
        pass
  • For Python exception handling, ensure proper stack trace preservation:
    • When re-raising exceptions: use bare raise statements to maintain the original stack trace,
      and use logger.error() (not logger.exception()) to avoid duplicate stack trace output.
    • When catching and logging exceptions without re-raising: always use logger.exception()
      to capture the full stack trace information.

Documentation Review Instructions - Verify that documentation and comments are clear and comprehensive. - Verify that the documentation doesn't contain any TODOs, FIXMEs or placeholder text like "lorem ipsum". - Verify that the documentation doesn't contain any offensive or outdated terms. - Verify that documentation and comments are free of spelling mistakes, ensure the documentation doesn't contain any

words listed in the ci/vale/styles/config/vocabularies/nat/reject.txt file, words that might appear to be
spelling mistakes but are listed in the ci/vale/styles/config/vocabularies/nat/accept.txt file are OK.

Misc. - All code (except .mdc files that contain Cursor rules) should be licensed under the Apache License 2.0,

and should contain an Apache License 2.0 header comment at the top of each file.

  • Confirm that copyright years are up-to date whenever a file is changed.

Files:

  • packages/nvidia_nat_test/src/nat/test/llm.py
  • packages/nvidia_nat_test/tests/test_test_llm.py
packages/**/*

⚙️ CodeRabbit configuration file

packages/**/*: - This directory contains optional plugin packages for the toolkit, each should contain a pyproject.toml file. - The pyproject.toml file should declare a dependency on nvidia-nat or another package with a name starting
with nvidia-nat-. This dependency should be declared using ~=<version>, and the version should be a two
digit version (ex: ~=1.0).

  • Not all packages contain Python code, if they do they should also contain their own set of tests, in a
    tests/ directory at the same level as the pyproject.toml file.

Files:

  • packages/nvidia_nat_test/src/nat/test/llm.py
  • packages/nvidia_nat_test/tests/test_test_llm.py
🪛 Ruff (0.13.3)
packages/nvidia_nat_test/src/nat/test/llm.py

209-209: Unused function argument: builder

(ARG001)


217-218: Avoid specifying long messages outside the exception class

(TRY003)


224-224: Unused method argument: stream

(ARG002)

Signed-off-by: Daniel Wang <daniewang@nvidia.com>
@zhongxuanwang-nv zhongxuanwang-nv removed the feature request New feature or request label Oct 7, 2025
@zhongxuanwang-nv zhongxuanwang-nv marked this pull request as ready for review October 7, 2025 19:14
@zhongxuanwang-nv zhongxuanwang-nv requested a review from a team as a code owner October 7, 2025 19:14
@coderabbitai coderabbitai bot added the feature request New feature or request label Oct 7, 2025
@willkill07 willkill07 removed the feature request New feature or request label Oct 7, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
packages/nvidia_nat_test/src/nat/test/llm.py (1)

208-235: Add required type hints to all methods.

Per coding guidelines, all public APIs must have type hints on parameters and return values. The function and methods are missing return type annotations.

Apply this diff to add the required type hints:

+from typing import AsyncGenerator
+
 @register_llm_client(config_type=TestLLMConfig, wrapper_type=LLMFrameworkEnum.ADK)
-async def test_llm_adk(config: TestLLMConfig, builder: Builder):
+async def test_llm_adk(config: TestLLMConfig, builder: Builder) -> AsyncGenerator[Any, None]:
     """LLM client for Google ADK."""
 
     try:
         from google.adk.models.base_llm import BaseLlm
         from google.adk.models.llm_response import LlmResponse
         from google.genai import types
     except ImportError as exc:
         raise ImportError("Google ADK is required for using the test_llm with ADK. "
                           "Please install the `nvidia-nat-adk` package. ") from exc
 
     chooser = _ResponseChooser(response_seq=config.response_seq, delay_ms=config.delay_ms)
 
     class ADKTestLLM(BaseLlm):
 
         async def generate_content_async(self,
                                          llm_request: Any,
-                                         stream: bool = False) -> AsyncGenerator[LlmResponse, None]:
+                                         stream: bool = False) -> AsyncGenerator["LlmResponse", None]:
             self._maybe_append_user_content(llm_request)
             await chooser.async_sleep()
             text = chooser.next_response()
             yield LlmResponse(content=types.Content(role="model", parts=[types.Part.from_text(text=text)]))
 
-        def connect(self, *_args: Any, **_kwargs: Any) -> None:
+        def connect(self, *_args: Any, **_kwargs: Any) -> None:
             return None
 
     yield ADKTestLLM(model="nat_test_llm")

Note: AsyncGenerator is already imported at line 21. The return type annotation for generate_content_async should use a forward reference ("LlmResponse") since it's imported inside the function scope.

Based on coding guidelines and past review comments.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f0bca2 and 21a5d51.

📒 Files selected for processing (2)
  • packages/nvidia_nat_test/src/nat/test/llm.py (1 hunks)
  • packages/nvidia_nat_test/tests/test_test_llm.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{py,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/nat-test-llm.mdc)

**/*.{py,yaml,yml}: Configure response_seq as a list of strings; values cycle per call, and [] yields an empty string.
Configure delay_ms to inject per-call artificial latency in milliseconds for nat_test_llm.

Files:

  • packages/nvidia_nat_test/src/nat/test/llm.py
  • packages/nvidia_nat_test/tests/test_test_llm.py
**/*.py

📄 CodeRabbit inference engine (.cursor/rules/nat-test-llm.mdc)

**/*.py: Programmatic use: create TestLLMConfig(response_seq=[...], delay_ms=...), add with builder.add_llm("", cfg).
When retrieving the test LLM wrapper, use builder.get_llm(name, wrapper_type=LLMFrameworkEnum.) and call the framework’s method (e.g., ainvoke, achat, call).

**/*.py: In code comments/identifiers use NAT abbreviations as specified: nat for API namespace/CLI, nvidia-nat for package name, NAT for env var prefixes; do not use these abbreviations in documentation
Follow PEP 20 and PEP 8; run yapf with column_limit=120; use 4-space indentation; end files with a single trailing newline
Run ruff check --fix as linter (not formatter) using pyproject.toml config; fix warnings unless explicitly ignored
Respect naming: snake_case for functions/variables, PascalCase for classes, UPPER_CASE for constants
Treat pyright warnings as errors during development
Exception handling: use bare raise to re-raise; log with logger.error() when re-raising to avoid duplicate stack traces; use logger.exception() when catching without re-raising
Provide Google-style docstrings for every public module, class, function, and CLI command; first line concise and ending with a period; surround code entities with backticks
Validate and sanitize all user input, especially in web or CLI interfaces
Prefer httpx with SSL verification enabled by default and follow OWASP Top-10 recommendations
Use async/await for I/O-bound work; profile CPU-heavy paths with cProfile or mprof before optimizing; cache expensive computations with functools.lru_cache or external cache; leverage NumPy vectorized operations when beneficial

Files:

  • packages/nvidia_nat_test/src/nat/test/llm.py
  • packages/nvidia_nat_test/tests/test_test_llm.py
packages/*/src/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Importable Python code inside packages must live under packages//src/

Files:

  • packages/nvidia_nat_test/src/nat/test/llm.py
{src/**/*.py,packages/*/src/**/*.py}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

All public APIs must have Python 3.11+ type hints on parameters and return values; prefer typing/collections.abc abstractions; use typing.Annotated when useful

Files:

  • packages/nvidia_nat_test/src/nat/test/llm.py
**/*

⚙️ CodeRabbit configuration file

**/*: # Code Review Instructions

  • Ensure the code follows best practices and coding standards. - For Python code, follow
    PEP 20 and
    PEP 8 for style guidelines.
  • Check for security vulnerabilities and potential issues. - Python methods should use type hints for all parameters and return values.
    Example:
    def my_function(param1: int, param2: str) -> bool:
        pass
  • For Python exception handling, ensure proper stack trace preservation:
    • When re-raising exceptions: use bare raise statements to maintain the original stack trace,
      and use logger.error() (not logger.exception()) to avoid duplicate stack trace output.
    • When catching and logging exceptions without re-raising: always use logger.exception()
      to capture the full stack trace information.

Documentation Review Instructions - Verify that documentation and comments are clear and comprehensive. - Verify that the documentation doesn't contain any TODOs, FIXMEs or placeholder text like "lorem ipsum". - Verify that the documentation doesn't contain any offensive or outdated terms. - Verify that documentation and comments are free of spelling mistakes, ensure the documentation doesn't contain any

words listed in the ci/vale/styles/config/vocabularies/nat/reject.txt file, words that might appear to be
spelling mistakes but are listed in the ci/vale/styles/config/vocabularies/nat/accept.txt file are OK.

Misc. - All code (except .mdc files that contain Cursor rules) should be licensed under the Apache License 2.0,

and should contain an Apache License 2.0 header comment at the top of each file.

  • Confirm that copyright years are up-to date whenever a file is changed.

Files:

  • packages/nvidia_nat_test/src/nat/test/llm.py
  • packages/nvidia_nat_test/tests/test_test_llm.py
packages/**/*

⚙️ CodeRabbit configuration file

packages/**/*: - This directory contains optional plugin packages for the toolkit, each should contain a pyproject.toml file. - The pyproject.toml file should declare a dependency on nvidia-nat or another package with a name starting
with nvidia-nat-. This dependency should be declared using ~=<version>, and the version should be a two
digit version (ex: ~=1.0).

  • Not all packages contain Python code, if they do they should also contain their own set of tests, in a
    tests/ directory at the same level as the pyproject.toml file.

Files:

  • packages/nvidia_nat_test/src/nat/test/llm.py
  • packages/nvidia_nat_test/tests/test_test_llm.py
packages/*/tests/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

If a package contains Python code, include tests in a tests/ directory at the same level as pyproject.toml

Files:

  • packages/nvidia_nat_test/tests/test_test_llm.py
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: NVIDIA/NeMo-Agent-Toolkit#0
File: .cursor/rules/nat-test-llm.mdc:0-0
Timestamp: 2025-09-09T20:32:39.016Z
Learning: When stubbing deterministic LLM responses in tests/workflows, use the NAT Test LLM (nat_test_llm).
📚 Learning: 2025-09-09T20:32:39.016Z
Learnt from: CR
PR: NVIDIA/NeMo-Agent-Toolkit#0
File: .cursor/rules/nat-test-llm.mdc:0-0
Timestamp: 2025-09-09T20:32:39.016Z
Learning: Ensure nat.test.llm is importable (install nvidia-nat-test from packages/ or import nat.test.llm once) before use.

Applied to files:

  • packages/nvidia_nat_test/tests/test_test_llm.py
🧬 Code graph analysis (2)
packages/nvidia_nat_test/src/nat/test/llm.py (2)
src/nat/builder/framework_enum.py (1)
  • LLMFrameworkEnum (19-25)
src/nat/builder/builder.py (1)
  • Builder (68-290)
packages/nvidia_nat_test/tests/test_test_llm.py (3)
src/nat/data_models/component_ref.py (1)
  • LLMRef (116-124)
packages/nvidia_nat_adk/src/nat/plugins/adk/agent.py (1)
  • ADKFunctionConfig (30-38)
packages/nvidia_nat_test/src/nat/test/llm.py (3)
  • TestLLMConfig (36-43)
  • ainvoke (87-89)
  • ainvoke (193-195)
🪛 Ruff (0.13.3)
packages/nvidia_nat_test/src/nat/test/llm.py

209-209: Unused function argument: builder

(ARG001)


217-218: Avoid specifying long messages outside the exception class

(TRY003)


226-226: Unused method argument: stream

(ARG002)

🔇 Additional comments (1)
packages/nvidia_nat_test/tests/test_test_llm.py (1)

26-29: LGTM!

The new imports are necessary for the ADK integration tests and are used correctly below.

Signed-off-by: Daniel Wang <daniewang@nvidia.com>
@zhongxuanwang-nv
Copy link
Member Author

/merge

@zhongxuanwang-nv
Copy link
Member Author

@willkill07 Thanks Will!

@coderabbitai coderabbitai bot added the feature request New feature or request label Oct 7, 2025
@willkill07 willkill07 removed the feature request New feature or request label Oct 7, 2025
@rapids-bot rapids-bot bot merged commit 6461d86 into NVIDIA:release/1.3 Oct 7, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvement to existing functionality non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants