Feat: Implement Gemini Interaction API in adk-js#364
Open
AmaadMartin wants to merge 15 commits into
Open
Conversation
…olve CI E401 error
…DK 2.0 type inheritance checks in CI
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
N/A
Closes: #issue_number
Related: #issue_number
2. Or, if no issue exists, describe the change:
This PR implements the next-generation stateful Gemini Interaction API integration in
adk-js, mirroring the design and functionality already present inadk-python. This enables stateful, multi-turn conversations by tracking interaction history server-side usinginteractionId, reducing payload sizes across progressive turns.If applicable, please follow the issue templates to provide as much detail as possible.
Problem:
The current
adk-jscore only supports stateless execution via the standardgenerateContentAPI, which requires sending the entire conversational history back and forth on every turn. This increases payload sizes, causes overhead, and prevents leveraging server-side interaction history tracking.Solution:
previousInteractionId?: stringtoLlmRequestincore/src/models/llm_request.ts.interactionId?: stringtoLlmResponseincore/src/models/llm_response.ts.InteractionsRequestProcessorundercore/src/agents/processors/interactions_request_processor.ts. It automatically traverses the session events history in reverse to find the latest validinteractionIdfor the current branch and sub-agent name, injecting it aspreviousInteractionIdinto the outgoing request.INTERACTIONS_REQUEST_PROCESSORinLlmAgentrequest processors, immediately following theCONTENT_REQUEST_PROCESSOR.core/src/models/interactions_utils.tscontaining:getLatestUserContentsto trim the outgoing conversation history, sending only the latest continuous user turn whenpreviousInteractionIdis present (with special handling to retain the preceding model turn's function call if the user turn contains a function response).@google/genaiInteractions REST schemas (and vice-versa).generateContentViaInteractionswrapping@google/genaiinteractions resource calls.Geminiclass (core/src/models/google_llm.ts) to acceptuseInteractionsApi?: booleanparameter, toggling the flow to delegate togenerateContentViaInteractionswhen enabled.Testing Plan
Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.
Unit Tests:
We implemented extensive unit tests targeting the stateful request processor and the payload converters:
core/test/agents/processors/interactions_request_processor_test.ts(6 tests)core/test/models/interactions_utils_test.ts(89 tests)Summary of passed npm test results:
We achieved 100% Statement, Branch, Function, and Line coverage for both new source files in
adk-js/core:core/src/agents/processors/interactions_request_processor.ts: 100% Coveragecore/src/models/interactions_utils.ts: 100% CoverageManual End-to-End (E2E) Tests:
We created a verification script
verify_interactions.tsin the root of the workspace. It tests a two-turn conversation:interactionId).previousInteractionIdset (verifies history is trimmed and the model correctly recalls "blue" from the server-side state).To execute manual verification:
Checklist
Additional context
TAG=agy
CONV=8a91ed6a-f4db-4160-83d9-68d5e80e066c