Interface ImageLoader
- All Superinterfaces:
ContentLoader
Implement this interface to provide custom image loading logic for multimodal AI agent interactions. This allows loading images from custom sources such as cloud storage, databases, or authenticated endpoints.
Example implementation:
public class MyImageLoader implements ImageLoader {
@Override
public LoadedImage load(
URI uri,
MessageContent.ImageMessageContent.DetailLevel detailLevel,
Optional<String> mimeType) {
// Load image bytes from your custom source
byte[] imageData = fetchFromStorage(uri);
String actualMimeType = mimeType.orElse("image/jpeg");
return new LoadedImage(imageData, actualMimeType);
}
}
To use the image loader, pass it to the agent effect builder:
return effects()
.imageLoader(new MyImageLoader())
.userMessage(UserMessage.from(
MessageContent.TextMessageContent.from("Describe this image"),
MessageContent.ImageMessageContent.fromUrl(imageUrl)))
.thenReply();
The instance used could be a new one for each agent request, to for example allow per request credentials, or it could be created globally in the service bootstrap, and made available to each agent via dependency injection.
In case of a shared instance, care must be taken that it is thread safe since it can be used by multiple separate agent interactions concurrently.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordDeprecated, for removal: This API element is subject to removal in a future version.Represents a loaded image with its binary data and MIME type.Nested classes/interfaces inherited from interface akka.javasdk.agent.ContentLoader
ContentLoader.LoadedContent -
Method Summary
Modifier and TypeMethodDescriptiondefault ContentLoader.LoadedContentDeprecated, for removal: This API element is subject to removal in a future version.Loads content from the given loadable message content.load(URI uri, MessageContent.ImageMessageContent.DetailLevel detailLevel, Optional<String> mimeType) Deprecated, for removal: This API element is subject to removal in a future version.Loads an image from the given URI.
-
Method Details
-
load
ImageLoader.LoadedImage load(URI uri, MessageContent.ImageMessageContent.DetailLevel detailLevel, Optional<String> mimeType) Deprecated, for removal: This API element is subject to removal in a future version.Loads an image from the given URI.This method is called by the runtime when processing multimodal messages that contain image references. The implementation should fetch the image data and return it along with the appropriate MIME type.
If the method throws, the entire agent request is failed.
- Parameters:
uri- The URI of the image to loaddetailLevel- The requested detail level for image processing (LOW, HIGH, or AUTO)mimeType- Optional MIME type hint provided by the user. Note that the returned mime type *must* match the actual MIME type of the returned bytes if the input MIME type is not correct.- Returns:
- The loaded image data and MIME type
-
load
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:ContentLoaderLoads content from the given loadable message content.This method is called by the runtime when processing multimodal messages that contain URL-referenced content. The implementation should fetch the content data and return it along with the appropriate MIME type.
Use pattern matching on the content parameter to handle different content types:
MessageContent.ImageUrlMessageContent— provides the URL, detail level, and optional MIME type hintMessageContent.PdfUrlMessageContent— provides the URL of the PDF
If the method throws, the entire agent request is failed.
- Specified by:
loadin interfaceContentLoader- Parameters:
content- The loadable message content containing the URL and metadata- Returns:
- The loaded content data and MIME type
-
ContentLoader