@@ -187,7 +187,7 @@ AgentInteractionParams request = AgentInteractionParams.builder()
187187Interaction interaction = client. create(request);
188188
189189// Poll for completion
190- while (interaction. status() != Status . COMPLETED && interaction . status() != Status . FAILED ) {
190+ while (! interaction. status(). isFinished() ) {
191191 try {
192192 Thread . sleep(2000 );
193193 } catch (InterruptedException e) {
@@ -199,6 +199,42 @@ while (interaction.status() != Status.COMPLETED && interaction.status() != Statu
199199System . out. println(interaction. steps());
200200```
201201
202+ ### Streaming Interactions
203+
204+ For long-running tasks or to see real-time updates (thoughts, code execution, text output), you can use the streaming API.
205+
206+ ``` java
207+ import io.github.glaforge.gemini.interactions.GeminiInteractionsClient ;
208+ import io.github.glaforge.gemini.interactions.model.* ;
209+ import io.github.glaforge.gemini.interactions.model.InteractionParams.AgentInteractionParams ;
210+
211+ GeminiInteractionsClient client = GeminiInteractionsClient . builder(). apiKey(System . getenv(" GEMINI_API_KEY" )). build();
212+
213+ AgentInteractionParams params = AgentInteractionParams . builder()
214+ .agent(" deep-research-pro-preview-12-2025" )
215+ .input(" Write a Python script for Conway's Game of Life" )
216+ .stream(true )
217+ .build();
218+
219+ try (var eventStream = client. stream(params)) {
220+ eventStream. forEach(event - > {
221+ if (event instanceof Events . InteractionCreated created) {
222+ System . out. println(" Interaction created: " + created. interaction(). id());
223+ } else if (event instanceof Events . ContentDelta contentDelta) {
224+ if (contentDelta. delta() instanceof Events . TextDelta textDelta) {
225+ System . out. print(textDelta. text());
226+ }
227+ } else if (event instanceof Events . StepDelta stepDelta) {
228+ if (stepDelta. delta() instanceof Events . ThoughtSummaryDelta thought) {
229+ System . out. println(" \n [Thinking...] " + thought. content());
230+ } else if (stepDelta. delta() instanceof Events . CodeExecutionCallDelta codeCall) {
231+ System . out. println(" \n [Executing Code...] " + codeCall. arguments());
232+ }
233+ }
234+ });
235+ }
236+ ```
237+
202238### Custom Agents (Sandboxing & Environment Egress)
203239
204240Create an isolated agent securely using remote sandboxing with specific network allowlists.
0 commit comments