AIAgentFunctionalContextBaseCommon

Base AIAgentContext implementation providing functionality common across platforms

Inheritors

Properties

Link copied to clipboard
open override val agentId: String

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

Link copied to clipboard
open override val agentInput: Any?

Represents the input provided to the agent's execution.

Link copied to clipboard
open override val config: AIAgentConfig

Represents the configuration for an AI agent.

Link copied to clipboard
open override val environment: AIAgentEnvironment

Represents the environment in which the agent operates.

Link copied to clipboard

Represents the observability data associated with the AI Agent context.

Link copied to clipboard
open 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
open override val parentContext: AIAgentContext?

Represents the parent context of the AI Agent.

Link copied to clipboard
open override val pipeline: Pipeline

Represents the pipeline associated with the AI agent.

Link copied to clipboard
open 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

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

Link copied to clipboard
open 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
open 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
suspend fun appendPrompt(body: PromptBuilder.() -> Unit)

Appends messages to the current LLM prompt without making an LLM request. Corresponds to nodeAppendPrompt.

Link copied to clipboard
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

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

Link copied to clipboard
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

Executes a tool call and returns the result.

Link copied to clipboard
suspend fun executeTools(message: Message.Assistant, parallelTools: Boolean = false): List<ReceivedToolResult>

Executes all tool calls from a Message.Assistant and returns their results. Corresponds to nodeExecuteToolsAndGetReceivedResults.

suspend fun executeTools(toolCalls: List<MessagePart.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

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

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

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard
suspend fun latestTokenUsage(): Int

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

Link copied to clipboard
suspend fun moderateMessage(message: Message, moderatingModel: LLModel? = null, includeCurrentPrompt: Boolean = false): ModerationResult

Moderates a message using the LLM. Corresponds to nodeLLMModerateMessage.

Link copied to clipboard

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

Link copied to clipboard

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 MessagePart.Tool.Call and executes the action on the filtered list if it is not empty.

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard
suspend fun requestLLM(message: String): Message.Assistant

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. Corresponds to nodeLLMRequestWithUserText.

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

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

Sends a string message to the LLM and returns multiple response choices. Corresponds to nodeLLMRequestMultipleChoicesWithUserText.

Link copied to clipboard

Sends a string message to the LLM without tool calls. Corresponds to nodeLLMRequestOnlyCallingToolsWithUserText.

Link copied to clipboard
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
suspend fun <T> requestLLMStructured(message: String, config: StructuredRequestConfig<T>, fixingParser: StructureFixingParser? = null): Result<StructuredResponse<T>>

Sends a string message to the LLM and returns a structured response using a StructuredRequestConfig. Corresponds to nodeLLMRequestStructuredWithUserText.

inline suspend fun <T> requestLLMStructured(message: String, examples: List<T> = emptyList(), fixingParser: StructureFixingParser? = null): Result<StructuredResponse<T>>

Sends a structured request to the Large Language Model (LLM) and processes the response.

Link copied to clipboard

Sends a string message to the LLM without tool calls. Corresponds to nodeLLMRequestWithoutToolsWithUserText.

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 a tool result to the prompt and requests an LLM response.

Link copied to clipboard

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

Link copied to clipboard

Sends tool results to the LLM and forces it to use a specific tool. Corresponds to nodeSendToolReceivedResultsForceOneTool.

Link copied to clipboard

Sends tool results to the LLM and returns multiple response choices. Corresponds to nodeSendToolReceivedResultsMultipleChoices.

Link copied to clipboard

Sends tool results to the LLM, restricting it to only calling tools. Corresponds to nodeSendToolReceivedResultsOnlyCallingTools.

Link copied to clipboard

Sends tool results to the LLM without allowing further tool calls. Corresponds to nodeSendToolReceivedResultsWithoutTools.

Link copied to clipboard

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

Link copied to clipboard
inline suspend fun <Output : Any> subtask(taskDescription: String, tools: List<ToolBase<*, *>>? = null, llmModel: LLModel? = null, llmParams: LLMParams? = null, parallelTools: Boolean = false, assistantResponseRepeatMax: Int? = null, responseProcessor: ResponseProcessor? = null): Output
suspend fun <Output : Any> subtask(taskDescription: String, outputClass: KClass<Output>, tools: List<ToolBase<*, *>>? = null, llmModel: LLModel? = null, llmParams: LLMParams? = null, parallelTools: Boolean = false, assistantResponseRepeatMax: Int? = null, responseProcessor: ResponseProcessor? = null): Output

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

suspend fun <OutputTransformed> subtask(taskDescription: String, tools: List<ToolBase<*, *>>? = null, finishTool: Tool<*, OutputTransformed>, llmModel: LLModel? = null, llmParams: LLMParams? = null, parallelTools: Boolean = false, 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.

Link copied to clipboard
suspend fun subtaskWithVerification(taskDescription: String, tools: List<ToolBase<*, *>>? = null, llmModel: LLModel? = null, llmParams: LLMParams? = null, parallelTools: Boolean = false, assistantResponseRepeatMax: Int? = null, responseProcessor: ResponseProcessor? = null): CriticResult<String>

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.