copy

open suspend fun copy(tools: List<ToolDescriptor> = this.tools, toolRegistry: ToolRegistry = this.toolRegistry, prompt: Prompt = this.prompt, model: LLModel = this.model, responseProcessor: ResponseProcessor? = this.responseProcessor, promptExecutor: PromptExecutor = this.promptExecutor, environment: AIAgentEnvironment = this.environment, config: AIAgentConfig = this.config, clock: KoogClock = this.clock): AIAgentLLMContext(source)

Creates a copy of this LLM context, taking a consistent snapshot of its mutable fields under the internal read lock. Multiple concurrent copy / readSession calls may proceed in parallel, but any concurrent writeSession / withPrompt will serialize against them.

Concurrency caveat: must not be invoked from inside a writeSession or withPrompt on the same context — the underlying lock is not reentrant (see RWLock).

Return

A new instance of AIAgentLLMContext with deep copies of mutable properties.


open fun copy(tools: List<ToolDescriptor> = this.tools, prompt: Prompt = this.prompt, model: LLModel = this.model, responseProcessor: ResponseProcessor? = this.responseProcessor, promptExecutor: PromptExecutor = this.promptExecutor, environment: AIAgentEnvironment = this.environment, config: AIAgentConfig = this.config, clock: KoogClock = this.clock): AIAgentLLMContext(source)

Creates a non-suspending copy of this LLM context with the given overrides. Unlike the suspending copy overload, this variant does not acquire the internal read lock and therefore does not guarantee a consistent snapshot if another coroutine is concurrently mutating this context.

Return

A new AIAgentLLMContext instance with the specified overrides applied.

Parameters

tools

The list of ToolDescriptor tools to use, or the current tools if not specified.

prompt

The Prompt to use, or the current prompt if not specified.

model

The LLModel to use, or the current model if not specified.

responseProcessor

The ResponseProcessor to use, or the current one if not specified.

promptExecutor

The PromptExecutor to use, or the current one if not specified.

environment

The AIAgentEnvironment to use, or the current one if not specified.

config

The AIAgentConfig to use, or the current configuration if not specified.

clock

The Clock to use, or the current clock if not specified.