AIAgentSubgraphBuilder

class AIAgentSubgraphBuilder<Input, Output>(val name: String? = null, inputType: KType, outputType: KType, toolSelectionStrategy: ToolSelectionStrategy, llmModel: LLModel?, llmParams: LLMParams?) : AIAgentSubgraphBuilderBase<Input, Output> , BaseBuilder<AIAgentSubgraphDelegate<Input, Output>> (source)

Builder class for creating AI agent subgraphs with a defined tool selection strategy.

This class facilitates the construction of customized subgraphs in an AI agent's execution pipeline. It provides methods for defining start and finish nodes and ensuring the connectivity between them. The subgraph can be configured with a tool selection strategy to control the tools available during its execution.

Parameters

Input

The input type expected by the starting node of the subgraph.

Output

The output type produced by the finishing node of the subgraph.

Constructors

Link copied to clipboard
constructor(name: String? = null, inputType: KType, outputType: KType, toolSelectionStrategy: ToolSelectionStrategy, llmModel: LLModel?, llmParams: LLMParams?)

Properties

Link copied to clipboard
val name: String? = null

Optional name of the subgraph for identification.

Link copied to clipboard
open override val nodeFinish: FinishNode<Output>

Represents the "finish" node in the AI agent's subgraph structure. This node indicates the endpoint of the subgraph and acts as a terminal stage where the workflow stops.

Link copied to clipboard
open override val nodeStart: StartNode<Input>

Represents the starting node of the subgraph in the AI agent's strategy graph.

Functions

Link copied to clipboard
open override fun build(): AIAgentSubgraphDelegate<Input, Output>

Builds and returns the instance of type T that has been configured using the builder.

Link copied to clipboard
Link copied to clipboard
inline fun <Input, Output> node(name: String? = null, noinline execute: suspend AIAgentContextBase.(input: Input) -> Output): AIAgentNodeDelegate<Input, Output>

Defines a new node in the agent's stage, representing a unit of execution that takes an input and produces an output.

Link copied to clipboard

A pass-through node that does nothing and returns input as output

Link copied to clipboard

A node that executes multiple tool calls. These calls can optionally be executed in parallel.

Link copied to clipboard

Creates a node in the AI agent subgraph that processes a collection of tool calls, executes them, and sends back the results to the downstream process. The tools can be executed either in parallel or sequentially based on the provided configuration.

Link copied to clipboard

A node that calls a specific tool directly using the provided arguments.

Link copied to clipboard

A node that executes a tool call and returns its result.

Link copied to clipboard
inline fun <T> AIAgentSubgraphBuilderBase<*, *>.nodeLLMCompressHistory(name: String? = null, strategy: HistoryCompressionStrategy = HistoryCompressionStrategy.WholeHistory, retrievalModel: LLModel? = null, preserveMemory: Boolean = true): AIAgentNodeDelegate<T, T>

A node that compresses the current LLM prompt (message history) into a summary, replacing messages with a TLDR.

Link copied to clipboard
fun AIAgentSubgraphBuilderBase<*, *>.nodeLLMModerateMessage(name: String? = null, moderatingModel: LLModel? = null, includeCurrentPrompt: Boolean = false): AIAgentNodeDelegate<Message, ModeratedMessage>

A node that moderates only a single input message using a specified language model.

Link copied to clipboard

A node that appends a user message to the LLM prompt and gets a response with optional tool usage.

Link copied to clipboard

A node that appends a user message to the LLM prompt and gets multiple LLM responses with tool calls enabled.

Link copied to clipboard

A node that appends a user message to the LLM prompt and streams LLM response without transformation.

fun <T> AIAgentSubgraphBuilderBase<*, *>.nodeLLMRequestStreaming(name: String? = null, structureDefinition: StructuredDataDefinition? = null, transformStreamData: suspend (Flow<String>) -> Flow<T>): AIAgentNodeDelegate<String, Flow<T>>

A node that appends a user message to the LLM prompt, streams LLM response and transforms the stream data.

Link copied to clipboard
inline fun <T> AIAgentSubgraphBuilderBase<*, *>.nodeLLMRequestStructured(name: String? = null, structure: StructuredData<T>, retries: Int, fixingModel: LLModel): AIAgentNodeDelegate<String, Result<StructuredResponse<T>>>

A node that appends a user message to the LLM prompt and requests structured data from the LLM with error correction capabilities.

Link copied to clipboard

A node that that appends a user message to the LLM prompt and forces the LLM to use a specific tool.

A node that appends a user message to the LLM prompt and forces the LLM to use a specific tool.

Link copied to clipboard

A node that appends a user message to the LLM prompt and gets a response where the LLM can only call tools.

Link copied to clipboard

A node that adds multiple tool results to the prompt and gets multiple LLM responses.

Link copied to clipboard

A node that sends multiple tool execution results to the LLM and gets multiple LLM choices.

Link copied to clipboard

A node that adds a tool result to the prompt and requests an LLM response.

Link copied to clipboard

A node that chooses an LLM choice based on the given strategy.

Link copied to clipboard
inline fun <T> AIAgentSubgraphBuilderBase<*, *>.nodeUpdatePrompt(name: String? = null, noinline body: PromptBuilder.() -> Unit): AIAgentNodeDelegate<T, T>

A node that adds messages to the LLM prompt using the provided prompt builder. The input is passed as it is to the output.

Link copied to clipboard

Creates a node that executes multiple nodes in parallel.

Link copied to clipboard
inline fun <Input, Output> subgraph(name: String? = null, toolSelectionStrategy: ToolSelectionStrategy = ToolSelectionStrategy.ALL, llmModel: LLModel? = null, llmParams: LLMParams? = null, define: AIAgentSubgraphBuilderBase<Input, Output>.() -> Unit): AIAgentSubgraphDelegate<Input, Output>

Creates a subgraph with a specified tool selection strategy.

inline fun <Input, Output> subgraph(name: String? = null, tools: List<Tool<*, *>>, llmModel: LLModel? = null, llmParams: LLMParams? = null, define: AIAgentSubgraphBuilderBase<Input, Output>.() -> Unit): AIAgentSubgraphDelegate<Input, Output>

Creates a subgraph with specified tools.

Link copied to clipboard