Package-level declarations

Types

Link copied to clipboard

Represents a basic interface for AI agent.

Link copied to clipboard
open class AIAgentException(problem: String, throwable: Throwable? = null) : Exception

Represents a custom exception class for use in AI Agent-related processes.

Link copied to clipboard
class AIAgentFunctionalContext(val environment: AIAgentEnvironment, val agent: FunctionalAIAgent<*, *>, val runId: String, val agentInput: Any?, val config: AIAgentConfig, val llm: AIAgentLLMContext, val stateManager: AIAgentStateManager, val storage: AIAgentStorage, val strategyName: String, val pipeline: AIAgentNonGraphPipeline, val parentContext: AIAgentContext? = null) : AIAgentContext

Represents the execution context for an AI agent operating in a loop. It provides access to critical parts such as the environment, configuration, large language model (LLM) context, state management, and storage. Additionally, it enables the agent to store, retrieve, and manage context-specific data during its execution lifecycle.

Link copied to clipboard

A strategy for implementing AI agent behavior that operates in a loop-based manner.

Link copied to clipboard

AIAgentService is a core interface for managing AI agents. The service allows creation, removal, and management of AI agents and provides functionalities to list agents based on their statuses.f

Link copied to clipboard

Abstract base class for implementing an AI Agent Service. This class provides foundational functionality for managing and interacting with AI agents.

Link copied to clipboard
class AIAgentTool<Input, Output>(agentService: AIAgentService<Input, Output>, agentName: String, agentDescription: String, inputDescription: String? = null, inputSerializer: KSerializer<Input>, outputSerializer: KSerializer<Output>, json: Json = Json.Default, parentAgentId: String? = null) : Tool<AIAgentTool.AgentToolArgs, AIAgentTool.AgentToolResult>

AIAgentTool is a generic tool that wraps an AI agent to facilitate integration with the context of a tool execution framework. It enables the serialization, deserialization, and execution of an AI agent's operations.

Link copied to clipboard
class FunctionalAIAgent<Input, Output>(val promptExecutor: PromptExecutor, val agentConfig: AIAgentConfig, val toolRegistry: ToolRegistry = ToolRegistry.EMPTY, strategy: AIAgentFunctionalStrategy<Input, Output>, id: String? = null, val clock: Clock = Clock.System, val featureContext: FunctionalAIAgent.FeatureContext.() -> Unit = {}) : StatefulSingleUseAIAgent<Input, Output, AIAgentFunctionalContext>

Represents the core AI agent for processing input and generating output using a defined configuration, toolset, and prompt execution pipeline.

Link copied to clipboard
class FunctionalAIAgentService<Input, Output>(val promptExecutor: PromptExecutor, val agentConfig: AIAgentConfig, val strategy: AIAgentFunctionalStrategy<Input, Output>, val toolRegistry: ToolRegistry, val installFeatures: FunctionalAIAgent.FeatureContext.() -> Unit) : AIAgentServiceBase<Input, Output>

A service for managing functional AI agents that operate based on a specified execution strategy.

Link copied to clipboard
open class GraphAIAgent<Input, Output>(val inputType: KType, val outputType: KType, val promptExecutor: PromptExecutor, val agentConfig: AIAgentConfig, val toolRegistry: ToolRegistry = ToolRegistry.EMPTY, strategy: AIAgentGraphStrategy<Input, Output>, id: String? = null, val clock: Clock = Clock.System, val installFeatures: GraphAIAgent.FeatureContext.() -> Unit = {}) : StatefulSingleUseAIAgent<Input, Output, AIAgentGraphContextBase> , Closeable

Represents an implementation of an AI agent that provides functionalities to execute prompts, manage tools, handle agent pipelines, and interact with various configurable strategies and features.

Link copied to clipboard
class GraphAIAgentService<Input, Output>(val promptExecutor: PromptExecutor, val agentConfig: AIAgentConfig, val strategy: AIAgentGraphStrategy<Input, Output>, inputType: KType, outputType: KType, val toolRegistry: ToolRegistry, val installFeatures: GraphAIAgent.FeatureContext.() -> Unit) : AIAgentServiceBase<Input, Output>

A service class for managing graph-based AI agents, responsible for orchestrating the behavior and execution of agents within a configurable graph-based strategy.

Link copied to clipboard
abstract class StatefulSingleUseAIAgent<Input, Output, TContext : AIAgentContext>(val strategy: AIAgentStrategy<Input, Output, TContext>, logger: KLogger, agentId: String? = null) : AIAgent<Input, Output>

Abstract base class representing a single-use AI agent with state.

Link copied to clipboard

Enum representing the modes in which a single-run strategy for an AI agent can be executed.

Functions

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
inline fun <Input, Output> AIAgent<Input, Output>.asTool(agentName: String, agentDescription: String, inputDescription: String? = null, inputSerializer: KSerializer<Input> = serializer(), outputSerializer: KSerializer<Output> = serializer(), json: Json = Json.Default): Tool<AIAgentTool.AgentToolArgs, AIAgentTool.AgentToolResult>

Converts the current AI agent into a tool to allow using it in other agents as a tool.

Link copied to clipboard
suspend fun AIAgentFunctionalContext.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
inline fun <Input, Output> AIAgentService<Input, Output>.createAgentTool(agentName: String, agentDescription: String, inputDescription: String? = null, inputSerializer: KSerializer<Input> = serializer(), outputSerializer: KSerializer<Output> = serializer(), json: Json = Json.Default, parentAgentId: String? = null, clock: Clock = Clock.System): Tool<AIAgentTool.AgentToolArgs, AIAgentTool.AgentToolResult>

Creates an AIAgent and converts it to a Tool that can be used by other AI Agents.

Link copied to clipboard

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

Link copied to clipboard

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

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

Link copied to clipboard

Creates an AIAgentFunctionalStrategy with the specified loop logic and name.

Link copied to clipboard
operator fun AIAgentService.Companion.invoke(promptExecutor: PromptExecutor, agentConfig: AIAgentConfig, strategy: AIAgentGraphStrategy<String, String> = singleRunStrategy(), toolRegistry: ToolRegistry = ToolRegistry.EMPTY, installFeatures: GraphAIAgent.FeatureContext.() -> Unit = {}): GraphAIAgentService<String, String>

Invokes the process to create and return an instance of GraphAIAgentService.

Link copied to clipboard
suspend fun AIAgent<*, *>.isFinished(): Boolean

Checks whether the AI agent has reached a finished state.

Link copied to clipboard
suspend fun AIAgent<*, *>.isRunning(): Boolean

Checks whether the AI agent is currently in a running state.

Link copied to clipboard

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

Link copied to clipboard

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

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
suspend fun AIAgentFunctionalContext.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

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 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

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
suspend fun AIAgentFunctionalContext.requestLLMStreaming(message: String, structureDefinition: StructuredDataDefinition? = 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
inline suspend fun <T> AIAgentFunctionalContext.requestLLMStructured(message: String, examples: List<T> = emptyList(), fixingParser: StructureFixingParser? = null): Result<StructuredResponse<T>>

Sends a message to a Large Language Model (LLM) and requests structured data from the LLM with error correction capabilities. The message becomes part of the current prompt, and the LLM's response is processed to extract structured data.

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard
fun singleRunStrategy(runMode: ToolCalls = ToolCalls.SINGLE_RUN_SEQUENTIAL): AIAgentGraphStrategy<String, String>

Creates a single-run strategy for an AI agent. This strategy defines a simple execution flow where the agent processes input, calls tools, and sends results back to the agent. The flow consists of the following steps: