18c9354095
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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"
|
|
|
|
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 {
|
|
conversation models.Conversation
|
|
aiAgent models.AIAgent
|
|
}
|
|
|
|
func NewHandoffGraphTool() *HandoffGraphTool {
|
|
return &HandoffGraphTool{}
|
|
}
|
|
|
|
func (t *HandoffGraphTool) Spec() toolx.ToolSpec {
|
|
return toolx.GraphHandoffConversation
|
|
}
|
|
|
|
func (t *HandoffGraphTool) Name() string {
|
|
return toolx.GraphHandoffConversation.Name
|
|
}
|
|
|
|
func (t *HandoffGraphTool) Code() string {
|
|
return toolx.GraphHandoffConversation.Code
|
|
}
|
|
|
|
func (t *HandoffGraphTool) Enabled(ctx registry.Context) bool {
|
|
return true
|
|
}
|
|
|
|
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{
|
|
Name: toolx.GraphHandoffConversation.Name,
|
|
Desc: i18nx.Get("tool.graph.handoffConversation.info"),
|
|
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",
|
|
Description: i18nx.Get("tool.graph.handoffConversation.param.reason"),
|
|
},
|
|
},
|
|
)),
|
|
}),
|
|
Extra: map[string]any{
|
|
"tool_code": toolx.GraphHandoffConversation.Code,
|
|
"source_type": toolx.GraphHandoffConversation.SourceType,
|
|
},
|
|
}, 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)
|
|
}
|