AIAgentBase

abstract class AIAgentBase<Input, Output, TContext : AIAgentContext>(logger: KLogger, id: String? = null) : AIAgent<Input, Output> (source)

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

This AI agent is designed to execute a specific long-running strategy only once, and provides API to monitor and manage it's state.

It maintains internal states including its running status, whether it was started, its result (if available), and the root context associated with its execution. The class enforces safe state transitions and provides thread-safe operations via a mutex.

Parameters

Input

the type of the input accepted by the agent.

Output

the type of the output produced by the agent.

TContext

the type of the context used during the agent's execution, extending AIAgentContext.

id

the unique identifier for the agent. Random UUID will be generated if set to null.

Inheritors

Constructors

Link copied to clipboard
constructor(logger: KLogger, id: String? = null)

Properties

Link copied to clipboard
expect abstract val agentConfig: AIAgentConfig

The configuration for the AI agent.

Link copied to clipboard
override val id: String

Represents the unique identifier for the AI agent.

Link copied to clipboard

Represents the pipeline used by the AI agent for processing tasks or data.

Link copied to clipboard

The execution strategy defining how the agent processes input and produces output.

Functions

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<Input, AIAgentTool.AgentToolResult<Output>>

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

Closes the AI Agent and performs necessary cleanup operations.

Link copied to clipboard
open override fun createSession(sessionId: String?): AIAgentRunSession<Input, Output, TContext>

Creates a new AIAgentRunSession for executing the agent with the given input.

Link copied to clipboard
abstract suspend fun prepareContext(agentInput: Input, runId: String, eventId: String): TContext

Prepares and initializes the agent context required to handle the given input and run ID.

Link copied to clipboard
open suspend override fun run(agentInput: Input, sessionId: String?): Output

Executes the agent's main functionality, coordinating with various components such as pipelines and strategies. Ensures the agent is run in a thread-safe manner using locking mechanisms.