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
- __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:
- Returns:
True if hook should trigger, False otherwise
- Return type:
- 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:
- 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)
- 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)
- 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)
- 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)