2026-04-12 13:39:16 +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:39:16 +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 TriageServiceRequestTool struct {
2026-04-17 18:48:45 +08:00
conversation models . Conversation
2026-04-12 13:39:16 +08:00
}
func NewTriageServiceRequestTool () * TriageServiceRequestTool {
return & TriageServiceRequestTool {}
}
2026-04-14 09:56:37 +08:00
func ( t * TriageServiceRequestTool ) Spec () toolx . ToolSpec {
return toolx . GraphTriageServiceRequest
}
2026-04-12 13:39:16 +08:00
func ( t * TriageServiceRequestTool ) Name () string {
2026-04-14 09:51:25 +08:00
return toolx . GraphTriageServiceRequest . Name
2026-04-12 13:39:16 +08:00
}
func ( t * TriageServiceRequestTool ) Code () string {
2026-04-14 09:51:25 +08:00
return toolx . GraphTriageServiceRequest . Code
2026-04-12 13:39:16 +08:00
}
func ( t * TriageServiceRequestTool ) Enabled ( ctx registry . Context ) bool {
2026-04-17 18:48:45 +08:00
return true
2026-04-12 13:39:16 +08:00
}
func ( t * TriageServiceRequestTool ) Build ( ctx registry . Context ) ( einotool . BaseTool , error ) {
if ! t . Enabled ( ctx ) {
return nil , nil
}
return & TriageServiceRequestTool { conversation : ctx . Conversation }, nil
}
func ( t * TriageServiceRequestTool ) Info ( ctx context . Context ) ( * schema . ToolInfo , error ) {
return & schema . ToolInfo {
2026-04-14 09:51:25 +08:00
Name : toolx . GraphTriageServiceRequest . Name ,
2026-05-31 20:06:44 +08:00
Desc : "Graph Tool. Analyzes the current conversation to decide whether to continue answering, prepare a ticket draft, or hand off to a human. When ticket creation is recommended, it returns a structured ticket draft suggestion." ,
2026-04-12 13:39:16 +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 escalate, create a ticket, or hand off to a human." ,
2026-04-12 13:39:16 +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 dispute observed in the conversation." ,
2026-04-12 13:39:16 +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:39:16 +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:39:16 +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 risk signals or constraints already identified." ,
2026-04-12 13:39:16 +08:00
},
},
)),
}),
Extra : map [ string ] any {
2026-04-14 09:51:25 +08:00
"toolCode" : toolx . GraphTriageServiceRequest . Code ,
2026-04-12 13:39:16 +08:00
"sourceType" : "graph" ,
},
}, nil
}
func ( t * TriageServiceRequestTool ) InvokableRun ( ctx context . Context , argumentsInJSON string , opts ... einotool . Option ) ( string , error ) {
return graphs . NewTriageServiceRequestGraph ( t . conversation ). Run ( ctx , argumentsInJSON )
}