Skip to content

fix: Make LlmResponse constructor protected for external subclassing#1137

Open
jinnigu wants to merge 1 commit intogoogle:mainfrom
jinnigu:fix/subclassing
Open

fix: Make LlmResponse constructor protected for external subclassing#1137
jinnigu wants to merge 1 commit intogoogle:mainfrom
jinnigu:fix/subclassing

Conversation

@jinnigu
Copy link
Copy Markdown
Contributor

@jinnigu jinnigu commented Apr 14, 2026

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
The LlmResponse constructor uses package-private (default) visibility, which prevents users from subclassing LlmResponse outside of the com.google.adk.models package. This blocks custom LLM integrations (e.g., connecting LM Studio or other local models) that need to extend LlmResponse.

Solution:
Change the LlmResponse constructor from package-private to protected. This is the minimal change needed. It allows subclassing from external packages while still preventing arbitrary instantiation (unlike public). The @AutoValue-generated subclass in the same package is unaffected.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added ExternalLlmResponseSubclassTest in the com.google.adk.models.external package (outside com.google.adk.models) to verify that an external subclass of LlmResponse can be instantiated.

./mvnw -pl core -Dtest=ExternalLlmResponseSubclassTest test
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 — BUILD SUCCESS

Checklist

  • I have read the CONTRIBUTING.md document.
  • My pull request contains a single commit.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LlmResponse constructor makes it hard to create new response type outside of package

1 participant