tooluniverse.extended_hooks moduleΒΆ

Extended Hook Types for ToolUniverse

This module demonstrates how to extend the hook system with additional hook types beyond summarization. It shows the pattern for creating new hook types while maintaining compatibility with the existing system.

class tooluniverse.extended_hooks.OutputHook(config: Dict[str, Any])[source][source]ΒΆ

Bases: object

Base class for all output hooks.

This abstract base class defines the interface that all output hooks must implement. Hooks are used to process tool outputs after execution, enabling features like summarization, filtering, transformation, and validation.

Parameters:

config (Dict[str, Any]) – Hook configuration including name, enabled status, priority, and conditions

config[source]ΒΆ

Hook configuration

Type:

Dict[str, Any]

name[source]ΒΆ

Name of the hook

Type:

str

enabled[source]ΒΆ

Whether the hook is enabled

Type:

bool

priority[source]ΒΆ

Hook priority (lower numbers execute first)

Type:

int

rule[source]ΒΆ

Rule for when this hook should trigger

Type:

HookRule

__init__(config: Dict[str, Any])[source][source]ΒΆ

Initialize the output hook with configuration.

Parameters:

config (Dict[str, Any]) – Hook configuration containing: - name: Hook identifier - enabled: Whether hook is active - priority: Execution priority - conditions: Trigger conditions

should_trigger(result: Any, tool_name: str, arguments: Dict[str, Any], context: Dict[str, Any]) bool[source][source]ΒΆ

Determine if this hook should be triggered for the given output.

Parameters:
  • result (Any) – The tool output to evaluate

  • tool_name (str) – Name of the tool that produced the output

  • arguments (Dict[str, Any]) – Arguments passed to the tool

  • context (Dict[str, Any]) – Additional context information

Returns:

True if hook should trigger, False otherwise

Return type:

bool

process(result: Any, tool_name: str, arguments: Dict[str, Any], context: Dict[str, Any]) Any[source][source]ΒΆ

Process the tool output.

This method must be implemented by subclasses to define the specific processing logic for the hook.

Parameters:
  • result (Any) – The tool output to process

  • tool_name (str) – Name of the tool that produced the output

  • arguments (Dict[str, Any]) – Arguments passed to the tool

  • context (Dict[str, Any]) – Additional context information

Returns:

The processed output

Return type:

Any

Raises:

NotImplementedError – If not implemented by subclass

class tooluniverse.extended_hooks.FilteringHook(config: Dict[str, Any], tooluniverse=None)[source][source]ΒΆ

Bases: OutputHook

Hook for filtering sensitive or unwanted content from tool outputs.

This hook can be used to: - Remove sensitive information (emails, phones, SSNs) - Filter inappropriate content - Sanitize data before display

Parameters:
  • config (Dict[str, Any]) – Hook configuration containing filter settings

  • tooluniverse – Optional ToolUniverse instance (not used for filtering)

__init__(config: Dict[str, Any], tooluniverse=None)[source][source]ΒΆ

Initialize the filtering hook with configuration.

Parameters:
  • config (Dict[str, Any]) – Hook configuration

  • tooluniverse – ToolUniverse instance (optional, not used)

process(result: Any, tool_name: str, arguments: Dict[str, Any], context: Dict[str, Any]) Any[source][source]ΒΆ

Apply filtering to the tool output.

Parameters:
  • result (Any) – The tool output to filter

  • tool_name (str) – Name of the tool that produced the output

  • arguments (Dict[str, Any]) – Arguments passed to the tool

  • context (Dict[str, Any]) – Additional context information

Returns:

The filtered output, or original output if filtering fails

Return type:

Any

class tooluniverse.extended_hooks.FormattingHook(config: Dict[str, Any], tooluniverse=None)[source][source]ΒΆ

Bases: OutputHook

Hook for formatting and beautifying tool outputs.

This hook can be used to: - Pretty-print JSON/XML outputs - Format text with proper indentation - Standardize output formats

Parameters:
  • config (Dict[str, Any]) – Hook configuration containing formatting settings

  • tooluniverse – Optional ToolUniverse instance (not used for formatting)

__init__(config: Dict[str, Any], tooluniverse=None)[source][source]ΒΆ

Initialize the formatting hook with configuration.

Parameters:
  • config (Dict[str, Any]) – Hook configuration

  • tooluniverse – ToolUniverse instance (optional, not used)

process(result: Any, tool_name: str, arguments: Dict[str, Any], context: Dict[str, Any]) Any[source][source]ΒΆ

Apply formatting to the tool output.

Parameters:
  • result (Any) – The tool output to format

  • tool_name (str) – Name of the tool that produced the output

  • arguments (Dict[str, Any]) – Arguments passed to the tool

  • context (Dict[str, Any]) – Additional context information

Returns:

The formatted output, or original output if formatting fails

Return type:

Any

class tooluniverse.extended_hooks.ValidationHook(config: Dict[str, Any], tooluniverse=None)[source][source]ΒΆ

Bases: OutputHook

Hook for validating tool outputs against schemas or rules.

This hook can be used to: - Validate JSON against schemas - Check required fields - Ensure data quality

Parameters:
  • config (Dict[str, Any]) – Hook configuration containing validation settings

  • tooluniverse – Optional ToolUniverse instance (not used for validation)

__init__(config: Dict[str, Any], tooluniverse=None)[source][source]ΒΆ

Initialize the validation hook with configuration.

Parameters:
  • config (Dict[str, Any]) – Hook configuration

  • tooluniverse – ToolUniverse instance (optional, not used)

process(result: Any, tool_name: str, arguments: Dict[str, Any], context: Dict[str, Any]) Any[source][source]ΒΆ

Apply validation to the tool output.

Parameters:
  • result (Any) – The tool output to validate

  • tool_name (str) – Name of the tool that produced the output

  • arguments (Dict[str, Any]) – Arguments passed to the tool

  • context (Dict[str, Any]) – Additional context information

Returns:

The validated output, or original output if validation fails

Return type:

Any

class tooluniverse.extended_hooks.LoggingHook(config: Dict[str, Any], tooluniverse=None)[source][source]ΒΆ

Bases: OutputHook

Hook for logging tool outputs and execution details.

This hook can be used to: - Log all tool outputs - Track execution metrics - Audit tool usage

Parameters:
  • config (Dict[str, Any]) – Hook configuration containing logging settings

  • tooluniverse – Optional ToolUniverse instance (not used for logging)

__init__(config: Dict[str, Any], tooluniverse=None)[source][source]ΒΆ

Initialize the logging hook with configuration.

Parameters:
  • config (Dict[str, Any]) – Hook configuration

  • tooluniverse – ToolUniverse instance (optional, not used)

process(result: Any, tool_name: str, arguments: Dict[str, Any], context: Dict[str, Any]) Any[source][source]ΒΆ

Log the tool output and execution details.

Parameters:
  • result (Any) – The tool output to log

  • tool_name (str) – Name of the tool that produced the output

  • arguments (Dict[str, Any]) – Arguments passed to the tool

  • context (Dict[str, Any]) – Additional context information

Returns:

The original output (logging doesn’t modify the output)

Return type:

Any