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.FilteringHook[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, tooluniverse=None)[source]ΒΆ

Initialize the filtering hook with configuration.

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

  • tooluniverse – ToolUniverse instance (optional, not used)

process(result, tool_name, arguments, context)[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[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, tooluniverse=None)[source]ΒΆ

Initialize the formatting hook with configuration.

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

  • tooluniverse – ToolUniverse instance (optional, not used)

process(result, tool_name, arguments, context)[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[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, tooluniverse=None)[source]ΒΆ

Initialize the validation hook with configuration.

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

  • tooluniverse – ToolUniverse instance (optional, not used)

process(result, tool_name, arguments, context)[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[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, tooluniverse=None)[source]ΒΆ

Initialize the logging hook with configuration.

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

  • tooluniverse – ToolUniverse instance (optional, not used)

process(result, tool_name, arguments, context)[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