Skip to content

Commit 75899b0

Browse files
authored
Adjustments in tool_filtering.py (#71)
1 parent 6aed443 commit 75899b0

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

splunklib/ai/tool_filtering.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright © 2011-2026 Splunk, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"): you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
115
from collections.abc import Sequence
216
from dataclasses import dataclass
317

@@ -6,23 +20,21 @@
620

721
@dataclass(frozen=True)
822
class ToolFilters:
23+
"""Allowlists by which Tools are filtered."""
24+
925
allowed_names: Sequence[str]
1026
allowed_tags: Sequence[str]
1127

1228

13-
def filter_tools(tools: Sequence[Tool], filters: ToolFilters) -> list[Tool]:
14-
"""Filters all tools by allowlists provided by user to the Agent
29+
def _is_allowed(tool: Tool, filters: ToolFilters) -> bool:
30+
return (
31+
tool.name in filters.allowed_names
32+
or len(set(filters.allowed_tags).intersection(tool.tags or [])) > 0
33+
)
1534

16-
TODO: What happens when local and remote tools share names?
17-
Does local overwrite remote (or vice versa)? Do we allow choice between overwriting,
18-
prefixing both or raising exceptions? See tools.py:load_mcp_tools()
19-
"""
2035

21-
def _predicate(tool: Tool) -> bool:
22-
return (
23-
tool.name in filters.allowed_names
24-
or len(set(filters.allowed_tags).intersection(tool.tags or [])) > 0
25-
)
36+
def filter_tools(tools: Sequence[Tool], filters: ToolFilters) -> list[Tool]:
37+
"""Filters all tools by allowlists provided by user to the Agent."""
2638

27-
filtered_tools = list(filter(_predicate, tools))
39+
filtered_tools = [t for t in tools if _is_allowed(t, filters)]
2840
return filtered_tools

0 commit comments

Comments
 (0)