Skip to content

Commit 5a277f9

Browse files
committed
feat: refactor polling logic to use isFinished() and add streaming API documentation
1 parent 425948f commit 5a277f9

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ AgentInteractionParams request = AgentInteractionParams.builder()
314314
Interaction interaction = client.create(request);
315315

316316
// Poll for completion
317-
while (interaction.status() != Status.COMPLETED) {
317+
while (!interaction.status().isFinished()) {
318318
Thread.sleep(1000);
319319
interaction = client.get(interaction.id());
320320
}
@@ -373,7 +373,7 @@ AgentInteractionParams params = AgentInteractionParams.builder()
373373
Interaction interaction = client.create(params);
374374

375375
// Poll remote sandbox until completion
376-
while (interaction.status() != Interaction.Status.COMPLETED) {
376+
while (!interaction.status().isFinished()) {
377377
Thread.sleep(2000);
378378
interaction = client.get(interaction.id());
379379
}

skills/gemini-interactions-java-api/SKILL.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ AgentInteractionParams request = AgentInteractionParams.builder()
187187
Interaction 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
199199
System.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

204240
Create an isolated agent securely using remote sandboxing with specific network allowlists.

0 commit comments

Comments
 (0)