EventHandlerConfig

Configuration class for the EventHandler feature.

This class provides a way to configure handlers for various events that occur during the execution of an agent. These events include agent lifecycle events, strategy events, node events, LLM call events, and tool call events.

Each handler is a property that can be assigned a lambda function to be executed when the corresponding event occurs.

Example usage:

handleEvents {
onToolCall { stage, tool, toolArgs ->
println("Tool called: ${tool.name} with args $toolArgs")
}

onAgentFinished { strategyName, result ->
println("Agent finished with result: $result")
}
}

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
var onAfterLLMCall: suspend (prompt: Prompt, tools: List<ToolDescriptor>, model: LLModel, responses: List<Message.Response>, sessionUuid: Uuid) -> Unit

A deprecated property to handle events triggered after a response is received from the language model (LLM).

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

A deprecated variable used to define a handler that is called after a node in the agent's execution graph has been processed.

Link copied to clipboard
var onAgentFinished: suspend (strategyName: String, result: Any?) -> Unit

A deprecated handler invoked when an agent finishes execution.

Link copied to clipboard
var onAgentRunError: suspend (strategyName: String, sessionUuid: Uuid?, throwable: Throwable) -> Unit

A deprecated variable used to define a handler that is called when an error occurs during agent execution.

Link copied to clipboard
var onBeforeAgentStarted: suspend (strategy: AIAgentStrategy<*, *>, agent: AIAgent<*, *>) -> Unit

A handler invoked before an AI agent is started.

Link copied to clipboard
var onBeforeLLMCall: suspend (prompt: Prompt, tools: List<ToolDescriptor>, model: LLModel, sessionUuid: Uuid) -> Unit

Deprecated variable used to define a handler that is invoked before a call is made to the language model.

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

A handler invoked before a node in the agent's execution graph is processed.

Link copied to clipboard
var onStrategyFinished: suspend (strategy: AIAgentStrategy<*, *>, result: Any?) -> Unit

A deprecated variable that defines a handler to be invoked when a strategy finishes execution. Replaced by the onStrategyFinished(handler) method to provide a more structured and extensible approach.

Link copied to clipboard
var onStrategyStarted: suspend (strategy: AIAgentStrategy<*, *>) -> Unit

A suspendable handler invoked when a strategy starts execution in the AI Agent workflow.

Link copied to clipboard
var onToolCall: suspend (tool: Tool<*, *>, toolArgs: ToolArgs) -> Unit

A deprecated variable for appending a handler called when a tool is about to be invoked.

Link copied to clipboard
var onToolCallFailure: suspend (tool: Tool<*, *>, toolArgs: ToolArgs, throwable: Throwable) -> Unit

Defines a handler invoked when a tool call fails due to an exception.

Link copied to clipboard
var onToolCallResult: suspend (tool: Tool<*, *>, toolArgs: ToolArgs, result: ToolResult?) -> Unit

Deprecated variable representing a handler invoked when a tool call is completed successfully. The handler is a suspend function with parameters for the tool, its arguments, and the result of the tool call.

Link copied to clipboard
var onToolValidationError: suspend (tool: Tool<*, *>, toolArgs: ToolArgs, value: String) -> Unit

A deprecated variable representing the handler invoked when a validation error occurs during a tool call. Use onToolValidationError(handler) instead to register error handling logic.

Functions

Link copied to clipboard
Link copied to clipboard
fun onAfterLLMCall(handler: suspend (eventContext: AfterLLMCallContext) -> Unit)

Append handler called after a response is received from the language model.

Link copied to clipboard
fun onAfterNode(handler: suspend (eventContext: NodeAfterExecuteContext) -> Unit)

Append handler called after a node in the agent's execution graph has been processed.

Link copied to clipboard
fun onAgentBeforeClose(handler: suspend (eventContext: AgentBeforeCloseContext) -> Unit)

Appends a handler called before an agent is closed. This allows for additional behavior to be executed prior to the agent being closed.

Link copied to clipboard
fun onAgentFinished(handler: suspend (eventContext: AgentFinishedContext) -> Unit)

Append handler called when an agent finishes execution.

Link copied to clipboard
fun onAgentRunError(handler: suspend (eventContext: AgentRunErrorContext) -> Unit)

Append handler called when an error occurs during agent execution.

Link copied to clipboard
fun onBeforeAgentStarted(handler: suspend (eventContext: AgentStartContext<*>) -> Unit)

Append handler called when an agent is started.

Link copied to clipboard
fun onBeforeLLMCall(handler: suspend (eventContext: BeforeLLMCallContext) -> Unit)

Append handler called before a call is made to the language model.

Link copied to clipboard
fun onBeforeNode(handler: suspend (eventContext: NodeBeforeExecuteContext) -> Unit)

Append handler called before a node in the agent's execution graph is processed.

Link copied to clipboard
fun onStrategyFinished(handler: suspend (eventContext: StrategyFinishContext<EventHandler>) -> Unit)

Append handler called when a strategy finishes execution.

Link copied to clipboard
fun onStrategyStarted(handler: suspend (eventContext: StrategyStartContext<EventHandler>) -> Unit)

Append handler called when a strategy starts execution.

Link copied to clipboard
fun onToolCall(handler: suspend (eventContext: ToolCallContext) -> Unit)

Append handler called when a tool is about to be called.

Link copied to clipboard
fun onToolCallFailure(handler: suspend (eventContext: ToolCallFailureContext) -> Unit)

Append handler called when a tool call fails with an exception.

Link copied to clipboard
fun onToolCallResult(handler: suspend (eventContext: ToolCallResultContext) -> Unit)

Append handler called when a tool call completes successfully.

Link copied to clipboard
fun onToolValidationError(handler: suspend (eventContext: ToolValidationErrorContext) -> Unit)

Append handler called when a validation error occurs during a tool call.