fix(tools): use registry-aware discovery tool cloning
This commit is contained in:
parent
8a8fe42f60
commit
cb606cdadc
2 changed files with 20 additions and 5 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue