fix(tools): rebind discovery tools when cloning registries
This commit is contained in:
parent
01280eaa53
commit
8a8fe42f60
2 changed files with 34 additions and 1 deletions
|
|
@ -412,8 +412,15 @@ func (r *ToolRegistry) Clone() *ToolRegistry {
|
||||||
mediaStore: r.mediaStore,
|
mediaStore: r.mediaStore,
|
||||||
}
|
}
|
||||||
for name, entry := range r.tools {
|
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)
|
||||||
|
}
|
||||||
clone.tools[name] = &ToolEntry{
|
clone.tools[name] = &ToolEntry{
|
||||||
Tool: entry.Tool,
|
Tool: tool,
|
||||||
IsCore: entry.IsCore,
|
IsCore: entry.IsCore,
|
||||||
TTL: entry.TTL,
|
TTL: entry.TTL,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -515,6 +515,32 @@ func TestToolRegistry_Clone_PreservesTTLValue(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestToolRegistry_Clone_RebindsDiscoveryToolsToClone(t *testing.T) {
|
||||||
|
parent := NewToolRegistry()
|
||||||
|
parent.RegisterHidden(newMockTool("mcp_research", "deep research report tool"))
|
||||||
|
parent.Register(NewBM25SearchTool(parent, 3, 5))
|
||||||
|
|
||||||
|
clone := parent.Clone()
|
||||||
|
|
||||||
|
searchTool, ok := clone.Get("tool_search_tool_bm25")
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("expected cloned registry to expose BM25 search tool")
|
||||||
|
}
|
||||||
|
result := searchTool.Execute(context.Background(), map[string]any{
|
||||||
|
"query": "deep research",
|
||||||
|
})
|
||||||
|
if result == nil || result.IsError {
|
||||||
|
t.Fatalf("search result error: %+v", result)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := clone.Get("mcp_research"); !ok {
|
||||||
|
t.Fatal("expected search in clone to promote hidden tool in clone")
|
||||||
|
}
|
||||||
|
if _, ok := parent.Get("mcp_research"); ok {
|
||||||
|
t.Fatal("expected search in clone not to promote hidden tool in parent")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestToolRegistry_ConcurrentAccess(t *testing.T) {
|
func TestToolRegistry_ConcurrentAccess(t *testing.T) {
|
||||||
r := NewToolRegistry()
|
r := NewToolRegistry()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue