refactor(tools): extract shared logic for internal channels and tool definitions

- Add constants package with IsInternalChannel helper to centralize internal channel checks across agent, channels, and heartbeat services
- Add ToProviderDefs method to ToolRegistry to consolidate tool definition conversion logic used in agent loop and tool loop
- Refactor SubagentTool.Execute to use RunToolLoop for consistent tool execution with iteration tracking
- Remove duplicate inline map definitions and type assertion code throughout codebase
This commit is contained in:
yinwm
2026-02-13 15:05:16 +08:00
parent 0cce9fc905
commit 8851152cbd
7 changed files with 86 additions and 51 deletions

View File

@@ -49,18 +49,7 @@ func RunToolLoop(ctx context.Context, config ToolLoopConfig, messages []provider
// 1. Build tool definitions
var providerToolDefs []providers.ToolDefinition
if config.Tools != nil {
toolDefs := config.Tools.GetDefinitions()
providerToolDefs = make([]providers.ToolDefinition, 0, len(toolDefs))
for _, td := range toolDefs {
providerToolDefs = append(providerToolDefs, providers.ToolDefinition{
Type: td["type"].(string),
Function: providers.ToolFunctionDefinition{
Name: td["function"].(map[string]any)["name"].(string),
Description: td["function"].(map[string]any)["description"].(string),
Parameters: td["function"].(map[string]any)["parameters"].(map[string]any),
},
})
}
providerToolDefs = config.Tools.ToProviderDefs()
}
// 2. Set default LLM options