subgraphWithRetrySimple
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>(source)
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.
Parameters
condition
A suspendable function that determines whether the condition is met, based on the output.
maxRetries
The maximum number of retries allowed if the condition is not met.
toolSelectionStrategy
The strategy used to select tools for this subgraph.
strict
If true, an exception is thrown if the condition is not met after the maximum retries.
name
An optional name for the subgraph.
defineAction
A lambda defining the actions within the subgraph.
Example usage:
val subgraphRetryCallLLM by subgraphWithRetrySimple(
condition = { it is Message.Tool.Call},
maxRetries = 2,
) {
val nodeCallLLM by nodeLLMRequest("sendInput")
nodeStart then nodeCallLLM then nodeFinish
}
val nodeExecuteTool by nodeExecuteTool("nodeExecuteTool")
edge(subgraphRetryCallLLM forwardTo nodeExecuteTool onToolCall { true })
Content copied to clipboard