Welcome, AI coding agent! This document contains guidelines and conventions for working on the gemini-interactions-api-sdk project.
This project is a Java implementation of the Gemini Interactions API.
This API goes beyond standard model generation (text, images, audio, video...) by allowing developers to provision, configure, and interact with stateful managed agents (like the Deep Research Agent).
These agents can be equipped with complex tools (Google Search, Code Execution, File Search, etc.) and execute autonomously inside isolated remote sandbox environments.
- API Key: Set the
GEMINI_API_KEYenvironment variable to your API key. - If you don't have an API key, you can create one on the Google AI Studio website.
- For running the tests, you must have the API key set for the tests to pass. The tests will not run without a valid API key, but they will not fail either (they will be skipped).
- Never hardcode API keys in source code or commit
.envfiles.
- Run a specific unit test:
mvn test -Dtest=ClassNameTest - Run a specific integration test:
mvn verify -Dtest=ClassNameIT
- Build and package:
mvn clean package - Run all fast tests:
mvn test - Run all integration tests:
mvn verify
- Use standard Java formatting conventions.
- Organize imports systematically. Always import classes instead of using Fully Qualified Names (FQN). Never use star imports (
import java.util.*;). - Favor records (
public record ...) over traditional POJOs for immutable configuration models. - Ensure proper Javadoc for all public API surfaces.
model/— Java records representing API resources (Agent,Interaction,InteractionParams,Tool,Config,Events,Step, etc.). Most are immutable records with nestedBuilderclasses.server/—InteractionsHandlerfor server-side webhook handling.GeminiInteractionsClient— The main SDK entry point. Handles all HTTP communication with the Gemini API (CRUD for agents, interactions, webhooks, environment downloads).AgentEnvironment— Stateful wrapper for downloading and inspecting a remote agent's sandbox filesystem (TAR archive).deserializer/— Custom Jackson deserializers for polymorphic API responses.ResearchFrontend(insrc/test/java) — A standalone demo web application for the Deep Research agent, deployable to Google Cloud Run. Seeresearcher-deployment.mdfor deployment instructions.
UPDATING_SDK.md— Instructions for keeping the SDK implementation in sync with the remote Gemini Interactions API contract via its OpenAPI JSON definition (openapi.json). Read this before adding or modifying API models, and remember to updateREADME.mdandskills/gemini-interactions-java-api/SKILL.mdto reflect the new capabilities.researcher-deployment.md— Step-by-step guide to building and deploying theResearchFrontenddemo to Google Cloud Run.RELEASE.md— Release process using JReleaser and GitHub Actions to publish to Maven Central. SeeREADME.mdfor additional context on versioning and usage.
- Builder pattern: Use the static
Builderclass for complex records (seeAgent.Builder,GenerationConfig.Builder,Retrieval.Builder). - Type-safe overloads: Prefer multiple overloaded methods with specific types over a single method accepting
Object(seeAgent.Builder.baseEnvironment()). - AutoCloseable:
AgentEnvironmentimplementsAutoCloseable; always use it in a try-with-resources block.
- Using Fully Qualified Names inline (e.g.,
java.io.InputStream) — always add an import statement. - Star imports (
import java.util.*;). - Mutable POJOs where an immutable
recordwould suffice.
This project uses Maven with both the Surefire (unit tests) and Failsafe (integration tests) plugins to separate fast tests from long-running tests.
- Convention: Files ending in
*Test.java - Execution: Run using
mvn test - When to run: Run these frequently while iterating on code. They execute mock-based tests and basic assertions that complete in milliseconds.
- Convention: Files ending in
*IT.java(e.g.,ResearchAgentIT.java,IntegrationIT.java) - Execution: Run using
mvn verify(ormvn integration-test) - When to run: Run these before making commits, finalizing a pull request, or validating end-to-end functionality. They often instantiate actual agents, connect to external endpoints, and can take up to 10 minutes to complete.
- If your new test is purely local, mocks the
GeminiInteractionsClient, or executes quickly, name it*Test.java. - If your new test makes live network calls, provisions remote agents, or performs heavy data generation, name it
*IT.java.
- Read files, list directories, and search the project code.
- Perform single-file edits or multi-file refactoring.
- Run unit tests on specific files.
- Making large structural architectural changes.
- Running the full 10-minute integration test suite (
mvn verify). - Committing or pushing to the repository.
- Ensure code is formatted correctly.
- Add or update tests for any changed logic.
- Keep diffs small and focused; avoid committing unnecessary files.