2026-04-12 13:36:01 +08:00
package tools
import (
"context"
2026-05-31 18:43:48 +08:00
"agent-desk/internal/ai/runtime/graphs"
"agent-desk/internal/ai/runtime/registry"
"agent-desk/internal/models"
"agent-desk/internal/pkg/toolx"
2026-04-12 13:36:01 +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 AnalyzeConversationTool struct {
2026-04-17 18:48:45 +08:00
conversation models . Conversation
2026-04-12 13:36:01 +08:00
}
func NewAnalyzeConversationTool () * AnalyzeConversationTool {
return & AnalyzeConversationTool {}
}
2026-04-14 09:56:37 +08:00
func ( t * AnalyzeConversationTool ) Spec () toolx . ToolSpec {
return toolx . GraphAnalyzeConversation
}
2026-04-12 13:36:01 +08:00
func ( t * AnalyzeConversationTool ) Name () string {
2026-04-14 09:51:25 +08:00
return toolx . GraphAnalyzeConversation . Name
2026-04-12 13:36:01 +08:00
}
func ( t * AnalyzeConversationTool ) Code () string {
2026-04-14 09:51:25 +08:00
return toolx . GraphAnalyzeConversation . Code
2026-04-12 13:36:01 +08:00
}
func ( t * AnalyzeConversationTool ) Enabled ( ctx registry . Context ) bool {
2026-04-17 18:48:45 +08:00
return true
2026-04-12 13:36:01 +08:00
}
func ( t * AnalyzeConversationTool ) Build ( ctx registry . Context ) ( einotool . BaseTool , error ) {
if ! t . Enabled ( ctx ) {
return nil , nil
}
return & AnalyzeConversationTool { conversation : ctx . Conversation }, nil
}
func ( t * AnalyzeConversationTool ) Info ( ctx context . Context ) ( * schema . ToolInfo , error ) {
return & schema . ToolInfo {
2026-04-14 09:51:25 +08:00
Name : toolx . GraphAnalyzeConversation . Name ,
2026-05-31 20:06:44 +08:00
Desc : "Graph Tool. Summarizes the current conversation, identifies complaint/payment/sentiment risk signals, and recommends whether to continue answering, create a ticket, or hand off to a human." ,
2026-04-12 13:36:01 +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 : "goal" ,
Value : & einojsonschema . Schema {
Type : "string" ,
2026-05-31 20:06:44 +08:00
Description : "Analysis goal, such as whether to hand off to a human, create a ticket, or perform risk review." ,
2026-04-12 13:36:01 +08:00
},
},
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "observedIssue" ,
Value : & einojsonschema . Schema {
Type : "string" ,
2026-05-31 20:06:44 +08:00
Description : "Main issue or request observed in the conversation." ,
2026-04-12 13:36:01 +08:00
},
},
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "needTicket" ,
Value : & einojsonschema . Schema {
Type : "boolean" ,
2026-05-31 20:06:44 +08:00
Description : "Whether to focus on evaluating ticket creation." ,
2026-04-12 13:36:01 +08:00
},
},
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "needHumanHandoff" ,
Value : & einojsonschema . Schema {
Type : "boolean" ,
2026-05-31 20:06:44 +08:00
Description : "Whether to focus on evaluating human handoff." ,
2026-04-12 13:36:01 +08:00
},
},
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "needQualityCheck" ,
Value : & einojsonschema . Schema {
Type : "boolean" ,
2026-05-31 20:06:44 +08:00
Description : "Whether to focus on risk or quality review." ,
2026-04-12 13:36:01 +08:00
},
},
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "additionalContext" ,
Value : & einojsonschema . Schema {
Type : "string" ,
2026-05-31 20:06:44 +08:00
Description : "Additional context, such as disputes, complaint points, or business constraints already identified." ,
2026-04-12 13:36:01 +08:00
},
},
)),
}),
Extra : map [ string ] any {
2026-04-14 09:51:25 +08:00
"toolCode" : toolx . GraphAnalyzeConversation . Code ,
2026-04-14 18:27:45 +08:00
"sourceType" : toolx . GraphAnalyzeConversation . SourceType ,
2026-04-12 13:36:01 +08:00
},
}, nil
}
func ( t * AnalyzeConversationTool ) InvokableRun ( ctx context . Context , argumentsInJSON string , opts ... einotool . Option ) ( string , error ) {
return graphs . NewAnalyzeConversationGraph ( t . conversation ). Run ( ctx , argumentsInJSON )
}