subgraphWithTask

inline fun <Input, Output> AIAgentSubgraphBuilderBase<*, *>.subgraphWithTask(toolSelectionStrategy: ToolSelectionStrategy, llmModel: LLModel? = null, llmParams: LLMParams? = 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. 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)

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


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>(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.

finishTool

The tool responsible for producing the final result of the subgraph.

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.

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>, llmModel: LLModel? = null, llmParams: LLMParams? = 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.

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.

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>, llmModel: LLModel? = null, llmParams: LLMParams? = 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.

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.

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.