-
Notifications
You must be signed in to change notification settings - Fork 161
Feat: Implement Gemini Interaction API in adk-js #364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AmaadMartin
wants to merge
28
commits into
google:main
Choose a base branch
from
AmaadMartin:feat/interactions-api-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
78eaec8
Feat: Add previousInteractionId to LlmRequest and interactionId to Ll…
b7ff160
Feat: Implement and register InteractionsRequestProcessor
18494c0
Feat: Implement interactions_utils for mapping and running Interactio…
81285df
Feat: Integrate Interactions API into Gemini model class
ab2cf0b
Test: Add unit tests for Interactions API and verify script
3c044e8
Test: Add unit test edge cases for 100% statement and branch coverage
8aa7b81
Fix: Remove MIME type checking code duplication and delete verificati…
a7fe707
Chore: Upgrade @google/genai SDK to version 2.0.0
b181159
Fix: Update copyright year to 2026 and reuse base64Encode utility
c219001
Fix: Point @google/genai package resolution to public registry to res…
205a906
Fix: Make structural interfaces independent to resolve strict GenAI S…
c4561d4
Refactor interactions API integration to use native SDK types and res…
7a2cb68
Merge branch 'main' into feat/interactions-api-2
AmaadMartin f9d74a6
refactor(test): optimize interactions utils and fix agent loader test…
50e0152
refactor(types): remove explicit any and eslint-disable from interact…
b96ee03
Merge branch 'main' into feat/interactions-api-2
AmaadMartin 4ed4f03
Merge branch 'main' into feat/interactions-api-2
AmaadMartin 2d303eb
Merge branch 'main' into feat/interactions-api-2
AmaadMartin 1ff040d
Merge branch 'main' into feat/interactions-api-2
AmaadMartin 2598ebb
Merge upstream/main into feat/interactions-api-2 and resolve conflict…
2241eb7
Address PR feedback: avoid instanceof, use native Tool, define Extend…
238b98f
test: increase hook timeouts in integration tests to prevent flakiness
87424f4
build: force prettier plugin to use root tsconfig to fix import sorti…
fcaf18a
build: restore public registry URL for @google/genai in package-lock.…
2ed182d
test: increase timeout and inherit stderr in agent_dirname_test.ts
b43d32b
build: use cross-env for format scripts to fix Windows CI
869e5d5
build: replace cross-env/TSCONFIG_PATH with split-command format scripts
add61b7
revert: format scripts and test timeouts per PR feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
49 changes: 49 additions & 0 deletions
49
core/src/agents/processors/interactions_request_processor.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import {Event} from '../../events/event.js'; | ||
| import {Gemini} from '../../models/google_llm.js'; | ||
| import {LlmRequest} from '../../models/llm_request.js'; | ||
| import {InvocationContext} from '../invocation_context.js'; | ||
| import {isLlmAgent} from '../llm_agent.js'; | ||
| import {BaseLlmRequestProcessor} from './base_llm_processor.js'; | ||
|
|
||
| /** | ||
| * Request processor for Gemini Interactions API. | ||
| * Resolves the previous interaction ID from the session history. | ||
| */ | ||
| export class InteractionsRequestProcessor implements BaseLlmRequestProcessor { | ||
| // eslint-disable-next-line require-yield | ||
| async *runAsync( | ||
| invocationContext: InvocationContext, | ||
| llmRequest: LlmRequest, | ||
| ): AsyncGenerator<Event, void, void> { | ||
| const agent = invocationContext.agent; | ||
| if (!agent || !isLlmAgent(agent)) { | ||
| return; | ||
| } | ||
|
|
||
| const model = agent.canonicalModel; | ||
| if (model instanceof Gemini && model.useInteractionsApi) { | ||
| const events = invocationContext.session.events; | ||
| for (let i = events.length - 1; i >= 0; i--) { | ||
| const event = events[i]; | ||
| // Skip events not belonging to the current branch or author | ||
| if ( | ||
| event.branch === invocationContext.branch && | ||
| event.author === agent.name && | ||
| event.interactionId | ||
| ) { | ||
| llmRequest.previousInteractionId = event.interactionId; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export const INTERACTIONS_REQUEST_PROCESSOR = | ||
| new InteractionsRequestProcessor(); | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please avoid using the
instanceofand use util functions likeisGenimiModel. Looks likeisGenimiModeldoes not exist yet so we should create one. As an example use the https://github.com/google/adk-js/blob/main/core/src/models/base_llm.ts#L17-L31 from BaseModel.Problem with
instanceofis that when user will have multiple adk-js packages in their runtime it will not able to mix objects from one to another.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved. Defined a new isGemini type guard in core/src/models/google_llm.ts using a unique symbol ( Symbol.for('google.adk.geminiModel') ) to avoid package duplication issues. Refactored interactions_request_processor.ts to use isGemini(model) instead of model instanceof Gemini .