subgraphWithTask

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>(source)

Creates a subgraph, which performs one specific task, defined by defineTask, using the tools defined by toolSelectionStrategy.

Use this function if you need the agent to perform a single task which outputs a structured result.

Return

A delegate that represents the created subgraph, allowing input and output operations.

Parameters

Input

The input type for the task to be defined in the subgraph.

Output

The output type for the subgraph's finalized result.

toolSelectionStrategy

The strategy used to select tools for the subgraph operations.

name

An optional name for the subgraph. Defaults to null if not provided.

llmModel

Optional language model to be used within the subgraph. Defaults to null.

llmParams

Optional parameters for configuring the language model behavior. Defaults to null.

runMode

The mode in which tools are executed. Defaults to sequential execution.

defineTask

A suspending lambda function that defines the task for the subgraph, taking the input as a parameter.


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>(source)

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.

Return

A delegate representing the subgraph that processes the input and produces a result through the finish tool.

Parameters

tools

The list of tools that are available for use within the subgraph.

name

An optional name for the subgraph. Defaults to null if not provided.

llmModel

An optional language model to be used in the subgraph. If not specified, a default model may be used.

llmParams

Optional parameters to customize the behavior of the language model in the subgraph.

runMode

The mode in which tools are executed. Defaults to sequential execution.

defineTask

A suspend function that defines the task to be executed by the subgraph based on the given input.


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>(source)

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

Return

A delegate object representing the constructed subgraph for the specified task.

Parameters

Input

The input type provided to the subgraph.

Output

The output type returned by the subgraph.

OutputTransformed

The transformed output type after finishing the task.

toolSelectionStrategy

The strategy to be used for selecting tools within the subgraph.

finishTool

The tool responsible for finalizing the task and producing the transformed output.

name

An optional name for the subgraph. Defaults to null if not provided.

llmModel

The optional language model to be used in the subgraph for processing requests.

llmParams

The optional parameters to customize the behavior of the language model.

runMode

The mode in which tools are executed. Defaults to sequential execution.

assistantResponseRepeatMax

The maximum number of assistant responses allowed before determining that the task cannot be completed.

defineTask

A lambda function to define the task logic, which accepts the input and returns a task description.


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>(source)

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

Return

A subgraph delegate that handles the input and produces the transformed output for the defined task.

Parameters

Input

The type of the input for the subgraph task.

Output

The type of the raw output produced by the finish tool.

OutputTransformed

The transformed type of the output after applying the finish tool.

tools

A list of tools to be used within the subgraph.

finishTool

The tool responsible for transforming the output of the subgraph.

name

An optional name for the subgraph. Defaults to null if not provided.

llmModel

The language model to be used within the subgraph. Defaults to null if not provided.

llmParams

Optional parameters to customize the behavior of the language model. Defaults to null if not provided.

runMode

The mode in which tools are executed. Defaults to sequential execution.

assistantResponseRepeatMax

The maximum number of assistant responses allowed before determining that the task cannot be completed.

defineTask

A suspend function that defines the task to be executed in the subgraph, based on the provided input.

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>(source)

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.

Return

An AIAgentSubgraphDelegate representing the constructed subgraph with the specified configuration.

Parameters

Input

The input type to the task defined in the subgraph.

Output

The output type produced by the task and the finish tool.

toolSelectionStrategy

The strategy to be used for selecting tools within the subgraph.

finishToolFunction

The function to finalize the task execution, providing the result as Output.

llmModel

The language model to be used within the subgraph, if specified.

llmParams

Parameters to configure the language model's behavior, if specified.

defineTask

A suspend function defining the task logic for the 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>(source)

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

Return

An instance of AIAgentSubgraphDelegate that represents the defined subgraph with input and output types.

Parameters

Input

The input type expected for the subgraph task.

Output

The output type expected from the subgraph task.

tools

A list of tools available for the subgraph task to utilize.

finishToolFunction

The function that represents the tool used to finish the task, producing the output.

llmModel

An optional LLModel to use within the subgraph for task execution. Defaults to null.

llmParams

Optional parameters for configuring the behavior of the LLModel. Defaults to null.

defineTask

A suspend lambda function that defines the task, taking an input of type Input and returning a task description as a String.