AIAgent

open class AIAgent<Input, Output>(val inputType: KType, val outputType: KType, val promptExecutor: PromptExecutor, strategy: AIAgentStrategy<Input, Output>, val agentConfig: AIAgentConfigBase, val id: String = Uuid.random().toString(), val toolRegistry: ToolRegistry = ToolRegistry.EMPTY, val clock: Clock = Clock.System, installFeatures: AIAgent.FeatureContext.() -> Unit = {}) : AIAgentBase<Input, Output> , AIAgentEnvironment, Closeable(source)

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.

The agent operates within a coroutine scope and leverages a tool registry and feature context to enable dynamic additions or configurations during its lifecycle. Its behavior is driven by a local agent strategy and executed via a prompt executor.

Parameters

Input

Type of agent input.

Output

Type of agent output.

Constructors

Link copied to clipboard
constructor(inputType: KType, outputType: KType, promptExecutor: PromptExecutor, strategy: AIAgentStrategy<Input, Output>, agentConfig: AIAgentConfigBase, id: String = Uuid.random().toString(), toolRegistry: ToolRegistry = ToolRegistry.EMPTY, clock: Clock = Clock.System, installFeatures: AIAgent.FeatureContext.() -> Unit = {})

Initializes the AI agent instance and prepares the feature context and pipeline for use.

Types

Link copied to clipboard

The context for adding and configuring features in a Kotlin AI Agent instance.

Properties

Link copied to clipboard

Configuration details for the local agent that define its operational parameters.

Link copied to clipboard
val clock: Clock

The clock used to calculate message timestamps

Link copied to clipboard
open override val id: String

Represents the unique identifier for the AI agent.

Link copied to clipboard

KType representing Input - agent input.

Link copied to clipboard

KType representing Output - agent output.

Link copied to clipboard

Executor used to manage and execute prompt strings.

Link copied to clipboard

Registry of tools the agent can interact with, defaulting to an empty registry.

Functions

Link copied to clipboard
inline fun <Input, Output> AIAgentBase<Input, Output>.asTool(agentName: String, agentDescription: String, inputDescriptor: ToolParameterDescriptor, 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
open suspend override fun close()
Link copied to clipboard

Executes a single tool call and retrieves the result.

Link copied to clipboard
open suspend override fun executeTools(toolCalls: List<Message.Tool.Call>): List<ReceivedToolResult>

Executes a list of tool calls and returns their corresponding results.

Link copied to clipboard
open suspend override fun reportProblem(exception: Throwable)

Reports a problem that occurred within the environment.

Link copied to clipboard
open suspend override fun run(agentInput: Input): Output

Executes the AI agent with the given input and retrieves the resulting output.