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
inline fun <Input, Output, OutputTransformed> AIAgentSubgraphBuilderBase<Input, OutputTransformed>.setupSubgraphWithTask(finishTool: Tool<Output, OutputTransformed>, assistantResponseRepeatMax: Int? = null, noinline defineTask: suspend AIAgentGraphContextBase.(Input) -> String)

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

inline fun <Input, Output, OutputTransformed> AIAgentSubgraphBuilderBase<Input, OutputTransformed>.setupSubgraphWithTask(finishTool: Tool<Output, OutputTransformed>, runMode: ToolCalls, assistantResponseRepeatMax: Int? = null, noinline defineTask: suspend AIAgentGraphContextBase.(Input) -> String)

Configures and sets up a subgraph with task handling, including tool execution operations, assistant response management, and task finalization logic.

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, name: String? = null, llmModel: LLModel? = null, llmParams: LLMParams? = null, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = 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.

inline fun <Input, Output> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(tools: List<Tool<*, *>>, name: String? = null, llmModel: LLModel? = null, llmParams: LLMParams? = null, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = 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>, name: String? = null, llmModel: LLModel? = null, llmParams: LLMParams? = null, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = 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>, name: String? = null, llmModel: LLModel? = null, llmParams: LLMParams? = null, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = 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, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = 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, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = 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.

Link copied to clipboard
inline suspend fun <Input, Output> AIAgentFunctionalContext.subtask(input: Input, tools: List<Tool<*, *>>? = null, llmModel: LLModel? = null, llmParams: LLMParams? = null, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = null, defineTask: suspend AIAgentFunctionalContext.(input: Input) -> String): Output

Executes a subtask within the larger context of an AI agent's functional operation. This method allows you to define a specific task to be performed, using the given input, tools, and optional configuration parameters.

inline suspend fun <Input, Output, OutputTransformed> AIAgentFunctionalContext.subtask(input: Input, tools: List<Tool<*, *>>? = null, finishTool: Tool<Output, OutputTransformed>, llmModel: LLModel? = null, llmParams: LLMParams? = null, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = null, defineTask: suspend AIAgentFunctionalContext.(input: Input) -> String): OutputTransformed

Executes a subtask within the AI agent's functional context. This method enables the use of tools to achieve a specific task based on the input provided. It defines the task using an inline function, employs tools iteratively, and attempts to complete the subtask with a designated finishing tool.

Link copied to clipboard
inline suspend fun <Input> AIAgentFunctionalContext.subtaskWithVerification(input: Input, tools: List<Tool<*, *>>? = null, llmModel: LLModel? = null, llmParams: LLMParams? = null, runMode: ToolCalls = ToolCalls.SEQUENTIAL, assistantResponseRepeatMax: Int? = null, defineTask: suspend AIAgentFunctionalContext.(input: Input) -> String): CriticResult<Input>

Executes a subtask with validation and verification of the results. The method defines a subtask for the AI agent using the provided input and additional parameters and ensures that the output is evaluated based on its correctness and feedback.