AIAgentPipeline

Pipeline for AI agent features that provides interception points for various agent lifecycle events.

The pipeline allows features to:

  • Be installed into stage contexts

  • Intercept agent creation

  • Intercept node execution before and after it happens

  • Intercept LLM (Language Learning Model) calls before and after they happen

  • Intercept tool calls before and after they happen

This pipeline serves as the central mechanism for extending and customizing agent behavior through a flexible interception system. Features can be installed with custom configurations and can hook into different stages of the agent's execution lifecycle.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard

Retrieves all features associated with the given stage context.

Link copied to clipboard
fun <Config : FeatureConfig, Feature : Any> install(feature: AIAgentFeature<Config, Feature>, configure: Config.() -> Unit)

Installs a feature into the pipeline with the provided configuration.

Link copied to clipboard
fun <TFeature : Any> interceptAfterLLMCall(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(response: String) -> Unit)

Intercepts LLM calls after they are made to process or log the response.

Link copied to clipboard
fun <TFeature : Any> interceptAfterLLMCallWithTools(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(responses: List<Message.Response>, tools: List<ToolDescriptor>) -> Unit)

Intercepts LLM calls with tools after they are made to process or log the structured response.

Link copied to clipboard
fun <TFeature : Any> interceptAfterNode(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(node: AIAgentNodeBase<*, *>, context: AIAgentContextBase, input: Any?, output: Any?) -> Unit)

Intercepts node execution after it completes.

Link copied to clipboard
fun <TFeature : Any> interceptAgentFinished(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(strategyName: String, result: String?) -> Unit)

Intercepts the completion of an agent's operation and assigns a custom handler to process the result.

Link copied to clipboard
fun <TFeature : Any> interceptAgentRunError(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(strategyName: String, throwable: Throwable) -> Unit)

Intercepts and handles errors occurring during the execution of an AI agent's strategy.

Link copied to clipboard
fun <TFeature : Any> interceptBeforeAgentStarted(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend AgentStartContext<TFeature>.() -> Unit)

Intercepts on before an agent started to modify or enhance the agent.

Link copied to clipboard
fun <TFeature : Any> interceptBeforeLLMCall(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(prompt: Prompt) -> Unit)

Intercepts LLM calls before they are made to modify or log the prompt.

Link copied to clipboard
fun <TFeature : Any> interceptBeforeLLMCallWithTools(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(prompt: Prompt, tools: List<ToolDescriptor>) -> Unit)

Intercepts LLM calls with tools before they are made to modify or log the prompt and tools.

Link copied to clipboard
fun <TFeature : Any> interceptBeforeNode(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(node: AIAgentNodeBase<*, *>, context: AIAgentContextBase, input: Any?) -> Unit)

Intercepts node execution before it starts.

Link copied to clipboard

Set feature handler for Context Stage events

Link copied to clipboard

Intercepts environment creation to allow features to modify or enhance the agent environment.

Link copied to clipboard
fun <TFeature : Any> interceptStrategyFinished(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(strategyName: String, result: String) -> Unit)

Sets up an interceptor to handle the completion of a strategy for the given feature.

Link copied to clipboard
fun <TFeature : Any> interceptStrategyStarted(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend StrategyUpdateContext<TFeature>.() -> Unit)

Intercepts strategy started event to perform actions when an agent strategy begins execution.

Link copied to clipboard
fun <TFeature : Any> interceptToolCall(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(tool: Tool<*, *>, toolArgs: Tool.Args) -> Unit)

Intercepts and handles tool calls for the specified feature and its implementation. Updates the tool call handler for the given feature key with a custom handler.

Link copied to clipboard
fun <TFeature : Any> interceptToolCallFailure(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(tool: Tool<*, *>, toolArgs: Tool.Args, throwable: Throwable) -> Unit)

Sets up an interception mechanism to handle tool call failures for a specific feature.

Link copied to clipboard
fun <TFeature : Any> interceptToolCallResult(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(tool: Tool<*, *>, toolArgs: Tool.Args, result: ToolResult?) -> Unit)

Intercepts the result of a tool call with a custom handler for a specific feature.

Link copied to clipboard
fun <TFeature : Any> interceptToolValidationError(feature: AIAgentFeature<*, TFeature>, featureImpl: TFeature, handle: suspend TFeature.(tool: Tool<*, *>, toolArgs: Tool.Args, value: String) -> Unit)

Intercepts validation errors encountered during the execution of tools associated with the specified feature.

Link copied to clipboard
suspend fun onAfterLLMCall(response: String)

Notifies all registered LLM handlers after a language model call has completed.

Link copied to clipboard

Notifies all registered LLM handlers after a language model call with tools has completed.

Link copied to clipboard
suspend fun onAfterNode(node: AIAgentNodeBase<*, *>, context: AIAgentContextBase, input: Any?, output: Any?)

Notifies all registered node handlers after a node has been executed.

Link copied to clipboard
suspend fun onAgentFinished(strategyName: String, result: String?)

Notifies all registered handlers that an agent has finished execution.

Link copied to clipboard
suspend fun onAgentRunError(strategyName: String, throwable: Throwable)

Notifies all registered handlers about an error that occurred during agent execution.

Link copied to clipboard
suspend fun onBeforeAgentStarted(strategy: AIAgentStrategy, agent: AIAgent)

Notifies all registered handlers that an agent has started execution.

Link copied to clipboard
suspend fun onBeforeLLMCall(prompt: Prompt)

Notifies all registered LLM handlers before a language model call is made.

Link copied to clipboard
suspend fun onBeforeLLMWithToolsCall(prompt: Prompt, tools: List<ToolDescriptor>)

Notifies all registered LLM handlers before a language model call with tools is made.

Link copied to clipboard
suspend fun onBeforeNode(node: AIAgentNodeBase<*, *>, context: AIAgentContextBase, input: Any?)

Notifies all registered node handlers before a node is executed.

Link copied to clipboard
suspend fun onStrategyFinished(strategyName: String, result: String)

Notifies all registered strategy handlers that a strategy has finished execution.

Link copied to clipboard
suspend fun onStrategyStarted(strategy: AIAgentStrategy)

Notifies all registered strategy handlers that a strategy has started execution.

Link copied to clipboard
suspend fun onToolCall(tool: Tool<*, *>, toolArgs: Tool.Args)

Notifies all registered tool handlers when a tool is called.

Link copied to clipboard
suspend fun onToolCallFailure(tool: Tool<*, *>, toolArgs: Tool.Args, throwable: Throwable)

Notifies all registered tool handlers when a tool call fails with an exception.

Link copied to clipboard
suspend fun onToolCallResult(tool: Tool<*, *>, toolArgs: Tool.Args, result: ToolResult?)

Notifies all registered tool handlers about the result of a tool call.

Link copied to clipboard
suspend fun onToolValidationError(tool: Tool<*, *>, toolArgs: Tool.Args, error: String)

Notifies all registered tool handlers when a validation error occurs during a tool call.

Link copied to clipboard

Transforms the agent environment by applying all registered environment transformers.