Class PromptTemplate
PromptTemplate allows you to change agent prompts at runtime without restarting or redeploying the service. Since it's managed as an entity, you retain full change history and can subscribe to prompt changes.
Automatic Registration: The Akka runtime automatically registers this entity
when it detects an Agent
component in your service.
Template Parameters: Templates support Java String.formatted(java.lang.Object...)
style
parameters when using systemMessageFromTemplate(templateId, args...)
.
Change Monitoring: You can subscribe to prompt template changes using a Consumer to build views or react to prompt updates.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static final record
Nested classes/interfaces inherited from class akka.javasdk.eventsourcedentity.EventSourcedEntity
EventSourcedEntity.Effect<T>, EventSourcedEntity.ReadOnlyEffect<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyEvent
(PromptTemplate.Event event) This is the main event handler method.EventSourcedEntity.Effect
<akka.Done> delete()
Delete the prompt template.get()
Get the prompt template.Get the prompt template.EventSourcedEntity.Effect
<akka.Done> Initialize the prompt template.EventSourcedEntity.Effect
<akka.Done> Update the prompt template.Methods inherited from class akka.javasdk.eventsourcedentity.EventSourcedEntity
commandContext, currentState, effects, emptyState, eventContext, isDeleted
-
Constructor Details
-
PromptTemplate
public PromptTemplate()
-
-
Method Details
-
init
Initialize the prompt template. Call this method for existing prompt template will be ignored, so it's safe to use it e.g. inServiceSetup
to initialize the prompt template with default value. -
update
Update the prompt template. Updating the prompt template with the same value will be ignored. -
delete
Delete the prompt template. If the prompt template was already deleted or never set, the call will succeed. -
get
Get the prompt template. If the prompt template is not set or deleted, an error will be returned. -
getOptional
Get the prompt template. If the prompt template is not set or deleted, an empty optional will be returned. -
applyEvent
Description copied from class:EventSourcedEntity
This is the main event handler method. Whenever an event is persisted, this handler will be called. It should return the new state of the entity.Note that this method is called in two situations:
- when one or more events are persisted by the command handler, this method is called to produce the new state of the entity.
- when instantiating an entity from the event journal, this method is called to restore the state of the entity.
Events are required to inherit from a common sealed interface, and it's recommend to implement this method using a switch statement. As such, the compiler can check if all existing events are being handled.
// example of sealed event interface with concrete events implementing it public sealed interface Event { @TypeName("created") public record UserCreated(String name, String email) implements Event {}; @TypeName("email-updated") public record EmailUpdated(String newEmail) implements Event {}; } // example of applyEvent implementation public User applyEvent(Event event) { return switch (event) { case UserCreated userCreated -> new User(userCreated.name, userCreated.email); case EmailUpdated emailUpdated -> this.copy(email = emailUpdated.newEmail); } }
- Specified by:
applyEvent
in classEventSourcedEntity<PromptTemplate.Prompt,
PromptTemplate.Event>
-