Package-level declarations

Types

Link copied to clipboard

Provides an implementation of ProvideSubgraphResult for handling StringSubgraphResult.

Link copied to clipboard

Represents an abstract result type for subgraph provisioning tools.

Link copied to clipboard

Represents a concrete implementation of ProvideSubgraphResult specialized to handle verified subgraph results.

Link copied to clipboard
data class RetrySubgraphResult<Output>(val output: Output, val success: Boolean, val retryCount: Int)

Represents the result of subgraphWithRetry.

Link copied to clipboard

The result which subgraphs can return.

Link copied to clipboard

Represents the result of a subgraph operation encapsulated as a string.

Link copied to clipboard

The result which subgraphs can return.

Link copied to clipboard
data class VerifiedSubgraphResult(val correct: Boolean, val message: String) : SubgraphResult

Represents the result of a verified subgraph execution.

Functions

Link copied to clipboard

Creates and configures a ai.koog.agents.core.agent.entity.AIAgentStrategy for executing a chat interaction process. The agent orchestrates interactions between different stages, nodes, and tools to handle user input, execute tools, and provide responses. Allows the agent to interact with the user in a chat-like manner.

Link copied to clipboard
fun reActStrategy(reasoningInterval: Int = 1, name: String = "re_act"): AIAgentStrategy<String, String>

Creates a ReAct AI agent strategy that alternates between reasoning and execution stages to dynamically process tasks and request outputs from an LLM.

Link copied to clipboard
inline fun <Input : Any, Output> AIAgentSubgraphBuilderBase<*, *>.subgraphWithRetry(noinline condition: suspend (Output) -> Boolean, maxRetries: Int, toolSelectionStrategy: ToolSelectionStrategy = ToolSelectionStrategy.ALL, name: String? = null, noinline defineAction: AIAgentSubgraphBuilderBase<Input, Output>.() -> Unit): AIAgentSubgraphDelegate<Input, RetrySubgraphResult<Output>>

Creates a subgraph with retry mechanism, allowing a specified action subgraph to be retried multiple times until a given condition is met or the maximum number of retries is reached.

Link copied to clipboard
inline fun <Input : Any, Output> AIAgentSubgraphBuilderBase<*, *>.subgraphWithRetrySimple(noinline condition: suspend (Output) -> Boolean, maxRetries: Int, toolSelectionStrategy: ToolSelectionStrategy = ToolSelectionStrategy.ALL, strict: Boolean = true, name: String? = null, noinline defineAction: AIAgentSubgraphBuilderBase<Input, Output>.() -> Unit): AIAgentSubgraphDelegate<Input, Output>

Creates a subgraph that includes retry functionality based on a given condition and a maximum number of retries. If the condition is not met after the specified retries and strict mode is enabled, an exception is thrown. Unlike subgraphWithRetry, this function directly returns the output value instead of a RetrySubgraphResult.

Link copied to clipboard
inline fun <Input> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(toolSelectionStrategy: ToolSelectionStrategy, llmModel: LLModel? = null, llmParams: LLMParams? = null, noinline defineTask: suspend AIAgentContextBase.(input: Input) -> String): AIAgentSubgraphDelegate<Input, StringSubgraphResult>
inline fun <Input> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(tools: List<Tool<*, *>>, llmModel: LLModel? = null, llmParams: LLMParams? = null, noinline defineTask: suspend AIAgentContextBase.(input: Input) -> String): AIAgentSubgraphDelegate<Input, StringSubgraphResult>

Creates a subgraph with a predefined task definition using the provided tools, model, and parameters.

inline fun <Input, ProvidedResult : SubgraphResult> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(toolSelectionStrategy: ToolSelectionStrategy, finishTool: ProvideSubgraphResult<ProvidedResult>, llmModel: LLModel? = null, llmParams: LLMParams? = null, noinline defineTask: suspend AIAgentContextBase.(input: Input) -> String): AIAgentSubgraphDelegate<Input, ProvidedResult>

Creates a subgraph, which performs one specific task, defined by defineTask, using the tools defined by toolSelectionStrategy. When LLM believes that the task is finished, it will call finishTool, generating ProvidedResult as its argument. The generated ProvidedResult is the result of this subgraph. The subgraph returns a wrapper SafeTool.Result to handle cases when the model didn't reach the finish condition or didn't generate a final ProvidedResult due to an error (reported as SafeTool.Result.Failure)

inline fun <Input, ProvidedResult : SubgraphResult> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(tools: List<Tool<*, *>>, finishTool: ProvideSubgraphResult<ProvidedResult>, llmModel: LLModel? = null, llmParams: LLMParams? = null, noinline defineTask: suspend AIAgentContextBase.(input: Input) -> String): AIAgentSubgraphDelegate<Input, ProvidedResult>

Creates a subgraph with a task definition and specified tools. The subgraph uses the provided tools to process input and execute the defined task, eventually producing a result through the provided finish tool.

Link copied to clipboard
inline fun <Input> AIAgentSubgraphBuilderBase<*, *>.subgraphWithVerification(toolSelectionStrategy: ToolSelectionStrategy, llmModel: LLModel? = null, llmParams: LLMParams? = null, noinline defineTask: suspend AIAgentContextBase.(input: Input) -> String): AIAgentSubgraphDelegate<Input, VerifiedSubgraphResult>

subgraphWithTask with VerifiedSubgraphResult result. It verifies if the task was performed correctly or not, and describes the problems if any.

inline fun <Input> AIAgentSubgraphBuilderBase<*, *>.subgraphWithVerification(tools: List<Tool<*, *>>, llmModel: LLModel? = null, llmParams: LLMParams? = null, noinline defineTask: suspend AIAgentContextBase.(input: Input) -> String): AIAgentSubgraphDelegate<Input, VerifiedSubgraphResult>

Constructs a subgraph within an AI agent's strategy graph with additional verification capabilities.