Interface PromptRunner
-
- All Implemented Interfaces:
-
com.embabel.agent.api.common.PromptRunnerOperations,com.embabel.agent.core.ToolGroupConsumer,com.embabel.agent.core.support.LlmUse,com.embabel.common.ai.prompt.PromptContributorConsumer
public interface PromptRunner implements LlmUse, PromptRunnerOperations
User code should always use this interface to execute prompts. Typically obtained from an OperationContext or ActionContext parameter, via OperationContext.ai A PromptRunner is immutable once constructed, and has determined LLM and hyperparameters. Use the "with" methods to evolve the state to your desired configuration before executing createObject, generateText or other LLM invocation methods. Thus, a PromptRunner can be reused within an action implementation. A contextual facade to LlmOperations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfacePromptRunner.CreatingFluent interface for creating strongly-typed objects from LLM responses. Provides configuration options for:
Adding examples
Filtering properties
Enabling/disabling validation
Instances are obtained via PromptRunner.creating.
public interfacePromptRunner.RenderingFluent interface for rendering templates and generating LLM responses. Provides operations for:
Creating strongly-typed objects from rendered templates
Generating text from rendered templates
Responding in conversations with templates as system prompts
Instances are obtained via PromptRunner.rendering.
public interfacePromptRunner.ThinkingFluent interface for operations that extract thinking blocks from LLM responses. Provides access to:
Creating objects or text with thinking extraction
Processing multimodal content with thinkingg
Instances are obtained via PromptRunner.thinking.
-
Method Summary
Modifier and Type Method Description abstract PromptRunnerwithInteractionId(InteractionId interactionId)Set an interaction id for this prompt runner. PromptRunnerwithId(String id)Set the interaction id for this prompt runner. abstract PromptRunnerwithLlm(LlmOptions llm)Specify an LLM for the PromptRunner PromptRunnerwithMessage(Message message)Add a message that will be included in the final prompt. abstract PromptRunnerwithMessages(List<Message> messages)PromptRunnerwithMessages(Message message)PromptRunnerwithImage(AgentImage image)Add an image that will be included in the final prompt. abstract PromptRunnerwithImages(List<AgentImage> images)PromptRunnerwithImages(AgentImage images)PromptRunnerwithToolGroup(String toolGroup)Add a tool group to the PromptRunner abstract PromptRunnerwithToolGroup(ToolGroup toolGroup)Allows for dynamic tool groups to be added to the PromptRunner. abstract PromptRunnerwithToolGroup(ToolGroupRequirement toolGroup)PromptRunnerwithToolGroups(Set<String> toolGroups)PromptRunnerwithTools(String toolGroups)Add a set of tool groups to the PromptRunner PromptRunnerwithTools(List<Tool> tools)Add multiple framework-agnostic Tools to the prompt runner. PromptRunnerwithToolObject(Object toolObject)Add a tool object to the prompt runner. abstract PromptRunnerwithToolObject(ToolObject toolObject)Add a tool object PromptRunnerwithToolObjectInstances(Object toolObjects)PromptRunnerwithToolObjects(List<Object> toolObjects)abstract PromptRunnerwithTool(Tool tool)Add a framework-agnostic Tool to the prompt runner. PromptRunnerwithFunctionTools(Tool tools)Add multiple framework-agnostic Tools to the prompt runner (varargs version). PromptRunnerwithReference(LlmReference reference)Add a reference which provides tools and prompt contribution. PromptRunnerwithReferences(List<LlmReference> references)Add a list of references which provide tools and prompt contributions. PromptRunnerwithReferences(LlmReference references)Add varargs of references which provide tools and prompt contributions. abstract PromptRunnerwithHandoffs(Class<?> outputTypes)Add a list of handoffs to agents on this platform abstract PromptRunnerwithSubagents(Subagent subagents)Add a list of subagents to hand off to. PromptRunnerwithSystemPrompt(String systemPrompt)Add a literal system prompt PromptRunnerwithPromptContributor(PromptContributor promptContributor)Add a prompt contributor that can add to the prompt. abstract PromptRunnerwithPromptContributors(List<PromptContributor> promptContributors)PromptRunnerwithPromptElements(PromptElement elements)Add varargs of prompt contributors and contextual prompt elements. abstract PromptRunnerwithContextualPromptContributors(List<ContextualPromptElement> contextualPromptContributors)Add a prompt contributor that can see context PromptRunnerwithContextualPromptContributor(ContextualPromptElement contextualPromptContributor)abstract PromptRunnerwithGenerateExamples(Boolean generateExamples)Set whether to generate examples of the output in the prompt on a per-PromptRunner basis. abstract PromptRunnerwithPropertyFilter(Predicate<String> filter)Adds a filter that determines which properties are to be included when creating an object. abstract PromptRunnerwithValidation(Boolean validation)Set whether to validate created objects. abstract PromptRunnerwithGuardRails(GuardRail guards)Add guardrail instances to this PromptRunner (additive). abstract <T extends Any> PromptRunner.Creating<T>creating(Class<T> outputClass)Returns a mode for creating strongly-typed objects. PromptRunner.RenderingwithTemplate(String templateName)Use operations from a given template abstract PromptRunner.Renderingrendering(String templateName)Returns Rendering for rendering the specified template. BooleansupportsStreaming()Check if true reactive streaming is supported by the underlying LLM model. StreamingCapabilitystream()Create streaming operations for this prompt runner configuration. StreamingCapabilitystreaming()Return a StreamingCapability for reactive streaming operations. BooleansupportsThinking()Check if thinking extraction capabilities are supported by the underlying implementation. PromptRunner.ThinkingwithThinking()Create a thinking-enhanced version of this prompt runner. PromptRunner.Thinkingthinking()Return a PromptRunner.Thinking for extracting thinking blocks. AssistantMessagerespond(List<Message> messages)Respond in a conversation abstract List<ToolObject>getToolObjects()Additional objects with @Tool annotation for use in this PromptRunner abstract List<Message>getMessages()Messages added to this PromptRunner abstract List<AgentImage>getImages()Images added to this PromptRunner -
Methods inherited from class com.embabel.agent.api.common.PromptRunnerOperations
createObject, createObject, createObject, createObjectIfPossible, createObjectIfPossible, createObjectIfPossible, evaluateCondition, generateText, generateText, respond -
Methods inherited from class com.embabel.agent.core.support.LlmUse
getGenerateExamples, getLlm, getPropertyFilter, getValidation -
Methods inherited from class com.embabel.common.ai.prompt.PromptContributorConsumer
getPromptContributors -
Methods inherited from class com.embabel.agent.core.ToolGroupConsumer
getToolGroups -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
withInteractionId
abstract PromptRunner withInteractionId(InteractionId interactionId)
Set an interaction id for this prompt runner.
-
withId
PromptRunner withId(String id)
Set the interaction id for this prompt runner.
-
withLlm
abstract PromptRunner withLlm(LlmOptions llm)
Specify an LLM for the PromptRunner
-
withMessage
PromptRunner withMessage(Message message)
Add a message that will be included in the final prompt.
-
withMessages
abstract PromptRunner withMessages(List<Message> messages)
-
withMessages
PromptRunner withMessages(Message message)
-
withImage
PromptRunner withImage(AgentImage image)
Add an image that will be included in the final prompt. Images will be combined with the prompt text when operations are executed.
-
withImages
abstract PromptRunner withImages(List<AgentImage> images)
-
withImages
PromptRunner withImages(AgentImage images)
-
withToolGroup
PromptRunner withToolGroup(String toolGroup)
Add a tool group to the PromptRunner
- Parameters:
toolGroup- name of the toolGroup we're requesting- Returns:
PromptRunner instance with the added tool group
-
withToolGroup
abstract PromptRunner withToolGroup(ToolGroup toolGroup)
Allows for dynamic tool groups to be added to the PromptRunner.
-
withToolGroup
abstract PromptRunner withToolGroup(ToolGroupRequirement toolGroup)
-
withToolGroups
PromptRunner withToolGroups(Set<String> toolGroups)
-
withTools
PromptRunner withTools(String toolGroups)
Add a set of tool groups to the PromptRunner
- Parameters:
toolGroups- the set of named tool groups to add
-
withTools
PromptRunner withTools(List<Tool> tools)
Add multiple framework-agnostic Tools to the prompt runner.
- Parameters:
tools- the tools to add- Returns:
PromptRunner instance with the added tools
-
withToolObject
PromptRunner withToolObject(Object toolObject)
Add a tool object to the prompt runner. The tool object should have @Tool annotations.
- Parameters:
toolObject- the object to add.- Returns:
PromptRunner instance with the added tool object
-
withToolObject
abstract PromptRunner withToolObject(ToolObject toolObject)
Add a tool object
- Parameters:
toolObject- the object to add.
-
withToolObjectInstances
PromptRunner withToolObjectInstances(Object toolObjects)
-
withToolObjects
PromptRunner withToolObjects(List<Object> toolObjects)
-
withTool
abstract PromptRunner withTool(Tool tool)
Add a framework-agnostic Tool to the prompt runner.
- Parameters:
tool- the tool to add- Returns:
PromptRunner instance with the added tool
-
withFunctionTools
PromptRunner withFunctionTools(Tool tools)
Add multiple framework-agnostic Tools to the prompt runner (varargs version).
- Parameters:
tools- the tools to add- Returns:
PromptRunner instance with the added tools
-
withReference
PromptRunner withReference(LlmReference reference)
Add a reference which provides tools and prompt contribution.
-
withReferences
PromptRunner withReferences(List<LlmReference> references)
Add a list of references which provide tools and prompt contributions.
-
withReferences
PromptRunner withReferences(LlmReference references)
Add varargs of references which provide tools and prompt contributions.
-
withHandoffs
@ApiStatus.Experimental() abstract PromptRunner withHandoffs(Class<?> outputTypes)
Add a list of handoffs to agents on this platform
- Parameters:
outputTypes- the types of objects that can result from output flow
-
withSubagents
@ApiStatus.Experimental() abstract PromptRunner withSubagents(Subagent subagents)
Add a list of subagents to hand off to.
-
withSystemPrompt
PromptRunner withSystemPrompt(String systemPrompt)
Add a literal system prompt
-
withPromptContributor
PromptRunner withPromptContributor(PromptContributor promptContributor)
Add a prompt contributor that can add to the prompt. Facilitates reuse of prompt elements.
- Returns:
PromptRunner instance with the added PromptContributor
-
withPromptContributors
abstract PromptRunner withPromptContributors(List<PromptContributor> promptContributors)
-
withPromptElements
PromptRunner withPromptElements(PromptElement elements)
Add varargs of prompt contributors and contextual prompt elements.
-
withContextualPromptContributors
abstract PromptRunner withContextualPromptContributors(List<ContextualPromptElement> contextualPromptContributors)
Add a prompt contributor that can see context
-
withContextualPromptContributor
PromptRunner withContextualPromptContributor(ContextualPromptElement contextualPromptContributor)
-
withGenerateExamples
abstract PromptRunner withGenerateExamples(Boolean generateExamples)
Set whether to generate examples of the output in the prompt on a per-PromptRunner basis. This overrides platform defaults. Note that adding individual examples with Creating.withExample will always override this.
-
withPropertyFilter
@Deprecated(message = "Use creating().withPropertyFilter() instead", replaceWith = @ReplaceWith(imports = {}, expression = "creating(outputClass).withPropertyFilter(filter)")) abstract PromptRunner withPropertyFilter(Predicate<String> filter)
Adds a filter that determines which properties are to be included when creating an object.
Note that each predicate is applied in addition to previously registered predicates.
- Parameters:
filter- the property predicate to be added
-
withValidation
@Deprecated(message = "Use creating().withValidation() instead", replaceWith = @ReplaceWith(imports = {}, expression = "creating(outputClass).withValidation(validation)")) abstract PromptRunner withValidation(Boolean validation)
Set whether to validate created objects.
- Parameters:
validation-trueto validate created objects;falseotherwise.
-
withGuardRails
abstract PromptRunner withGuardRails(GuardRail guards)
Add guardrail instances to this PromptRunner (additive).
- Parameters:
guards- the guardrail instances to add- Returns:
PromptRunner instance with additional guardrails configured
-
creating
abstract <T extends Any> PromptRunner.Creating<T> creating(Class<T> outputClass)
Returns a mode for creating strongly-typed objects.
- Parameters:
outputClass- the class of objects to create- Returns:
creating mode supporting examples, property filtering, and validation
-
withTemplate
@Deprecated(message = "Use rendering(templateName) instead", replaceWith = @ReplaceWith(imports = {}, expression = "rendering(templateName)")) PromptRunner.Rendering withTemplate(String templateName)
Use operations from a given template
-
rendering
abstract PromptRunner.Rendering rendering(String templateName)
Returns Rendering for rendering the specified template.
- Parameters:
templateName- the name of the template to render- Returns:
rendering mode for creating objects and generating text from templates
-
supportsStreaming
Boolean supportsStreaming()
Check if true reactive streaming is supported by the underlying LLM model. Always check this before calling stream() to avoid exceptions.
- Returns:
true if real-time streaming is supported, false if streaming is not available
-
stream
@Deprecated(message = "Use streaming() instead", replaceWith = @ReplaceWith(imports = {}, expression = "streaming()")) StreamingCapability stream()
Create streaming operations for this prompt runner configuration.
This follows an explicit failure policy - if streaming is not supported by the underlying LLM implementation, this method will throw an exception rather than providing fallback behavior. Always check supportsStreaming() first for safe usage.
- Returns:
StreamingCapability instance providing access to streaming operations
-
streaming
StreamingCapability streaming()
Return a StreamingCapability for reactive streaming operations. Throws an exception if the underlying LLM does not support streaming. Use supportsStreaming to check availability before calling.
- Returns:
streaming capability for reactive object and text generation
-
supportsThinking
Boolean supportsThinking()
Check if thinking extraction capabilities are supported by the underlying implementation.
Thinking capabilities allow extraction of thinking blocks (like
<think>...</think>) from LLM responses and provide access to both the result and the extracted thinking content. Always check this before calling thinking() to avoid exceptions.Note: Thinking and streaming capabilities are mutually exclusive.
- Returns:
true if thinking extraction is supported, false if thinking is not available
-
withThinking
@Deprecated(message = "Use thinking() instead", replaceWith = @ReplaceWith(imports = {}, expression = "thinking()")) PromptRunner.Thinking withThinking()
Create a thinking-enhanced version of this prompt runner.
Returns a PromptRunner where all operations (createObject, generateText, etc.) return ThinkingResponse<T> wrappers that include both results and extracted thinking blocks from the LLM response.
Always check supportsThinking() first and ensure LlmOptions includes thinking configuration via withLlm(LlmOptions.withThinking(Thinking.withExtraction())).
Note: Thinking and streaming capabilities are mutually exclusive.
- Returns:
ThinkingCapability instance providing access to thinking-aware operations
-
thinking
PromptRunner.Thinking thinking()
Return a PromptRunner.Thinking for extracting thinking blocks. Throws an exception if the underlying LLM does not support thinking extraction. Use supportsThinking to check availability before calling.
- Returns:
thinking operations returning results with extracted reasoning
-
respond
AssistantMessage respond(List<Message> messages)
Respond in a conversation
-
getToolObjects
abstract List<ToolObject> getToolObjects()
Additional objects with @Tool annotation for use in this PromptRunner
-
getMessages
abstract List<Message> getMessages()
Messages added to this PromptRunner
-
getImages
abstract List<AgentImage> getImages()
Images added to this PromptRunner
-
-
-
-