AIAgentLLMContext

class AIAgentLLMContext(tools: List<ToolDescriptor>, val toolRegistry: ToolRegistry = ToolRegistry.Companion.EMPTY, prompt: Prompt, model: LLModel, val promptExecutor: PromptExecutor, environment: AIAgentEnvironment, config: AIAgentConfigBase, clock: Clock)(source)

Represents the context for an AI agent LLM, managing tools, prompt handling, and interaction with the environment and execution layers. It provides mechanisms for concurrent read and write operations through sessions, ensuring thread safety.

Constructors

Link copied to clipboard
constructor(tools: List<ToolDescriptor>, toolRegistry: ToolRegistry = ToolRegistry.Companion.EMPTY, prompt: Prompt, model: LLModel, promptExecutor: PromptExecutor, environment: AIAgentEnvironment, config: AIAgentConfigBase, clock: Clock)

Properties

Link copied to clipboard

LLM currently associated with this context.

Link copied to clipboard

The current prompt used within the AIAgentLLMContext.

Link copied to clipboard

The PromptExecutor responsible for performing operations on the current prompt.

Link copied to clipboard

A registry that contains metadata about available tools.

Link copied to clipboard

List of current tools associated with this agent context.

Functions

Link copied to clipboard
fun copy(tools: List<ToolDescriptor> = this.tools, prompt: Prompt = this.prompt, model: LLModel = this.model, promptExecutor: PromptExecutor = this.promptExecutor, environment: AIAgentEnvironment = this.environment, config: AIAgentConfigBase = this.config, clock: Clock = this.clock): AIAgentLLMContext

Returns the current prompt used in the LLM context.

suspend fun copy(tools: List<ToolDescriptor> = this.tools, toolRegistry: ToolRegistry = this.toolRegistry, prompt: Prompt = this.prompt, model: LLModel = this.model, promptExecutor: PromptExecutor = this.promptExecutor, environment: AIAgentEnvironment = this.environment, config: AIAgentConfigBase = this.config, clock: Clock = this.clock): AIAgentLLMContext

Creates a deep copy of this LLM context.

Link copied to clipboard
suspend fun <T> readSession(block: suspend AIAgentLLMReadSession.() -> T): T

Executes a read session within the AIAgentLLMContext, ensuring concurrent safety with active write session and other read sessions.

Link copied to clipboard
suspend fun withPrompt(block: Prompt.() -> Prompt): AIAgentLLMContext

Updates the current AIAgentLLMContext with a new prompt and ensures thread-safe access using a read lock.

Link copied to clipboard
suspend fun <T> writeSession(block: suspend AIAgentLLMWriteSession.() -> T): T

Executes a write session on the AIAgentLLMContext, ensuring that all active write and read sessions are completed before initiating the write session.