toolregistry.class_tool_integration module

Integration for registering class-based tools as tools.

This module provides functionality to scan a Python class and register its methods as tools. If the class only contains static methods, they are registered directly. If there are instance methods or other non-static attributes, the class will be instantiated and its callable public methods will be registered.

Example

>>> from toolregistry import ToolRegistry
>>> registry = ToolRegistry()
>>> registry.register_class_tool(MyClass)
>>> registry.get_available_tools()
['MyClass.method1', 'MyClass.method2', ...]
class toolregistry.class_tool_integration.ClassToolIntegration(registry: ToolRegistry)[source]

Bases: object

__init__(registry: ToolRegistry) None[source]

Initialize with a ToolRegistry instance.

Parameters:

registry (ToolRegistry) – The tool registry to register methods with.

register_class_methods(cls_or_instance: Type | object, with_namespace: bool | str = False) None[source]

Register all methods from a class or instance as tools.

If a class is provided:
  • If all public methods are static, they are registered directly.

  • Otherwise, the class is instantiated and its public callable methods are registered.

If an instance is provided:
  • Its public callable methods are registered directly.

Parameters:
  • cls_or_instance (Union[Type, object]) – The class or instance to scan for methods.

  • with_namespace (Union[bool, str]) – Whether to prefix tool names with a namespace. - If False, no namespace is used. - If True, the namespace is derived from the class name. - If a string is provided, it is used as the namespace. Defaults to False.

async register_class_methods_async(cls_or_instance: Type | object, with_namespace: bool | str = False) None[source]

Async implementation to register tools from a class.

Currently, this is implemented synchronously.

Parameters:
  • cls_or_instance (Union[Type, object]) – The class or instance to scan for methods.

  • with_namespace (Union[bool, str]) – Whether to prefix tool names with a namespace. - If False, no namespace is used. - If True, the namespace is derived from the class name. - If a string is provided, it is used as the namespace. Defaults to False.