Skip to content

static

Class info

Classes

Name Children Inherits
ResourceProvider
llmling_agent.resource_providers.base
Base class for resource providers.
StaticResourceProvider
llmling_agent.resource_providers.static
Provider for pre-configured tools, prompts and resources.

    🛈 DocStrings

    Static resource provider implementation.

    StaticResourceProvider

    Bases: ResourceProvider

    Provider for pre-configured tools, prompts and resources.

    Allows creating a provider that serves a fixed set of resources passed during initialization. Useful for converting static configurations to the common ResourceProvider interface.

    Source code in src/llmling_agent/resource_providers/static.py
     19
     20
     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
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    class StaticResourceProvider(ResourceProvider):
        """Provider for pre-configured tools, prompts and resources.
    
        Allows creating a provider that serves a fixed set of resources
        passed during initialization. Useful for converting static configurations
        to the common ResourceProvider interface.
        """
    
        def __init__(
            self,
            name: str = "static",
            tools: Sequence[Tool] | None = None,
            prompts: Sequence[BasePrompt] | None = None,
            resources: Sequence[ResourceInfo] | None = None,
        ):
            """Initialize provider with static resources.
    
            Args:
                name: Name of the provider
                tools: Optional list of tools to serve
                prompts: Optional list of prompts to serve
                resources: Optional list of resources to serve
            """
            super().__init__(name=name)
            self._tools = list(tools) if tools else []
            self._prompts = list(prompts) if prompts else []
            self._resources = list(resources) if resources else []
    
        async def get_tools(self) -> list[Tool]:
            """Get pre-configured tools."""
            return self._tools
    
        async def get_prompts(self) -> list[BasePrompt]:
            """Get pre-configured prompts."""
            return self._prompts
    
        async def get_resources(self) -> list[ResourceInfo]:
            """Get pre-configured resources."""
            return self._resources
    
        def add_tool(self, tool: Tool) -> None:
            """Add a tool to this provider.
    
            Args:
                tool: Tool to add
            """
            self._tools.append(tool)
    
        def remove_tool(self, name: str) -> bool:
            """Remove a tool by name.
    
            Args:
                name: Name of tool to remove
    
            Returns:
                True if tool was found and removed, False otherwise
            """
            for i, tool in enumerate(self._tools):
                if tool.name == name:
                    self._tools.pop(i)
                    return True
            return False
    
        def add_prompt(self, prompt: BasePrompt) -> None:
            """Add a prompt to this provider.
    
            Args:
                prompt: Prompt to add
            """
            self._prompts.append(prompt)
    
        def remove_prompt(self, name: str) -> bool:
            """Remove a prompt by name.
    
            Args:
                name: Name of prompt to remove
    
            Returns:
                True if prompt was found and removed, False otherwise
            """
            for i, prompt in enumerate(self._prompts):
                if prompt.name == name:
                    self._prompts.pop(i)
                    return True
            return False
    
        def add_resource(self, resource: ResourceInfo) -> None:
            """Add a resource to this provider.
    
            Args:
                resource: Resource to add
            """
            self._resources.append(resource)
    
        def remove_resource(self, name: str) -> bool:
            """Remove a resource by name.
    
            Args:
                name: Name of resource to remove
    
            Returns:
                True if resource was found and removed, False otherwise
            """
            for i, resource in enumerate(self._resources):
                if resource.name == name:
                    self._resources.pop(i)
                    return True
            return False
    
        @overload
        def tool(self, func: Callable[..., Any]) -> Callable[..., Any]: ...
    
        @overload
        def tool(
            self,
            *,
            name: str | None = None,
            description: str | None = None,
            enabled: bool = True,
            requires_confirmation: bool = False,
            requires_capability: str | None = None,
            priority: int = 100,
            cache_enabled: bool = False,
            metadata: dict[str, str] | None = None,
            **kwargs: Any,
        ) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ...
    
        def tool(
            self,
            func: Callable[..., Any] | None = None,
            *,
            name: str | None = None,
            description: str | None = None,
            enabled: bool = True,
            requires_confirmation: bool = False,
            requires_capability: str | None = None,
            priority: int = 100,
            cache_enabled: bool = False,
            metadata: dict[str, str] | None = None,
            **kwargs: Any,
        ) -> Callable[..., Any] | Callable[[Callable[..., Any]], Callable[..., Any]]:
            """Decorator to register a function as a tool.
    
            Can be used with or without parameters:
    
            ```python
            # Without parameters
            @provider.tool
            def my_function(x: int) -> str:
                return str(x)
    
            # With parameters
            @provider.tool(name="custom_name", description="Custom description")
            def another_function(y: str) -> str:
                return y.upper()
            ```
    
            Args:
                func: Function to register (when used without parentheses)
                name: Override for tool name
                description: Override for tool description
                enabled: Whether tool is initially enabled
                requires_confirmation: Whether execution needs confirmation
                requires_capability: Optional capability requirement
                priority: Execution priority (lower = higher priority)
                cache_enabled: Whether to enable result caching
                metadata: Additional tool metadata
                **kwargs: Additional arguments passed to Tool.from_callable
            """
            from llmling_agent.tools.base import Tool
    
            def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
                tool = Tool.from_callable(
                    f,
                    name_override=name,
                    description_override=description,
                    enabled=enabled,
                    requires_confirmation=requires_confirmation,
                    requires_capability=requires_capability,
                    priority=priority,
                    cache_enabled=cache_enabled,
                    metadata=metadata or {},
                    **kwargs,
                )
                self.add_tool(tool)
                return f
    
            if func is None:
                # Called with arguments: @provider.tool(...)
                return decorator
            # Called without arguments: @provider.tool
            return decorator(func)
    

    __init__

    __init__(
        name: str = "static",
        tools: Sequence[Tool] | None = None,
        prompts: Sequence[BasePrompt] | None = None,
        resources: Sequence[ResourceInfo] | None = None,
    )
    

    Initialize provider with static resources.

    Parameters:

    Name Type Description Default
    name str

    Name of the provider

    'static'
    tools Sequence[Tool] | None

    Optional list of tools to serve

    None
    prompts Sequence[BasePrompt] | None

    Optional list of prompts to serve

    None
    resources Sequence[ResourceInfo] | None

    Optional list of resources to serve

    None
    Source code in src/llmling_agent/resource_providers/static.py
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    def __init__(
        self,
        name: str = "static",
        tools: Sequence[Tool] | None = None,
        prompts: Sequence[BasePrompt] | None = None,
        resources: Sequence[ResourceInfo] | None = None,
    ):
        """Initialize provider with static resources.
    
        Args:
            name: Name of the provider
            tools: Optional list of tools to serve
            prompts: Optional list of prompts to serve
            resources: Optional list of resources to serve
        """
        super().__init__(name=name)
        self._tools = list(tools) if tools else []
        self._prompts = list(prompts) if prompts else []
        self._resources = list(resources) if resources else []
    

    add_prompt

    add_prompt(prompt: BasePrompt) -> None
    

    Add a prompt to this provider.

    Parameters:

    Name Type Description Default
    prompt BasePrompt

    Prompt to add

    required
    Source code in src/llmling_agent/resource_providers/static.py
    82
    83
    84
    85
    86
    87
    88
    def add_prompt(self, prompt: BasePrompt) -> None:
        """Add a prompt to this provider.
    
        Args:
            prompt: Prompt to add
        """
        self._prompts.append(prompt)
    

    add_resource

    add_resource(resource: ResourceInfo) -> None
    

    Add a resource to this provider.

    Parameters:

    Name Type Description Default
    resource ResourceInfo

    Resource to add

    required
    Source code in src/llmling_agent/resource_providers/static.py
    105
    106
    107
    108
    109
    110
    111
    def add_resource(self, resource: ResourceInfo) -> None:
        """Add a resource to this provider.
    
        Args:
            resource: Resource to add
        """
        self._resources.append(resource)
    

    add_tool

    add_tool(tool: Tool) -> None
    

    Add a tool to this provider.

    Parameters:

    Name Type Description Default
    tool Tool

    Tool to add

    required
    Source code in src/llmling_agent/resource_providers/static.py
    59
    60
    61
    62
    63
    64
    65
    def add_tool(self, tool: Tool) -> None:
        """Add a tool to this provider.
    
        Args:
            tool: Tool to add
        """
        self._tools.append(tool)
    

    get_prompts async

    get_prompts() -> list[BasePrompt]
    

    Get pre-configured prompts.

    Source code in src/llmling_agent/resource_providers/static.py
    51
    52
    53
    async def get_prompts(self) -> list[BasePrompt]:
        """Get pre-configured prompts."""
        return self._prompts
    

    get_resources async

    get_resources() -> list[ResourceInfo]
    

    Get pre-configured resources.

    Source code in src/llmling_agent/resource_providers/static.py
    55
    56
    57
    async def get_resources(self) -> list[ResourceInfo]:
        """Get pre-configured resources."""
        return self._resources
    

    get_tools async

    get_tools() -> list[Tool]
    

    Get pre-configured tools.

    Source code in src/llmling_agent/resource_providers/static.py
    47
    48
    49
    async def get_tools(self) -> list[Tool]:
        """Get pre-configured tools."""
        return self._tools
    

    remove_prompt

    remove_prompt(name: str) -> bool
    

    Remove a prompt by name.

    Parameters:

    Name Type Description Default
    name str

    Name of prompt to remove

    required

    Returns:

    Type Description
    bool

    True if prompt was found and removed, False otherwise

    Source code in src/llmling_agent/resource_providers/static.py
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    def remove_prompt(self, name: str) -> bool:
        """Remove a prompt by name.
    
        Args:
            name: Name of prompt to remove
    
        Returns:
            True if prompt was found and removed, False otherwise
        """
        for i, prompt in enumerate(self._prompts):
            if prompt.name == name:
                self._prompts.pop(i)
                return True
        return False
    

    remove_resource

    remove_resource(name: str) -> bool
    

    Remove a resource by name.

    Parameters:

    Name Type Description Default
    name str

    Name of resource to remove

    required

    Returns:

    Type Description
    bool

    True if resource was found and removed, False otherwise

    Source code in src/llmling_agent/resource_providers/static.py
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    def remove_resource(self, name: str) -> bool:
        """Remove a resource by name.
    
        Args:
            name: Name of resource to remove
    
        Returns:
            True if resource was found and removed, False otherwise
        """
        for i, resource in enumerate(self._resources):
            if resource.name == name:
                self._resources.pop(i)
                return True
        return False
    

    remove_tool

    remove_tool(name: str) -> bool
    

    Remove a tool by name.

    Parameters:

    Name Type Description Default
    name str

    Name of tool to remove

    required

    Returns:

    Type Description
    bool

    True if tool was found and removed, False otherwise

    Source code in src/llmling_agent/resource_providers/static.py
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    def remove_tool(self, name: str) -> bool:
        """Remove a tool by name.
    
        Args:
            name: Name of tool to remove
    
        Returns:
            True if tool was found and removed, False otherwise
        """
        for i, tool in enumerate(self._tools):
            if tool.name == name:
                self._tools.pop(i)
                return True
        return False
    

    tool

    tool(func: Callable[..., Any]) -> Callable[..., Any]
    
    tool(
        *,
        name: str | None = None,
        description: str | None = None,
        enabled: bool = True,
        requires_confirmation: bool = False,
        requires_capability: str | None = None,
        priority: int = 100,
        cache_enabled: bool = False,
        metadata: dict[str, str] | None = None,
        **kwargs: Any,
    ) -> Callable[[Callable[..., Any]], Callable[..., Any]]
    
    tool(
        func: Callable[..., Any] | None = None,
        *,
        name: str | None = None,
        description: str | None = None,
        enabled: bool = True,
        requires_confirmation: bool = False,
        requires_capability: str | None = None,
        priority: int = 100,
        cache_enabled: bool = False,
        metadata: dict[str, str] | None = None,
        **kwargs: Any,
    ) -> Callable[..., Any] | Callable[[Callable[..., Any]], Callable[..., Any]]
    

    Decorator to register a function as a tool.

    Can be used with or without parameters:

    # Without parameters
    @provider.tool
    def my_function(x: int) -> str:
        return str(x)
    
    # With parameters
    @provider.tool(name="custom_name", description="Custom description")
    def another_function(y: str) -> str:
        return y.upper()
    

    Parameters:

    Name Type Description Default
    func Callable[..., Any] | None

    Function to register (when used without parentheses)

    None
    name str | None

    Override for tool name

    None
    description str | None

    Override for tool description

    None
    enabled bool

    Whether tool is initially enabled

    True
    requires_confirmation bool

    Whether execution needs confirmation

    False
    requires_capability str | None

    Optional capability requirement

    None
    priority int

    Execution priority (lower = higher priority)

    100
    cache_enabled bool

    Whether to enable result caching

    False
    metadata dict[str, str] | None

    Additional tool metadata

    None
    **kwargs Any

    Additional arguments passed to Tool.from_callable

    {}
    Source code in src/llmling_agent/resource_providers/static.py
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    def tool(
        self,
        func: Callable[..., Any] | None = None,
        *,
        name: str | None = None,
        description: str | None = None,
        enabled: bool = True,
        requires_confirmation: bool = False,
        requires_capability: str | None = None,
        priority: int = 100,
        cache_enabled: bool = False,
        metadata: dict[str, str] | None = None,
        **kwargs: Any,
    ) -> Callable[..., Any] | Callable[[Callable[..., Any]], Callable[..., Any]]:
        """Decorator to register a function as a tool.
    
        Can be used with or without parameters:
    
        ```python
        # Without parameters
        @provider.tool
        def my_function(x: int) -> str:
            return str(x)
    
        # With parameters
        @provider.tool(name="custom_name", description="Custom description")
        def another_function(y: str) -> str:
            return y.upper()
        ```
    
        Args:
            func: Function to register (when used without parentheses)
            name: Override for tool name
            description: Override for tool description
            enabled: Whether tool is initially enabled
            requires_confirmation: Whether execution needs confirmation
            requires_capability: Optional capability requirement
            priority: Execution priority (lower = higher priority)
            cache_enabled: Whether to enable result caching
            metadata: Additional tool metadata
            **kwargs: Additional arguments passed to Tool.from_callable
        """
        from llmling_agent.tools.base import Tool
    
        def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
            tool = Tool.from_callable(
                f,
                name_override=name,
                description_override=description,
                enabled=enabled,
                requires_confirmation=requires_confirmation,
                requires_capability=requires_capability,
                priority=priority,
                cache_enabled=cache_enabled,
                metadata=metadata or {},
                **kwargs,
            )
            self.add_tool(tool)
            return f
    
        if func is None:
            # Called with arguments: @provider.tool(...)
            return decorator
        # Called without arguments: @provider.tool
        return decorator(func)