diff --git a/pkg/tools/registry.go b/pkg/tools/registry.go index a81e79d63..9a483ce0c 100644 --- a/pkg/tools/registry.go +++ b/pkg/tools/registry.go @@ -30,6 +30,10 @@ type mediaStoreAware interface { SetMediaStore(store media.MediaStore) } +type registryCloneAware interface { + CloneForRegistry(registry *ToolRegistry) Tool +} + func NewToolRegistry() *ToolRegistry { return &ToolRegistry{ tools: make(map[string]*ToolEntry), @@ -413,11 +417,8 @@ func (r *ToolRegistry) Clone() *ToolRegistry { } for name, entry := range r.tools { tool := entry.Tool - switch t := entry.Tool.(type) { - case *RegexSearchTool: - tool = NewRegexSearchTool(clone, t.ttl, t.maxSearchResults) - case *BM25SearchTool: - tool = NewBM25SearchTool(clone, t.ttl, t.maxSearchResults) + if aware, ok := entry.Tool.(registryCloneAware); ok { + tool = aware.CloneForRegistry(clone) } clone.tools[name] = &ToolEntry{ Tool: tool, diff --git a/pkg/tools/search_tool.go b/pkg/tools/search_tool.go index c5884c9de..4304f9e01 100644 --- a/pkg/tools/search_tool.go +++ b/pkg/tools/search_tool.go @@ -26,6 +26,13 @@ func NewRegexSearchTool(r *ToolRegistry, ttl int, maxSearchResults int) *RegexSe return &RegexSearchTool{registry: r, ttl: ttl, maxSearchResults: maxSearchResults} } +func (t *RegexSearchTool) CloneForRegistry(registry *ToolRegistry) Tool { + if t == nil { + return NewRegexSearchTool(registry, 0, 0) + } + return NewRegexSearchTool(registry, t.ttl, t.maxSearchResults) +} + func (t *RegexSearchTool) Name() string { return "tool_search_tool_regex" } @@ -95,6 +102,13 @@ func NewBM25SearchTool(r *ToolRegistry, ttl int, maxSearchResults int) *BM25Sear return &BM25SearchTool{registry: r, ttl: ttl, maxSearchResults: maxSearchResults} } +func (t *BM25SearchTool) CloneForRegistry(registry *ToolRegistry) Tool { + if t == nil { + return NewBM25SearchTool(registry, 0, 0) + } + return NewBM25SearchTool(registry, t.ttl, t.maxSearchResults) +} + func (t *BM25SearchTool) Name() string { return "tool_search_tool_bm25" }