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 llm: <Error class: unknown class>?
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
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(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
abstract 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

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
open infix fun generateText(prompt: String): String

Generate text

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

Respond in a conversation

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
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.

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
abstract fun withLlm(llm: <Error class: unknown class>): PromptRunner

Specify an LLM for the 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

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 system prompt

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

Use operations from a given template

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.

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

Add a set of tool groups to the PromptRunner