feat: implement Spec method for tools and update tool resolution logic in the registry
This commit is contained in:
@@ -29,7 +29,11 @@ func (r *Registry) Resolve(ctx Context) (*ToolSet, error) {
|
||||
if toolDef == nil || !toolDef.Enabled(ctx) {
|
||||
continue
|
||||
}
|
||||
toolCode := strings.TrimSpace(toolDef.Code())
|
||||
spec := toolDef.Spec()
|
||||
toolCode := strings.TrimSpace(spec.Code)
|
||||
if toolCode == "" {
|
||||
toolCode = strings.TrimSpace(toolDef.Code())
|
||||
}
|
||||
if len(allowedToolCodes) > 0 && !isAllowedToolCode(toolCode, allowedToolCodes) {
|
||||
continue
|
||||
}
|
||||
@@ -40,13 +44,25 @@ func (r *Registry) Resolve(ctx Context) (*ToolSet, error) {
|
||||
if tool == nil {
|
||||
continue
|
||||
}
|
||||
toolName := strings.TrimSpace(toolDef.Name())
|
||||
toolName := strings.TrimSpace(spec.Name)
|
||||
if toolName == "" {
|
||||
toolName = strings.TrimSpace(toolDef.Name())
|
||||
}
|
||||
if toolName == "" || toolCode == "" {
|
||||
continue
|
||||
}
|
||||
ret.StaticTools = append(ret.StaticTools, tool)
|
||||
ret.StaticToolCodes[toolName] = toolCode
|
||||
resolvedMetadata := toolx.ResolveToolMetadata(toolCode, toolName)
|
||||
if strings.TrimSpace(resolvedMetadata.ServerCode) == "" {
|
||||
resolvedMetadata.ServerCode = strings.TrimSpace(spec.ServerCode)
|
||||
}
|
||||
if strings.TrimSpace(resolvedMetadata.ToolName) == "" {
|
||||
resolvedMetadata.ToolName = toolName
|
||||
}
|
||||
if strings.TrimSpace(resolvedMetadata.SourceType) == "" {
|
||||
resolvedMetadata.SourceType = strings.TrimSpace(spec.SourceType)
|
||||
}
|
||||
ret.StaticToolMetadata[toolName] = ToolMetadata{
|
||||
ToolCode: resolvedMetadata.ToolCode,
|
||||
ServerCode: resolvedMetadata.ServerCode,
|
||||
|
||||
@@ -17,6 +17,15 @@ type stubTool struct {
|
||||
code string
|
||||
}
|
||||
|
||||
func (t stubTool) Spec() toolx.ToolSpec {
|
||||
return toolx.ToolSpec{
|
||||
Code: t.code,
|
||||
Name: t.name,
|
||||
ServerCode: toolx.GraphCreateTicketConfirm.ServerCode,
|
||||
SourceType: toolx.GraphCreateTicketConfirm.SourceType,
|
||||
}
|
||||
}
|
||||
|
||||
func (t stubTool) Name() string { return t.name }
|
||||
func (t stubTool) Code() string { return t.code }
|
||||
func (t stubTool) Enabled(registry.Context) bool {
|
||||
|
||||
@@ -2,6 +2,7 @@ package registry
|
||||
|
||||
import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/pkg/toolx"
|
||||
|
||||
einotool "github.com/cloudwego/eino/components/tool"
|
||||
)
|
||||
@@ -34,6 +35,7 @@ type ToolSet struct {
|
||||
}
|
||||
|
||||
type Tool interface {
|
||||
Spec() toolx.ToolSpec
|
||||
Name() string
|
||||
Code() string
|
||||
Enabled(ctx Context) bool
|
||||
|
||||
Reference in New Issue
Block a user