-
Notifications
You must be signed in to change notification settings - Fork 10
feat: LLM image input support #1106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
35e088d
feat: LLM image input/output support
aludwiko 2b321f8
fixes after merge
aludwiko 028d985
renames + session memory tests
aludwiko 9c0cff0
Update Dependencies.scala
aludwiko 4fdf7b7
Merge remote-tracking branch 'origin/main' into release-notes-3.5.6
aludwiko d9eacf2
reverting grpc changes
aludwiko d70aaac
vale errors
aludwiko eb9f5e5
fixing nav page
aludwiko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...asdk-tests/src/test/java/akkajavasdk/components/agent/SomeMultiModalUserMessageAgent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * Copyright (C) 2021-2025 Lightbend Inc. <https://www.lightbend.com> | ||
| */ | ||
|
|
||
| package akkajavasdk.components.agent; | ||
|
|
||
| import akka.javasdk.agent.Agent; | ||
| import akka.javasdk.agent.MessageContent; | ||
| import akka.javasdk.agent.UserMessage; | ||
| import akka.javasdk.annotations.Component; | ||
|
|
||
| @Component(id = "some-multi-modal-user-message-agent") | ||
| public class SomeMultiModalUserMessageAgent extends Agent { | ||
| public record SomeResponse(String response) {} | ||
|
|
||
| public Effect<String> ask() { | ||
| return effects() | ||
| .systemMessage("You are a helpful...") | ||
| .userMessage( | ||
| UserMessage.from( | ||
| MessageContent.TextMessageContent.from("testing"), | ||
| MessageContent.ImageMessageContent.fromUrl("https://example.com"))) | ||
| .thenReply(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
akka-javasdk/src/main/java/akka/javasdk/agent/MessageContent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Copyright (C) 2021-2025 Lightbend Inc. <https://www.lightbend.com> | ||
| */ | ||
|
|
||
| package akka.javasdk.agent; | ||
|
|
||
| import java.net.MalformedURLException; | ||
| import java.net.URI; | ||
| import java.net.URL; | ||
|
|
||
| /** | ||
| * Represents a piece of content within a multimodal message to an AI model. | ||
| * | ||
| * <p>Message content can be text or images, allowing agents to send multimodal inputs. | ||
| * | ||
| * @see UserMessage | ||
| */ | ||
| public sealed interface MessageContent { | ||
|
|
||
| /** | ||
| * Text content within a user message. | ||
| * | ||
| * @param text The text content | ||
| */ | ||
| record TextMessageContent(String text) implements MessageContent { | ||
|
|
||
| /** | ||
| * Creates text content from a string. | ||
| * | ||
| * @param text The text content | ||
| * @return A new TextMessageContent instance | ||
| */ | ||
| public static TextMessageContent from(String text) { | ||
| return new TextMessageContent(text); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Image content within a user message, referenced by URL. | ||
| * | ||
| * @param url The URL pointing to the image | ||
| * @param detailLevel The level of detail for image processing | ||
| */ | ||
| record ImageUrlMessageContent(URL url, ImageMessageContent.DetailLevel detailLevel) | ||
| implements MessageContent {} | ||
|
|
||
| /** Factory methods for creating image message content. */ | ||
| record ImageMessageContent() { | ||
|
|
||
| /** | ||
| * Creates image content from a URL string with automatic detail level. | ||
| * | ||
| * @param url The URL string pointing to the image | ||
| * @return A new ImageUrlMessageContent instance with AUTO detail level | ||
| */ | ||
| public static ImageUrlMessageContent fromUrl(String url) { | ||
| try { | ||
| return ImageMessageContent.fromUrl(URI.create(url).toURL()); | ||
| } catch (MalformedURLException e) { | ||
| throw new RuntimeException("Can't transform " + url + " to URL", e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates image content from a URL with automatic detail level. | ||
| * | ||
| * @param url The URL pointing to the image | ||
| * @return A new ImageUrlMessageContent instance with AUTO detail level | ||
| */ | ||
| public static ImageUrlMessageContent fromUrl(URL url) { | ||
| return new ImageUrlMessageContent(url, DetailLevel.AUTO); | ||
| } | ||
|
|
||
| /** | ||
| * Creates image content from a URL with a specific detail level. | ||
| * | ||
| * @param url The URL pointing to the image | ||
| * @param detailLevel The level of detail for image processing | ||
| * @return A new ImageUrlMessageContent instance | ||
| */ | ||
| public static ImageUrlMessageContent fromUrl(URL url, DetailLevel detailLevel) { | ||
| return new ImageUrlMessageContent(url, detailLevel); | ||
| } | ||
|
|
||
| /** | ||
| * Controls the level of detail used when processing images. | ||
| * | ||
| * <p>The detail level affects both the quality of image analysis and the number of tokens | ||
| * consumed by the AI model. | ||
| */ | ||
| public enum DetailLevel { | ||
| /** Lower resolution processing, faster and uses fewer tokens */ | ||
| LOW, | ||
| /** Higher resolution processing, more detailed analysis but uses more tokens */ | ||
| HIGH, | ||
| /** Let the model automatically choose the appropriate detail level */ | ||
| AUTO; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, I used
CompoundUserMessagefor all interactions, text-only and multimodal, but I think most of the time, the user message will be text-based so it's worth optimizing it and supporting both options. Especially that we need to be backward compatible with events anyway.