AIAgent

open class AIAgent(val promptExecutor: PromptExecutor, strategy: AIAgentStrategy, val agentConfig: AIAgentConfigBase, val toolRegistry: ToolRegistry = ToolRegistry.EMPTY, installFeatures: AIAgent.FeatureContext.() -> Unit = {}) : AIAgentBase, 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.

Constructors

Link copied to clipboard
constructor(promptExecutor: PromptExecutor, strategy: AIAgentStrategy, agentConfig: AIAgentConfigBase, toolRegistry: ToolRegistry = ToolRegistry.EMPTY, 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

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
fun AIAgentBase.asTool(agentDescription: String, name: String? = null, requestDescription: String = "Input for the task"): Tool<AIAgentTool.AgentToolArgs, AIAgentTool.AgentToolResult>

Converts the current AI agent into a tool that can be utilized with the specified parameters.

Link copied to clipboard
open suspend override fun close()
Link copied to clipboard
Link copied to clipboard
open suspend override fun executeTools(toolCalls: List<Message.Tool.Call>): List<ReceivedToolResult>
Link copied to clipboard
open suspend override fun reportProblem(exception: Throwable)
Link copied to clipboard
open suspend override fun run(agentInput: String)

Initiates the execution of the AI agent based on the provided input prompt.

suspend fun run(builder: suspend TextContentBuilder.() -> Unit)
Link copied to clipboard
open suspend override fun runAndGetResult(agentInput: String): String?

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

Link copied to clipboard
open suspend override fun sendTermination(result: String?)