FunctionalAIAgent

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

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

Parameters

Input

The type of input data expected by the agent.

Output

The type of output data produced by the agent.

id

The unique identifier for the agent instance.

promptExecutor

The executor responsible for processing prompts and interacting with language models.

agentConfig

The configuration for the agent, including the prompt structure and execution parameters.

toolRegistry

The registry of tools available for the agent. Defaults to an empty registry if not specified.

Constructors

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

Types

Link copied to clipboard

Represents a context for managing and configuring features in an AI agent. Provides functionality to install and configure features into a specific instance of an AI agent.

Properties

Link copied to clipboard
open override val agentConfig: AIAgentConfig
Link copied to clipboard
val clock: Clock
Link copied to clipboard
override val id: String

A unique identifier represented as a string. This identifier is lazily initialized. If a value is present in agentId, it will use that; otherwise, it will generate a random UUID string.

Link copied to clipboard

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

Link copied to clipboard
Link copied to clipboard

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

Link copied to clipboard

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<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 override fun close()

Closes the AI Agent and performs necessary cleanup operations.

Link copied to clipboard
open override fun <Feature : Any> feature(key: AIAgentStorageKey<Feature>): Feature?

Retrieves a feature associated with the given key from the current context.

Link copied to clipboard

Retrieves a specific agent feature of type Feature from the AI agent's storage. If the requested feature is not found, throws an IllegalStateException.

Link copied to clipboard
suspend override fun getState(): AIAgent.Companion.State<Output>

Retrieves the current state of the AI agent during its lifecycle.

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
open suspend override fun prepareContext(agentInput: Input, runId: String): AIAgentFunctionalContext

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

Link copied to clipboard
open suspend fun result(): Output

Retrieves the result of the operation if the current state is State.Finished. Throws an IllegalStateException if the operation is not in a finished state.

Link copied to clipboard
suspend override fun run(agentInput: Input): 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.