2026-04-10 16:00:10 +08:00
|
|
|
package tools
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2026-08-21 00:41:07 +08:00
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/ai/runtime/graphs"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/ai/runtime/registry"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/i18nx"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/toolx"
|
2026-04-10 16:00:10 +08:00
|
|
|
|
|
|
|
|
einotool "github.com/cloudwego/eino/components/tool"
|
|
|
|
|
"github.com/cloudwego/eino/schema"
|
|
|
|
|
einojsonschema "github.com/eino-contrib/jsonschema"
|
|
|
|
|
orderedmap "github.com/wk8/go-ordered-map/v2"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type HandoffGraphTool struct {
|
2026-04-17 18:48:45 +08:00
|
|
|
conversation models.Conversation
|
2026-04-17 17:57:01 +08:00
|
|
|
aiAgent models.AIAgent
|
2026-04-10 16:00:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewHandoffGraphTool() *HandoffGraphTool {
|
|
|
|
|
return &HandoffGraphTool{}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 09:56:37 +08:00
|
|
|
func (t *HandoffGraphTool) Spec() toolx.ToolSpec {
|
|
|
|
|
return toolx.GraphHandoffConversation
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-10 16:00:10 +08:00
|
|
|
func (t *HandoffGraphTool) Name() string {
|
2026-04-14 09:51:25 +08:00
|
|
|
return toolx.GraphHandoffConversation.Name
|
2026-04-10 16:00:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *HandoffGraphTool) Code() string {
|
2026-04-14 09:51:25 +08:00
|
|
|
return toolx.GraphHandoffConversation.Code
|
2026-04-10 16:00:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *HandoffGraphTool) Enabled(ctx registry.Context) bool {
|
2026-04-17 17:57:01 +08:00
|
|
|
return true
|
2026-04-10 16:00:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *HandoffGraphTool) Build(ctx registry.Context) (einotool.BaseTool, error) {
|
|
|
|
|
if !t.Enabled(ctx) {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
return &HandoffGraphTool{
|
|
|
|
|
conversation: ctx.Conversation,
|
|
|
|
|
aiAgent: ctx.AIAgent,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *HandoffGraphTool) Info(ctx context.Context) (*schema.ToolInfo, error) {
|
|
|
|
|
return &schema.ToolInfo{
|
2026-04-14 09:51:25 +08:00
|
|
|
Name: toolx.GraphHandoffConversation.Name,
|
2026-06-03 09:36:33 +08:00
|
|
|
Desc: i18nx.Get("tool.graph.handoffConversation.info"),
|
2026-04-10 16:00:10 +08:00
|
|
|
ParamsOneOf: schema.NewParamsOneOfByJSONSchema(&einojsonschema.Schema{
|
|
|
|
|
Version: einojsonschema.Version,
|
|
|
|
|
Type: "object",
|
|
|
|
|
Properties: orderedmap.New[string, *einojsonschema.Schema](orderedmap.WithInitialData(
|
|
|
|
|
orderedmap.Pair[string, *einojsonschema.Schema]{
|
|
|
|
|
Key: "reason",
|
|
|
|
|
Value: &einojsonschema.Schema{
|
|
|
|
|
Type: "string",
|
2026-06-03 09:36:33 +08:00
|
|
|
Description: i18nx.Get("tool.graph.handoffConversation.param.reason"),
|
2026-04-10 16:00:10 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
)),
|
|
|
|
|
}),
|
|
|
|
|
Extra: map[string]any{
|
2026-08-28 22:23:13 +08:00
|
|
|
"tool_code": toolx.GraphHandoffConversation.Code,
|
|
|
|
|
"source_type": toolx.GraphHandoffConversation.SourceType,
|
2026-04-10 16:00:10 +08:00
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *HandoffGraphTool) InvokableRun(ctx context.Context, argumentsInJSON string, opts ...einotool.Option) (string, error) {
|
|
|
|
|
return graphs.NewHandoffGraph(t.conversation, t.aiAgent).Run(ctx, argumentsInJSON)
|
|
|
|
|
}
|