PromptRunner

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.

See also

Inheritors

Properties

Link copied to clipboard
abstract val generateExamples: Boolean?

Whether to generate examples for the prompt. Defaults to unknown: Set to false if generating your own examples.

Link copied to clipboard
abstract val images: List<AgentImage>

Images added to this PromptRunner

Link copied to clipboard
abstract val llm: <Error class: unknown class>?
Link copied to clipboard
abstract val messages: List<Message>

Messages added to this PromptRunner

Link copied to clipboard

Filter that determines which properties to include when creating objects.

Link copied to clipboard

Tool groups exposed. This will include directly registered tool groups and tool groups resolved from ToolGroups.

Link copied to clipboard
abstract val toolObjects: List<ToolObject>

Additional objects with @Tool annotation for use in this PromptRunner

Functions

Link copied to clipboard

Extension function to safely cast PromptRunner to streaming operations. Pure casting - assumes streaming support already verified.

Link copied to clipboard

Extension function to safely convert PromptRunner to streaming operations. Includes validation - checks streaming support before casting.

Link copied to clipboard
infix inline fun <T> PromptRunner.create(prompt: String): T

Create an object of the given type. Method overloading is evil

Link copied to clipboard
open fun <T> createObject(content: MultimodalContent, outputClass: Class<T>): T

Create an object from multimodal content (text + images)

open fun <T> createObject(prompt: String, outputClass: Class<T>): T

Create an object of the given type using the given prompt and LLM options from context (process context or implementing class). Prompts are typically created within the scope of an

abstract fun <T> createObject(messages: List<Message>, outputClass: Class<T>): T

Create an object from messages

Link copied to clipboard
infix inline fun <T> PromptRunner.createObject(prompt: String): T

Create an object of the given type

Link copied to clipboard
open fun <T> createObjectIfPossible(content: MultimodalContent, outputClass: Class<T>): T?

Try to create an object from multimodal content (text + images)

open fun <T> createObjectIfPossible(prompt: String, outputClass: Class<T>): T?

Try to create an object of the given type using the given prompt and LLM options from context (process context or implementing class). Prompt is typically created within the scope of an

abstract fun <T> createObjectIfPossible(messages: List<Message>, outputClass: Class<T>): T?
Link copied to clipboard
inline fun <T> PromptRunner.createObjectIfPossible(prompt: String): T?
Link copied to clipboard
abstract fun <T> creating(outputClass: Class<T>): ObjectCreator<T>

Create an object creator for the given output class. Allows setting strongly typed examples.

Link copied to clipboard
abstract fun evaluateCondition(condition: String, context: String, confidenceThreshold: <Error class: unknown class> = 0.8): Boolean
Link copied to clipboard

Generate text from multimodal content (text + images)

open infix fun generateText(prompt: String): String

Generate text

Link copied to clipboard
open override fun respond(messages: List<Message>): AssistantMessage

Respond in a conversation

Respond in a conversation with multimodal content

Link copied to clipboard

Create streaming operations for this prompt runner configuration.

Link copied to clipboard

Check if true reactive streaming is supported by the underlying LLM model. Always check this before calling stream() to avoid exceptions.

Link copied to clipboard
Link copied to clipboard
abstract fun withContextualPromptContributors(contextualPromptContributors: List<ContextualPromptElement>): PromptRunner

Add a prompt contributor that can see context

Link copied to clipboard
open fun withFunctionTools(vararg tools: Tool): PromptRunner

Add multiple framework-agnostic Tools to the prompt runner (varargs version).

Link copied to clipboard
abstract fun withGenerateExamples(generateExamples: Boolean): PromptRunner

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 com.embabel.agent.api.common.nested.ObjectCreator.withExample will always override this.

Link copied to clipboard
@ApiStatus.Experimental
abstract fun withHandoffs(vararg outputTypes: Class<*>): PromptRunner

Add a list of handoffs to agents on this platform

Link copied to clipboard
open fun withId(id: String): PromptRunner

Set the interaction id for this prompt runner.

Link copied to clipboard

Add an image that will be included in the final prompt. Images will be combined with the prompt text when operations are executed.

Link copied to clipboard

Add an image from a file

Add an image from a path

Add an image with explicit MIME type and data

Link copied to clipboard
open fun withImages(vararg images: AgentImage): PromptRunner
abstract fun withImages(images: List<AgentImage>): PromptRunner
Link copied to clipboard
abstract fun withInteractionId(interactionId: InteractionId): PromptRunner

Set an interaction id for this prompt runner.

Link copied to clipboard
abstract fun withLlm(llm: <Error class: unknown class>): PromptRunner

Specify an LLM for the PromptRunner

Link copied to clipboard
open fun withMessage(message: Message): PromptRunner

Add a message that will be included in the final prompt.

Link copied to clipboard
open fun withMessages(vararg message: Message): PromptRunner
abstract fun withMessages(messages: List<Message>): PromptRunner
Link copied to clipboard
open fun withPromptContributor(promptContributor: <Error class: unknown class>): PromptRunner

Add a prompt contributor that can add to the prompt. Facilitates reuse of prompt elements.

Link copied to clipboard
abstract fun withPromptContributors(promptContributors: List<<Error class: unknown class>>): PromptRunner
Link copied to clipboard
open fun withPromptElements(vararg elements: <Error class: unknown class>): PromptRunner

Add varargs of prompt contributors and contextual prompt elements.

Link copied to clipboard

Adds a filter that determines which properties are to be included when creating an object.

Link copied to clipboard

Add a reference which provides tools and prompt contribution.

Link copied to clipboard
open fun withReferences(vararg references: LlmReference): PromptRunner

Add varargs of references which provide tools and prompt contributions.

Add a list of references which provide tools and prompt contributions.

Link copied to clipboard
@ApiStatus.Experimental
abstract fun withSubagents(vararg subagents: Subagent): PromptRunner

Add a list of subagents to hand off to.

Link copied to clipboard
open fun withSystemPrompt(systemPrompt: String): PromptRunner

Add a literal system prompt

Link copied to clipboard
abstract fun withTemplate(templateName: String): TemplateOperations

Use operations from a given template

Link copied to clipboard
abstract fun withTool(tool: Tool): PromptRunner

Add a framework-agnostic Tool to the prompt runner.

Link copied to clipboard
abstract fun withToolGroup(toolGroup: ToolGroup): PromptRunner

Allows for dynamic tool groups to be added to the PromptRunner.


open fun withToolGroup(toolGroup: String): PromptRunner

Add a tool group to the PromptRunner

Link copied to clipboard
open fun withToolGroups(toolGroups: Set<String>): PromptRunner
Link copied to clipboard
abstract fun withToolObject(toolObject: ToolObject): PromptRunner

Add a tool object

open fun withToolObject(toolObject: Any?): PromptRunner

Add a tool object to the prompt runner. The tool object should have @Tool annotations.

Link copied to clipboard
open fun withToolObjectInstances(vararg toolObjects: Any?): PromptRunner
Link copied to clipboard
open fun withToolObjects(toolObjects: List<Any>): PromptRunner
Link copied to clipboard
open fun withTools(vararg toolGroups: String): PromptRunner

Add a set of tool groups to the PromptRunner

open fun withTools(tools: List<Tool>): PromptRunner

Add multiple framework-agnostic Tools to the prompt runner.