feat: enhance AI agent functionality with tool management and logging improvements

- Added AllowedToolCodes field to Context for managing tool access.
- Introduced ResumeSource in aiReplyTraceData to track resume points.
- Enhanced logging with additional fields: PlannedSkillName, SkillRouteTrace, InterruptType, ResumeSource, and FinalStatus.
- Implemented functions to parse and resolve allowed tool codes for agents and skills.
- Refactored skill definition creation and update logic to streamline request handling.
- Updated MCP tool catalog to include source type and integrated built-in tools.
- Improved UI components to display additional tool information and enhance user experience.
This commit is contained in:
mlogclub
2026-04-10 14:43:57 +08:00
parent 7411bac57d
commit 1370e4b675
23 changed files with 642 additions and 222 deletions
@@ -69,6 +69,7 @@ type MCPToolCatalogResponse struct {
ToolCode string `json:"toolCode"`
ServerCode string `json:"serverCode"`
ToolName string `json:"toolName"`
SourceType string `json:"sourceType"`
Title string `json:"title"`
Description string `json:"description"`
InputSchema any `json:"inputSchema"`
@@ -46,9 +46,14 @@ type AgentRunLogResponse struct {
UserMessage string `json:"userMessage"`
PlannedAction string `json:"plannedAction"`
PlannedSkillCode string `json:"plannedSkillCode"`
PlannedSkillName string `json:"plannedSkillName"`
SkillRouteTrace string `json:"skillRouteTrace"`
PlannedToolCode string `json:"plannedToolCode"`
PlanReason string `json:"planReason"`
InterruptType string `json:"interruptType"`
ResumeSource string `json:"resumeSource"`
FinalAction string `json:"finalAction"`
FinalStatus string `json:"finalStatus"`
ReplyText string `json:"replyText"`
ErrorMessage string `json:"errorMessage"`
LatencyMs int64 `json:"latencyMs"`
+9
View File
@@ -0,0 +1,9 @@
package toolx
const (
BuiltinToolCatalogServerCode = "builtin"
BuiltinCreateTicketConfirmToolCode = "builtin/create_ticket_with_confirmation"
BuiltinCreateTicketConfirmToolName = "create_ticket_with_confirmation"
BuiltinCreateTicketConfirmToolTitle = "创建工单并发起确认"
BuiltinCreateTicketConfirmToolDescription = "当用户明确要求创建工单,且标题和描述已经整理清楚后调用。工具会先向用户确认,确认后才真正创建工单。"
)
+20 -11
View File
@@ -35,23 +35,32 @@ func NormalizeMCPToolRequest(item request.AIAgentMCPToolRequest) (request.AIAgen
toolName := strings.TrimSpace(item.ToolName)
if toolCode != "" {
parsedServerCode, parsedToolName := SplitMCPToolCode(toolCode)
if parsedServerCode == "" || parsedToolName == "" {
return request.AIAgentMCPToolRequest{}, errorsx.InvalidParam("Direct Tool 的 toolCode 格式不合法")
if parsedServerCode != "" && parsedToolName != "" {
if serverCode != "" && !strings.EqualFold(serverCode, parsedServerCode) {
return request.AIAgentMCPToolRequest{}, errorsx.InvalidParam("Direct Tool 的 toolCode 与 serverCode 不一致")
}
if toolName != "" && !strings.EqualFold(toolName, parsedToolName) {
return request.AIAgentMCPToolRequest{}, errorsx.InvalidParam("Direct Tool 的 toolCode 与 toolName 不一致")
}
serverCode = parsedServerCode
toolName = parsedToolName
} else {
serverCode = ""
toolName = ""
}
if serverCode != "" && !strings.EqualFold(serverCode, parsedServerCode) {
return request.AIAgentMCPToolRequest{}, errorsx.InvalidParam("Direct Tool 的 toolCode 与 serverCode 不一致")
}
if toolName != "" && !strings.EqualFold(toolName, parsedToolName) {
return request.AIAgentMCPToolRequest{}, errorsx.InvalidParam("Direct Tool 的 toolCode 与 toolName 不一致")
}
serverCode = parsedServerCode
toolName = parsedToolName
} else {
toolCode = BuildMCPToolCode(serverCode, toolName)
}
if toolCode == "" || serverCode == "" || toolName == "" {
if toolCode == "" {
return request.AIAgentMCPToolRequest{}, errorsx.InvalidParam("Direct Tool 的 toolCode、serverCode 和 toolName 不能为空")
}
if parsedServerCode, parsedToolName := SplitMCPToolCode(toolCode); parsedServerCode != "" && parsedToolName != "" {
serverCode = parsedServerCode
toolName = parsedToolName
}
if serverCode == "" && toolName == "" && strings.Contains(toolCode, "/") && !strings.HasPrefix(toolCode, "builtin/") {
return request.AIAgentMCPToolRequest{}, errorsx.InvalidParam("Direct Tool 的 toolCode 格式不合法")
}
ret := request.AIAgentMCPToolRequest{
ToolCode: toolCode,
ServerCode: serverCode,