Properties

Link copied to clipboard
abstract override val agentId: String

A unique identifier representing the current agent instance within the context.

Link copied to clipboard
abstract override val agentInput: Any?

Represents the input provided to the agent's execution.

Link copied to clipboard
abstract override val config: AIAgentConfig

Represents the configuration for an AI agent.

Link copied to clipboard
abstract override val environment: AIAgentEnvironment

Represents the environment in which the agent operates.

Link copied to clipboard
abstract override var executionInfo: AgentExecutionInfo

Represents the observability data associated with the AI Agent context.

Link copied to clipboard
abstract override val llm: AIAgentLLMContext

Represents the AI agent's LLM context, providing mechanisms for managing tools, prompts, and interaction with the execution environment. It ensures thread safety during concurrent read and write operations through the use of sessions.

Link copied to clipboard
abstract override val parentContext: AIAgentContext?

Represents the parent context of the AI Agent.

Link copied to clipboard
abstract override val pipeline: Pipeline

Represents the pipeline associated with the AI agent.

Link copied to clipboard
abstract override val runId: String

A unique identifier for the current session associated with the AI agent context. Used to track and differentiate sessions within the execution of the agent pipeline.

Link copied to clipboard
abstract override val stateManager: AIAgentStateManager

Manages and tracks the state of aт AI agent within the context of its execution.

Link copied to clipboard
abstract override val storage: AIAgentStorage

Concurrent-safe key-value storage for an agent, used to manage and persist data within the context of the AI agent stage execution. The storage property provides a thread-safe mechanism for sharing and storing data specific to the agent's operation.

Link copied to clipboard
abstract override val strategyName: String

Represents the name of the strategy being used in the current AI agent context.

Functions

Link copied to clipboard
inline fun <T> AIAgentContext.agentInput(): T

Utility function to get AIAgentContext.agentInput and try to cast it to some expected type.

Link copied to clipboard

Casts the current instance of a Message.Response to a Message.Assistant. This function should only be used when it is guaranteed that the instance is of type Message.Assistant, as it will throw an exception if the type does not match.

Link copied to clipboard

Attempts to cast a Message.Response instance to a Message.Assistant type.

Link copied to clipboard
abstract suspend fun compressHistory(strategy: HistoryCompressionStrategy = HistoryCompressionStrategy.WholeHistory, preserveMemory: Boolean = true)

Compresses the current LLM prompt (message history) into a summary, replacing messages with a TLDR.

Link copied to clipboard

Checks if the list of Message.Response contains any instances of Message.Tool.Call.

Link copied to clipboard

Extension function to access the Debugger feature from an agent context.

Link copied to clipboard
abstract suspend fun executeMultipleTools(toolCalls: List<Message.Tool.Call>, parallelTools: Boolean = false): List<ReceivedToolResult>

Executes multiple tool calls and returns their results. These calls can optionally be executed in parallel.

Link copied to clipboard
abstract suspend fun <ToolArg, TResult> executeSingleTool(tool: Tool<ToolArg, TResult>, toolArgs: ToolArg, doUpdatePrompt: Boolean = true): SafeTool.Result<TResult>

Calls a specific tool directly using the provided arguments.

Link copied to clipboard
abstract suspend fun executeTool(toolCall: Message.Tool.Call): ReceivedToolResult

Executes a tool call and returns the result.

Link copied to clipboard

Extracts a list of tool call messages from a given list of response messages.

Link copied to clipboard

Retrieves a feature from the AIAgentContext.pipeline associated with this context using the specified key.

Link copied to clipboard

Retrieves a feature from the AIAgentContext.pipeline associated with this context using the specified key or throws an exception if it is not available.

Link copied to clipboard
abstract override fun <T> get(key: AIAgentStorageKey<*>): T?

Retrieves data from the agent's storage using the specified key.

Link copied to clipboard

Retrieves the agent-specific context data associated with the current instance.

Link copied to clipboard
abstract suspend override fun getHistory(): List<Message>

Retrieves the history of messages exchanged during the agent's execution.

Link copied to clipboard
abstract suspend fun latestTokenUsage(): Int

Retrieves the latest token usage from the prompt within the LLM session.

Link copied to clipboard
abstract fun onAssistantMessage(response: Message.Response, action: (Message.Assistant) -> Unit)

Executes the provided action if the given response is of type Message.Assistant.

Link copied to clipboard

Filters the provided list of response messages to include only assistant messages and, if the filtered list is not empty, performs the specified action with the filtered list.

Link copied to clipboard
abstract fun onMultipleToolCalls(response: List<Message.Response>, action: (List<Message.Tool.Call>) -> Unit)

Invokes the provided action when multiple tool call messages are found within a given list of response messages. Filters the list of responses to include only instances of Message.Tool.Call and executes the action on the filtered list if it is not empty.

Link copied to clipboard
abstract override fun remove(key: AIAgentStorageKey<*>): Boolean

Removes a feature or data associated with the specified key from the agent's storage.

Link copied to clipboard

Removes the agent-specific context data associated with the current context.

Link copied to clipboard
abstract suspend fun requestLLM(message: String, allowToolCalls: Boolean = true): Message.Response

Sends a message to a Large Language Model (LLM) and optionally allows the use of tools during the LLM interaction. The message becomes part of the current prompt, and the LLM's response is processed accordingly, either with or without tool integrations based on the provided parameters.

Link copied to clipboard
abstract suspend fun requestLLMForceOneTool(message: String, tool: ToolDescriptor): Message.Response
abstract suspend fun requestLLMForceOneTool(message: String, tool: Tool<*, *>): Message.Response

Sends a message to a Large Language Model (LLM) and forces it to use a specific tool. The message becomes part of the current prompt, and the LLM is instructed to use only the specified tool.

Link copied to clipboard
abstract suspend fun requestLLMMultiple(message: String): List<Message.Response>

Sends a message to a Large Language Model (LLM) and gets multiple LLM responses with tool calls enabled. The message becomes part of the current prompt, and multiple responses from the LLM are collected.

Link copied to clipboard
abstract suspend fun requestLLMOnlyCallingTools(message: String): Message.Response

Sends a message to a Large Language Model (LLM) that will only call tools without generating text responses. The message becomes part of the current prompt, and the LLM is instructed to only use tools.

Link copied to clipboard
abstract suspend fun requestLLMStreaming(message: String, structureDefinition: StructureDefinition? = null): Flow<StreamFrame>

Sends a message to a Large Language Model (LLM) and streams the LLM response. The message becomes part of the current prompt, and the LLM's response is streamed as it's generated.

Link copied to clipboard

Provides the root context of the current agent. If the root context is not defined, this function defaults to returning the current instance.

Link copied to clipboard

Adds multiple tool results to the prompt and gets multiple LLM responses.

Link copied to clipboard
abstract suspend fun sendToolResult(toolResult: ReceivedToolResult): Message.Response

Adds a tool result to the prompt and requests an LLM response.

Link copied to clipboard
abstract override fun store(key: AIAgentStorageKey<*>, value: Any)

Stores a feature in the agent's storage using the specified key.

Link copied to clipboard

Stores the given agent context data within the current AI agent context.

Link copied to clipboard
abstract suspend fun <Input, OutputTransformed> subtask(taskDescription: String, input: Input, tools: List<Tool<*, *>>? = null, finishTool: Tool<*, OutputTransformed>, llmModel: LLModel? = null, llmParams: LLMParams? = null, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = null, responseProcessor: ResponseProcessor? = null): OutputTransformed

Executes a subtask within the AI agent's functional context. This method enables the use of tools to achieve a specific task based on the input provided. It defines the task using an inline function, employs tools iteratively, and attempts to complete the subtask with a designated finishing tool.

abstract suspend fun <Input, Output : Any> subtask(taskDescription: String, input: Input, outputClass: KClass<Output>, tools: List<Tool<*, *>>? = null, llmModel: LLModel? = null, llmParams: LLMParams? = null, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = null, responseProcessor: ResponseProcessor? = null): Output

Executes a subtask within the larger context of an AI agent's functional operation. This method allows you to define a specific task to be performed, using the given input, tools, and optional configuration parameters.

Link copied to clipboard
abstract suspend fun <Input> subtaskWithVerification(taskDescription: String, input: Input, tools: List<Tool<*, *>>? = null, llmModel: LLModel? = null, llmParams: LLMParams? = null, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = null, responseProcessor: ResponseProcessor? = null): CriticResult<Input>

Executes a subtask with validation and verification of the results. The method defines a subtask for the AI agent using the provided input and additional parameters and ensures that the output is evaluated based on its correctness and feedback.

Link copied to clipboard
inline fun <T> AIAgentContext.with(executionInfo: AgentExecutionInfo, block: (executionInfo: AgentExecutionInfo, eventId: String) -> T): T

Executes a block of code with a modified execution context.

inline fun <T> AIAgentContext.with(partName: String, block: (executionInfo: AgentExecutionInfo, eventId: String) -> T): T

Executes a block of code with a modified execution context, creating a parent-child relationship between execution contexts for tracing purposes.