PromptBuilder

A builder class for creating prompts using a DSL approach.

PromptBuilder allows constructing prompts by adding different types of messages (system, user, assistant, tool) in a structured way.

Example usage:

val prompt = prompt("example-prompt") {
system("You are a helpful assistant.")
user("What is the capital of France?")
}

Types

Link copied to clipboard
inner class ToolMessageBuilder(val clock: Clock)

Builder class for adding tool-related messages to the prompt.

Link copied to clipboard

A builder class for constructing tool result messages and appending them to a PromptBuilder.

Functions

Link copied to clipboard
fun assistant(cacheControl: CacheControl? = null, init: TextContentBuilder.() -> Unit): PromptBuilder

Adds an assistant message to the prompt using a TextContentBuilder.

fun assistant(content: String, cacheControl: CacheControl? = null): PromptBuilder

Adds an assistant message to the prompt.

Link copied to clipboard
fun build(): Prompt

Builds and returns a Prompt object from the current state of the builder.

Link copied to clipboard

Adds a generic message to the prompt.

Link copied to clipboard

Adds multiple messages to the prompt.

Link copied to clipboard
fun system(cacheControl: CacheControl? = null, init: TextContentBuilder.() -> Unit): PromptBuilder

Adds a system message to the prompt using a TextContentBuilder.

fun system(content: String, cacheControl: CacheControl? = null): PromptBuilder

Adds a system message to the prompt.

Link copied to clipboard

Adds tool-related messages to the prompt using a ToolMessageBuilder.

Link copied to clipboard

Creates a ToolResultMessageBuilder initialized with the provided tool call.

Adds a tool call message and initializes a ToolResultMessageBuilder.

Link copied to clipboard

Adds a user message to the prompt with attachments.

fun user(content: String): PromptBuilder

Adds a user message to the prompt.

fun user(content: String, block: ContentPartsBuilder.() -> Unit): PromptBuilder
fun user(content: String, attachments: List<ContentPart> = emptyList()): PromptBuilder
fun user(parts: List<ContentPart>, cacheControl: CacheControl? = null): PromptBuilder

Adds a user message to the prompt with optional attachments.