Skip to content
Merged
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: 7 additions & 11 deletions core/src/main/java/com/google/adk/plugins/LoggingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Maybe;
import java.util.Map;
import java.util.Optional;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -57,7 +57,7 @@ private void log(String message) {

@Override
public Maybe<Content> onUserMessageCallback(
InvocationContext invocationContext, Content userMessage) {
InvocationContext invocationContext, @Nullable Content userMessage) {
return Maybe.fromAction(
() -> {
log("🚀 USER MESSAGE RECEIVED");
Expand All @@ -66,7 +66,7 @@ public Maybe<Content> onUserMessageCallback(
log(" User ID: " + invocationContext.userId());
log(" App Name: " + invocationContext.appName());
log(" Root Agent: " + invocationContext.agent().name());
log(" User Content: " + formatContent(Optional.ofNullable(userMessage)));
log(" User Content: " + formatContent(userMessage));
invocationContext.branch().ifPresent(branch -> log(" Branch: " + branch));
});
}
Expand All @@ -88,7 +88,7 @@ public Maybe<Event> onEventCallback(InvocationContext invocationContext, Event e
log("📢 EVENT YIELDED");
log(" Event ID: " + event.id());
log(" Author: " + event.author());
log(" Content: " + formatContent(event.content()));
log(" Content: " + formatContent(event.content().orElse(null)));
log(" Final Response: " + event.finalResponse());

if (!event.functionCalls().isEmpty()) {
Expand Down Expand Up @@ -190,7 +190,7 @@ public Maybe<LlmResponse> afterModelCallback(
log(" ❌ ERROR - Code: " + llmResponse.errorCode().get());
log(" Error Message: " + llmResponse.errorMessage().orElse("None"));
} else {
log(" Content: " + formatContent(llmResponse.content()));
log(" Content: " + formatContent(llmResponse.content().orElse(null)));
llmResponse.partial().ifPresent(partial -> log(" Partial: " + partial));
llmResponse
.turnComplete()
Expand Down Expand Up @@ -265,12 +265,8 @@ public Maybe<Map<String, Object>> onToolErrorCallback(
});
}

private String formatContent(Optional<Content> contentOptional) {
if (contentOptional.isEmpty()) {
return "None";
}
Content content = contentOptional.get();
if (content.parts().isEmpty() || content.parts().get().isEmpty()) {
private String formatContent(@Nullable Content content) {
if (content == null || content.parts().isEmpty() || content.parts().get().isEmpty()) {
return "None";
}
return content.parts().get().stream()
Expand Down
Loading