Skip to content

Commit d5b6edf

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: Return Completable from saveArtifact in CallbackContext
The return type of the artifactService is Single, meaning it doesn't get scheduled to execute until it is subscribed. Today it's not subscribed. This is a bug leads to saveArtifact never executes. Changing the return type to Completable allows clients subscribe to it and fits naturally with the async pattern of Orcas APIs. PiperOrigin-RevId: 817930873
1 parent 58462fd commit d5b6edf

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

core/src/main/java/com/google/adk/agents/CallbackContext.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.adk.events.EventActions;
2121
import com.google.adk.sessions.State;
2222
import com.google.genai.types.Part;
23+
import io.reactivex.rxjava3.core.Completable;
2324
import io.reactivex.rxjava3.core.Maybe;
2425
import io.reactivex.rxjava3.core.Single;
2526
import java.util.List;
@@ -99,21 +100,22 @@ public Maybe<Part> loadArtifact(String filename, Optional<Integer> version) {
99100
*
100101
* @param filename Artifact file name.
101102
* @param artifact Artifact content to save.
103+
* @return a {@link Completable} that completes when the artifact is saved.
102104
* @throws IllegalStateException if the artifact service is not initialized.
103105
*/
104-
public void saveArtifact(String filename, Part artifact) {
106+
public Completable saveArtifact(String filename, Part artifact) {
105107
if (invocationContext.artifactService() == null) {
106108
throw new IllegalStateException("Artifact service is not initialized.");
107109
}
108-
var unused =
109-
invocationContext
110-
.artifactService()
111-
.saveArtifact(
112-
invocationContext.appName(),
113-
invocationContext.userId(),
114-
invocationContext.session().id(),
115-
filename,
116-
artifact);
117-
this.eventActions.artifactDelta().put(filename, artifact);
110+
return invocationContext
111+
.artifactService()
112+
.saveArtifact(
113+
invocationContext.appName(),
114+
invocationContext.userId(),
115+
invocationContext.session().id(),
116+
filename,
117+
artifact)
118+
.doOnSuccess(unusedVersion -> this.eventActions.artifactDelta().put(filename, artifact))
119+
.ignoreElement();
118120
}
119121
}

0 commit comments

Comments
 (0)