feat: refactor tool handling to use ToolSet for improved organization and clarity
This commit is contained in:
@@ -20,8 +20,8 @@ func NewRegistry(tools ...Tool) *Registry {
|
||||
|
||||
func (r *Registry) Resolve(ctx Context) (*ToolSet, error) {
|
||||
ret := &ToolSet{
|
||||
Tools: make([]einotool.BaseTool, 0, len(r.tools)),
|
||||
ToolCodes: make(map[string]string),
|
||||
StaticTools: make([]einotool.BaseTool, 0, len(r.tools)),
|
||||
StaticToolCodes: make(map[string]string),
|
||||
}
|
||||
allowedToolCodes := makeAllowedToolCodeSet(ctx.AllowedToolCodes)
|
||||
for _, toolDef := range r.tools {
|
||||
@@ -45,8 +45,8 @@ func (r *Registry) Resolve(ctx Context) (*ToolSet, error) {
|
||||
if toolName == "" || toolCode == "" {
|
||||
continue
|
||||
}
|
||||
ret.Tools = append(ret.Tools, tool)
|
||||
ret.ToolCodes[toolName] = toolCode
|
||||
ret.StaticTools = append(ret.StaticTools, tool)
|
||||
ret.StaticToolCodes[toolName] = toolCode
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
@@ -14,9 +14,14 @@ type Context struct {
|
||||
AllowedToolCodes []string
|
||||
}
|
||||
|
||||
// ToolSet 描述当前运行时可直接挂载到 ToolsNode 上的固定工具集合。
|
||||
//
|
||||
// 这里不承载通过 tool_search 动态暴露的 MCP 工具;动态工具仍由 engine 层单独装配。
|
||||
type ToolSet struct {
|
||||
Tools []einotool.BaseTool
|
||||
ToolCodes map[string]string
|
||||
// StaticTools 为固定可见工具实例,例如 Graph Tool。
|
||||
StaticTools []einotool.BaseTool
|
||||
// StaticToolCodes 为固定工具的 modelName -> toolCode 映射,用于 trace 和运行日志归因。
|
||||
StaticToolCodes map[string]string
|
||||
}
|
||||
|
||||
type Tool interface {
|
||||
|
||||
Reference in New Issue
Block a user