Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions core/src/main/java/com/google/adk/agents/CallbackContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,20 @@ public Single<List<String>> listArtifacts() {
.map(ListArtifactsResponse::filenames);
}

/** Loads the latest version of an artifact from the service. */
public Maybe<Part> loadArtifact(String filename) {
return loadArtifact(filename, Optional.empty());
}

/** Loads a specific version of an artifact from the service. */
public Maybe<Part> loadArtifact(String filename, int version) {
return loadArtifact(filename, Optional.of(version));
}

/**
* Loads an artifact from the artifact service associated with the current session.
*
* @param filename Artifact file name.
* @param version Artifact version (optional).
* @return loaded part, or empty if not found.
* @throws IllegalStateException if the artifact service is not initialized.
* @deprecated Use {@link #loadArtifact(String)} or {@link #loadArtifact(String, int)} instead.
*/
@Deprecated
public Maybe<Part> loadArtifact(String filename, Optional<Integer> version) {
if (invocationContext.artifactService() == null) {
throw new IllegalStateException("Artifact service is not initialized.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,26 @@ Single<Integer> saveArtifact(
default Single<Part> saveAndReloadArtifact(
String appName, String userId, String sessionId, String filename, Part artifact) {
return saveArtifact(appName, userId, sessionId, filename, artifact)
.flatMap(
version ->
loadArtifact(appName, userId, sessionId, filename, Optional.of(version))
.toSingle());
.flatMap(version -> loadArtifact(appName, userId, sessionId, filename, version).toSingle());
}

/** Loads the latest version of an artifact from the service. */
default Maybe<Part> loadArtifact(
String appName, String userId, String sessionId, String filename) {
return loadArtifact(appName, userId, sessionId, filename, Optional.empty());
}

/** Loads a specific version of an artifact from the service. */
default Maybe<Part> loadArtifact(
String appName, String userId, String sessionId, String filename, int version) {
return loadArtifact(appName, userId, sessionId, filename, Optional.of(version));
}

/**
* Gets an artifact.
*
* @param appName the app name
* @param userId the user ID
* @param sessionId the session ID
* @param filename the filename
* @param version Optional version number. If null, loads the latest version.
* @return the artifact or empty if not found
* @deprecated Use {@link #loadArtifact(String, String, String, String)} or {@link
* #loadArtifact(String, String, String, String, int)} instead.
*/
@Deprecated
Maybe<Part> loadArtifact(
String appName, String userId, String sessionId, String filename, Optional<Integer> version);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ public Single<ImmutableList<Integer>> listVersions(
public Single<Part> saveAndReloadArtifact(
String appName, String userId, String sessionId, String filename, Part artifact) {
return saveArtifact(appName, userId, sessionId, filename, artifact)
.flatMap(
version ->
loadArtifact(appName, userId, sessionId, filename, Optional.of(version))
.toSingle());
.flatMap(version -> loadArtifact(appName, userId, sessionId, filename, version).toSingle());
}

private Map<String, List<Part>> getArtifactsMap(String appName, String userId, String sessionId) {
Expand Down