fix(tools): use registry-aware discovery tool cloning

This commit is contained in:
Anton Bogdanovich 2026-05-07 13:29:47 -07:00
parent 8a8fe42f60
commit cb606cdadc
2 changed files with 20 additions and 5 deletions

View file

@ -30,6 +30,10 @@ type mediaStoreAware interface {
SetMediaStore(store media.MediaStore) SetMediaStore(store media.MediaStore)
} }
type registryCloneAware interface {
CloneForRegistry(registry *ToolRegistry) Tool
}
func NewToolRegistry() *ToolRegistry { func NewToolRegistry() *ToolRegistry {
return &ToolRegistry{ return &ToolRegistry{
tools: make(map[string]*ToolEntry), tools: make(map[string]*ToolEntry),
@ -413,11 +417,8 @@ func (r *ToolRegistry) Clone() *ToolRegistry {
} }
for name, entry := range r.tools { for name, entry := range r.tools {
tool := entry.Tool tool := entry.Tool
switch t := entry.Tool.(type) { if aware, ok := entry.Tool.(registryCloneAware); ok {
case *RegexSearchTool: tool = aware.CloneForRegistry(clone)
tool = NewRegexSearchTool(clone, t.ttl, t.maxSearchResults)
case *BM25SearchTool:
tool = NewBM25SearchTool(clone, t.ttl, t.maxSearchResults)
} }
clone.tools[name] = &ToolEntry{ clone.tools[name] = &ToolEntry{
Tool: tool, Tool: tool,

View file

@ -26,6 +26,13 @@ func NewRegexSearchTool(r *ToolRegistry, ttl int, maxSearchResults int) *RegexSe
return &RegexSearchTool{registry: r, ttl: ttl, maxSearchResults: maxSearchResults} 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 { func (t *RegexSearchTool) Name() string {
return "tool_search_tool_regex" 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} 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 { func (t *BM25SearchTool) Name() string {
return "tool_search_tool_bm25" return "tool_search_tool_bm25"
} }