Package-level declarations

Types

Link copied to clipboard
sealed interface ConditionResult

Represents the result of evaluating a specific condition in a system or workflow. This sealed interface allows for expressing various outcomes of a condition check.

Link copied to clipboard
data class CriticResult<T>(val successful: Boolean, val feedback: String, val input: T)

Represents the result of a critique or feedback process.

Link copied to clipboard
data class CriticResultFromLLM(val isCorrect: Boolean, val feedback: String)

Represents the result of a plan evaluation performed by an LLM (Large Language Model).

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

Utility object providing tools and methods for working with subgraphs and tasks in a controlled and structured way. These utilities are designed to help finalize subgraph-related tasks and encapsulate result handling within tool constructs.

Properties

Link copied to clipboard

Extension property that converts a Boolean to a ConditionResult.

Functions

Link copied to clipboard

Creates and configures a ai.koog.agents.core.agent.entity.AIAgentGraphStrategy 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
inline fun <T> AIAgentSubgraphBuilderBase<*, *>.llmAsAJudge(llmModel: LLModel? = null, task: String): AIAgentNodeDelegate<T, CriticResult<T>>

A method to utilize a language model (LLM) as a critic or judge for evaluating tasks with context-aware feedback. This method processes a given task and the interaction history to provide structured feedback on the task's correctness.

Link copied to clipboard
fun reActStrategy(reasoningInterval: Int = 1, name: String = "re_act"): AIAgentGraphStrategy<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

Configures a subgraph within the AI agent framework, associating it with required tasks and operations.

Link copied to clipboard
inline fun <Input, Output> structuredOutputWithToolsStrategy(config: StructuredOutputConfig<Output>, parallelTools: Boolean = false, noinline transform: suspend AIAgentGraphContextBase.(input: Input) -> String): AIAgentGraphStrategy<Input, Output>

Defines a strategy for handling structured output with tools integration using specified configuration and execution logic.

Link copied to clipboard
inline fun <Input : Any, Output> AIAgentSubgraphBuilderBase<*, *>.subgraphWithRetry(noinline condition: suspend AIAgentGraphContextBase.(Output) -> ConditionResult, maxRetries: Int, conditionDescription: String? = null, 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 AIAgentGraphContextBase.(Output) -> ConditionResult, maxRetries: Int, conditionDescription: String? = null, 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, Output> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(toolSelectionStrategy: ToolSelectionStrategy, llmModel: LLModel? = null, llmParams: LLMParams? = null, noinline defineTask: suspend AIAgentGraphContextBase.(input: Input) -> String): AIAgentSubgraphDelegate<Input, Output>

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, Output> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(tools: List<Tool<*, *>>, llmModel: LLModel? = null, llmParams: LLMParams? = null, noinline defineTask: suspend AIAgentGraphContextBase.(input: Input) -> String): AIAgentSubgraphDelegate<Input, Output>

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.

inline fun <Input, Output, OutputTransformed> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(toolSelectionStrategy: ToolSelectionStrategy, finishTool: Tool<Output, OutputTransformed>, llmModel: LLModel? = null, llmParams: LLMParams? = null, noinline defineTask: suspend AIAgentGraphContextBase.(input: Input) -> String): AIAgentSubgraphDelegate<Input, OutputTransformed>

Defines a subgraph with a specific task to be performed by an AI agent.

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

Creates a subgraph with a specified task definition, a list of tools, and a finish tool to transform output.

inline fun <Input, Output> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(toolSelectionStrategy: ToolSelectionStrategy, finishToolFunction: KFunction<Output>, llmModel: LLModel? = null, llmParams: LLMParams? = null, noinline defineTask: suspend AIAgentGraphContextBase.(input: Input) -> String): AIAgentSubgraphDelegate<Input, Output>

Creates a subgraph within an AI agent graph using a defined task, a tool selection strategy, and a finish tool function. This method provides the capability to integrate task-specific logic and tool selection into the AI agent's subgraph.

inline fun <Input, Output> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(tools: List<Tool<*, *>>, finishToolFunction: KFunction<Output>, llmModel: LLModel? = null, llmParams: LLMParams? = null, noinline defineTask: suspend AIAgentGraphContextBase.(input: Input) -> String): AIAgentSubgraphDelegate<Input, Output>

Defines a subgraph with a specific task in an AI agent graph, enabling the coordination of tools, task definitions, and execution logic.

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

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

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

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