GraphAIAgentService

class GraphAIAgentService<Input, Output>(val promptExecutor: PromptExecutor, val agentConfig: AIAgentConfig, val strategy: AIAgentGraphStrategy<Input, Output>, inputType: KType, outputType: KType, val toolRegistry: ToolRegistry, val installFeatures: GraphAIAgent.FeatureContext.() -> Unit) : AIAgentServiceBase<Input, Output> (source)

A service class for managing graph-based AI agents, responsible for orchestrating the behavior and execution of agents within a configurable graph-based strategy.

This class extends AIAgentServiceBase and provides an implementation for creating AI agents that follow a graph-based approach. It leverages a strategy pattern defined by AIAgentGraphStrategy to handle input and output transformations.

The GraphAIAgentService is marked with the InternalAgentsApi annotation, indicating that it is intended for internal use within agent-related implementations and not guaranteed for backward compatibility.

Parameters

promptExecutor

An instance of PromptExecutor, responsible for executing prompts using language models and handling responses.

Constructors

Link copied to clipboard
constructor(promptExecutor: PromptExecutor, agentConfig: AIAgentConfig, strategy: AIAgentGraphStrategy<Input, Output>, inputType: KType, outputType: KType, toolRegistry: ToolRegistry, installFeatures: GraphAIAgent.FeatureContext.() -> Unit)

Properties

Link copied to clipboard
open override val agentConfig: AIAgentConfig

Holds the configuration details for an AI agent.

Link copied to clipboard
Link copied to clipboard
open override val promptExecutor: PromptExecutor
Link copied to clipboard
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): AIAgent<Input, Output>

Creates a managed AI agent with the specified identifier and clock.

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.