FunctionalAIAgentService

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

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

This class provides the infrastructure for creating and managing functional AI agents. It integrates an execution strategy with associated input and output types, a tool registry for additional functionalities, and a customizable feature installation context.

Parameters

Input

The type of input data that the functional AI agent will process.

Output

The type of output data produced by the functional AI agent.

Constructors

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

Properties

Link copied to clipboard
open override val agentConfig: AIAgentConfig

The configuration settings for the AI agent, including model and prompt behavior.

Link copied to clipboard
open override val promptExecutor: PromptExecutor

The executor responsible for handling and executing prompts.

Link copied to clipboard

The functional strategy defining the agent's iteration logic and processing behavior.

Link copied to clipboard
open override val toolRegistry: ToolRegistry

Represents the central repository or registry for managing tools within the system.

Functions

Link copied to clipboard
suspend override fun agentById(id: String): AIAgent<Input, Output>?

Retrieves an AI agent managed by this service based on the provided unique identifier.

Link copied to clipboard
open suspend fun closeAll()

Closes all AI agents currently managed by the service.

Link copied to clipboard
suspend override fun createAgent(id: String?, clock: Clock): AIAgent<Input, Output>

Creates and registers a new AI agent using the provided agent ID and clock.

Link copied to clipboard
open suspend fun createAgentAndRun(agentInput: Input, id: String? = null, clock: Clock = Clock.System): Output

Creates a new AI agent with the specified optional parameters (id, clock), executes it with the given input, and retrieves the resulting output.

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
open override fun createManagedAgent(id: String?, clock: Clock): FunctionalAIAgent<Input, Output>

Creates and returns a managed instance of FunctionalAIAgent.

Link copied to clipboard
suspend override fun listActiveAgents(): List<AIAgent<Input, Output>>

Retrieves a list of all currently active AI agents managed by the service.

Link copied to clipboard
open suspend override fun listAllAgents(): List<AIAgent<Input, Output>>

Retrieves a list of all AI agents currently managed by the service, regardless of their state (e.g., active, inactive, or finished).

Link copied to clipboard
suspend override fun listFinishedAgents(): List<AIAgent<Input, Output>>

Retrieves a list of all agents that have already finished their task.

Link copied to clipboard
suspend override fun listInactiveAgents(): List<AIAgent<Input, Output>>

Retrieves a list of inactive AI agents managed by this service.

Link copied to clipboard
suspend override fun removeAgent(agent: AIAgent<Input, Output>): Boolean

Removes the specified AI agent from the managed collection.

Link copied to clipboard
suspend override fun removeAgentWithId(id: String): Boolean

Removes a managed AI agent identified by the specified unique identifier.