This commit is contained in:
jhawpetoss6-collab 2026-03-24 01:37:10 +00:00 committed by GitHub
commit 5cfb84bbc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
from collections.abc import Callable
from typing import Any
class DynamicToolRegistry:
"""
Registry for dynamic tool injection in Dify agents.
Allows injecting custom tool logic at runtime without service restarts.
"""
def __init__(self):
self._tools: dict[str, Callable] = {}
def register_tool(self, name: str, func: Callable):
self._tools[name] = func
def get_tool(self, name: str) -> Callable:
return self._tools.get(name)
def execute_tool(self, name: str, **kwargs) -> Any:
tool = self.get_tool(name)
if not tool:
raise ValueError(f"Tool {name} not found in dynamic registry.")
return tool(**kwargs)