Skip to content

Commit c256e8b

Browse files
committed
refactor: Rename default_requires_instance to requires_redis_instance
Simplify the property to return bool instead of Optional[bool]. Base class returns whether redis_instance was provided; subclasses override to return True or False explicitly.
1 parent 8031d10 commit c256e8b

File tree

6 files changed

+18
-33
lines changed

6 files changed

+18
-33
lines changed

redis_sre_agent/tools/admin/redis_enterprise/provider.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ def provider_name(self) -> str:
101101
return "re_admin" # Shortened to avoid OpenAI 64-char tool name limit
102102

103103
@property
104-
def default_requires_instance(self) -> Optional[bool]:
105-
"""Admin tools always require a Redis Enterprise instance with admin access."""
106-
104+
def requires_redis_instance(self) -> bool:
105+
"""Admin tools always require a Redis Enterprise instance."""
107106
return True
108107

109108
def get_client(self) -> httpx.AsyncClient:

redis_sre_agent/tools/cloud/redis_cloud/provider.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ def provider_name(self) -> str:
144144
return "redis_cloud"
145145

146146
@property
147-
def default_requires_instance(self) -> Optional[bool]:
148-
"""Redis Cloud management tools do not require a specific Redis instance."""
149-
147+
def requires_redis_instance(self) -> bool:
148+
"""Redis Cloud management tools do not require a Redis instance."""
150149
return False
151150

152151
def get_client(self) -> GeneratedClient:

redis_sre_agent/tools/diagnostics/redis_command/provider.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ def provider_name(self) -> str:
126126
return "redis_command"
127127

128128
@property
129-
def default_requires_instance(self) -> Optional[bool]:
130-
"""Diagnostics tools for redis_command always require a Redis instance."""
131-
129+
def requires_redis_instance(self) -> bool:
130+
"""Diagnostics tools always require a Redis instance."""
132131
return True
133132

134133
def get_client(self) -> Redis:

redis_sre_agent/tools/knowledge/knowledge_base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ def provider_name(self) -> str:
3838
return "knowledge"
3939

4040
@property
41-
def default_requires_instance(self) -> Optional[bool]:
42-
"""Knowledge base tools do not depend on a specific Redis instance."""
43-
41+
def requires_redis_instance(self) -> bool:
42+
"""Knowledge base tools do not require a Redis instance."""
4443
return False
4544

4645
def create_tool_schemas(self) -> List[ToolDefinition]:

redis_sre_agent/tools/protocols.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -320,23 +320,21 @@ def create_tool_schemas(self) -> List["ToolDefinition"]:
320320
)
321321

322322
@property
323-
def default_requires_instance(self) -> Optional[bool]:
324-
"""Default ``requires_instance`` flag for this provider's tools.
323+
def requires_redis_instance(self) -> bool:
324+
"""Whether this provider's tools require a Redis instance.
325325
326-
Returns:
327-
* ``True`` if tools always require a Redis instance.
328-
* ``False`` if tools never require a Redis instance.
329-
* ``None`` (default) to derive from whether ``redis_instance`` was provided.
326+
Returns ``True`` if the provider was initialized with a ``redis_instance``.
327+
Subclasses can override to always return ``True`` or ``False`` regardless
328+
of initialization.
330329
"""
331-
332-
return None
330+
return self.redis_instance is not None
333331

334332
def tools(self) -> List["Tool"]:
335333
"""Return the concrete tools exposed by this provider.
336334
337335
The default implementation builds :class:`Tool` objects from
338336
:meth:`create_tool_schemas`, using the ``capability`` on each
339-
:class:`ToolDefinition` and :attr:`default_requires_instance` to
337+
:class:`ToolDefinition` and :attr:`requires_redis_instance` to
340338
populate :class:`ToolMetadata`.
341339
342340
Each tool's :pyattr:`Tool.invoke` closure is wired directly to the
@@ -351,14 +349,6 @@ def tools(self) -> List["Tool"]:
351349
# ignore :meth:`create_tool_schemas` entirely.
352350
schemas: List[ToolDefinition] = self.create_tool_schemas()
353351

354-
# Determine default requires_instance. ``None`` means derive from the
355-
# presence of ``redis_instance``.
356-
requires_instance = (
357-
bool(self.redis_instance)
358-
if self.default_requires_instance is None
359-
else bool(self.default_requires_instance)
360-
)
361-
362352
tools: List["Tool"] = []
363353
for schema in schemas:
364354
capability = schema.capability
@@ -373,7 +363,7 @@ def tools(self) -> List["Tool"]:
373363
description=schema.description,
374364
capability=capability,
375365
provider_name=self.provider_name,
376-
requires_instance=requires_instance,
366+
requires_instance=self.requires_redis_instance,
377367
)
378368

379369
# Derive operation name and look up the corresponding method.

redis_sre_agent/tools/utilities/provider.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ def provider_name(self) -> str:
4848
return "utilities"
4949

5050
@property
51-
def default_requires_instance(self) -> Optional[bool]:
52-
"""Utility tools do not depend on a specific Redis instance."""
53-
51+
def requires_redis_instance(self) -> bool:
52+
"""Utility tools do not require a Redis instance."""
5453
return False
5554

5655
def create_tool_schemas(self) -> List[ToolDefinition]:

0 commit comments

Comments
 (0)