Skip to content

namespace_callable

Class info

Classes

Name Children Inherits
NamespaceCallable
llmling_agent.resource_providers.codemode.namespace_callable
Wrapper for tool functions with proper repr and call interface.

    🛈 DocStrings

    Namespace callable wrapper for tools.

    NamespaceCallable dataclass

    Wrapper for tool functions with proper repr and call interface.

    Source code in src/llmling_agent/resource_providers/codemode/namespace_callable.py
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    @dataclass
    class NamespaceCallable:
        """Wrapper for tool functions with proper repr and call interface."""
    
        callable: Callable
        """The callable function to execute."""
    
        name_override: str | None = None
        """Override name for the callable, defaults to callable.__name__."""
    
        def __post_init__(self) -> None:
            """Set function attributes for introspection."""
            self.__name__ = self.name_override or self.callable.__name__
            self.__doc__ = self.callable.__doc__ or ""
    
        @property
        def name(self) -> str:
            """Get the effective name of the callable."""
            return self.name_override or self.callable.__name__
    
        @classmethod
        def from_tool(cls, tool: Tool) -> NamespaceCallable:
            """Create a NamespaceCallable from a Tool.
    
            Args:
                tool: The tool to wrap
    
            Returns:
                NamespaceCallable instance
            """
            name_override = tool.name if tool.name != tool.callable.__name__ else None
            return cls(tool.callable, name_override)
    
        @classmethod
        def from_generator(cls, generator: ToolCodeGenerator) -> NamespaceCallable:
            """Create a NamespaceCallable from a ToolCodeGenerator.
    
            Args:
                generator: The generator to wrap
    
            Returns:
                NamespaceCallable instance
            """
            return cls(generator.callable, generator.name_override)
    
        async def __call__(self, *args, **kwargs) -> Any:
            """Execute the wrapped callable."""
            try:
                result = await execute(self.callable, *args, **kwargs)
            except Exception as e:  # noqa: BLE001
                return f"Error executing {self.name}: {e!s}"
            else:
                return result if result is not None else "Operation completed successfully"
    
        def __repr__(self) -> str:
            """Return detailed representation for debugging."""
            return f"NamespaceCallable(name='{self.name}')"
    
        def __str__(self) -> str:
            """Return readable string representation."""
            return f"<tool: {self.name}>"
    
        @property
        def signature(self) -> str:
            """Get function signature for debugging."""
            try:
                sig = inspect.signature(self.callable)
            except (ValueError, TypeError):
                return f"{self.name}(...)"
            else:
                return f"{self.name}{sig}"
    

    callable instance-attribute

    callable: Callable
    

    The callable function to execute.

    name property

    name: str
    

    Get the effective name of the callable.

    name_override class-attribute instance-attribute

    name_override: str | None = None
    

    Override name for the callable, defaults to callable.name.

    signature property

    signature: str
    

    Get function signature for debugging.

    __call__ async

    __call__(*args, **kwargs) -> Any
    

    Execute the wrapped callable.

    Source code in src/llmling_agent/resource_providers/codemode/namespace_callable.py
    66
    67
    68
    69
    70
    71
    72
    73
    async def __call__(self, *args, **kwargs) -> Any:
        """Execute the wrapped callable."""
        try:
            result = await execute(self.callable, *args, **kwargs)
        except Exception as e:  # noqa: BLE001
            return f"Error executing {self.name}: {e!s}"
        else:
            return result if result is not None else "Operation completed successfully"
    

    __post_init__

    __post_init__() -> None
    

    Set function attributes for introspection.

    Source code in src/llmling_agent/resource_providers/codemode/namespace_callable.py
    31
    32
    33
    34
    def __post_init__(self) -> None:
        """Set function attributes for introspection."""
        self.__name__ = self.name_override or self.callable.__name__
        self.__doc__ = self.callable.__doc__ or ""
    

    __repr__

    __repr__() -> str
    

    Return detailed representation for debugging.

    Source code in src/llmling_agent/resource_providers/codemode/namespace_callable.py
    75
    76
    77
    def __repr__(self) -> str:
        """Return detailed representation for debugging."""
        return f"NamespaceCallable(name='{self.name}')"
    

    __str__

    __str__() -> str
    

    Return readable string representation.

    Source code in src/llmling_agent/resource_providers/codemode/namespace_callable.py
    79
    80
    81
    def __str__(self) -> str:
        """Return readable string representation."""
        return f"<tool: {self.name}>"
    

    from_generator classmethod

    from_generator(generator: ToolCodeGenerator) -> NamespaceCallable
    

    Create a NamespaceCallable from a ToolCodeGenerator.

    Parameters:

    Name Type Description Default
    generator ToolCodeGenerator

    The generator to wrap

    required

    Returns:

    Type Description
    NamespaceCallable

    NamespaceCallable instance

    Source code in src/llmling_agent/resource_providers/codemode/namespace_callable.py
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    @classmethod
    def from_generator(cls, generator: ToolCodeGenerator) -> NamespaceCallable:
        """Create a NamespaceCallable from a ToolCodeGenerator.
    
        Args:
            generator: The generator to wrap
    
        Returns:
            NamespaceCallable instance
        """
        return cls(generator.callable, generator.name_override)
    

    from_tool classmethod

    from_tool(tool: Tool) -> NamespaceCallable
    

    Create a NamespaceCallable from a Tool.

    Parameters:

    Name Type Description Default
    tool Tool

    The tool to wrap

    required

    Returns:

    Type Description
    NamespaceCallable

    NamespaceCallable instance

    Source code in src/llmling_agent/resource_providers/codemode/namespace_callable.py
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    @classmethod
    def from_tool(cls, tool: Tool) -> NamespaceCallable:
        """Create a NamespaceCallable from a Tool.
    
        Args:
            tool: The tool to wrap
    
        Returns:
            NamespaceCallable instance
        """
        name_override = tool.name if tool.name != tool.callable.__name__ else None
        return cls(tool.callable, name_override)