refactor: update tool registry usage and enhance WebSearchTool execution result handling
This commit is contained in:
@@ -77,9 +77,9 @@ func createToolRegistry(workspace string, restrict bool, cfg *config.Config, msg
|
|||||||
DuckDuckGoMaxResults: cfg.Tools.Web.DuckDuckGo.MaxResults,
|
DuckDuckGoMaxResults: cfg.Tools.Web.DuckDuckGo.MaxResults,
|
||||||
DuckDuckGoEnabled: cfg.Tools.Web.DuckDuckGo.Enabled,
|
DuckDuckGoEnabled: cfg.Tools.Web.DuckDuckGo.Enabled,
|
||||||
}); searchTool != nil {
|
}); searchTool != nil {
|
||||||
toolsRegistry.Register(searchTool)
|
registry.Register(searchTool)
|
||||||
}
|
}
|
||||||
toolsRegistry.Register(tools.NewWebFetchTool(50000))
|
registry.Register(tools.NewWebFetchTool(50000))
|
||||||
|
|
||||||
// Message tool - available to both agent and subagent
|
// Message tool - available to both agent and subagent
|
||||||
// Subagent uses it to communicate directly with user
|
// Subagent uses it to communicate directly with user
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ func (t *WebSearchTool) Parameters() map[string]interface{} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *WebSearchTool) Execute(ctx context.Context, args map[string]interface{}) (string, error) {
|
func (t *WebSearchTool) Execute(ctx context.Context, args map[string]interface{}) *ToolResult {
|
||||||
query, ok := args["query"].(string)
|
query, ok := args["query"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrorResult("query is required")
|
return ErrorResult("query is required")
|
||||||
@@ -261,7 +261,15 @@ func (t *WebSearchTool) Execute(ctx context.Context, args map[string]interface{}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.provider.Search(ctx, query, count)
|
result, err := t.provider.Search(ctx, query, count)
|
||||||
|
if err != nil {
|
||||||
|
return ErrorResult(fmt.Sprintf("search failed: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ToolResult{
|
||||||
|
ForLLM: result,
|
||||||
|
ForUser: result,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebFetchTool struct {
|
type WebFetchTool struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user