feat: add Graph Tool tracing and logging support in agent run logs
This commit is contained in:
@@ -49,3 +49,13 @@ func (c *RuntimeTraceCollector) AddToolSearchItem(item ToolSearchTraceItem) {
|
||||
c.Data.ToolSearch.Count++
|
||||
c.Data.ToolSearch.Items = append(c.Data.ToolSearch.Items, item)
|
||||
}
|
||||
|
||||
func (c *RuntimeTraceCollector) AddGraphToolItem(item GraphToolTraceItem) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.Data.GraphTools.Count++
|
||||
c.Data.GraphTools.Items = append(c.Data.GraphTools.Items, item)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,16 @@ type ToolSearchTraceItem struct {
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
}
|
||||
|
||||
type GraphToolTraceItem struct {
|
||||
ToolCode string `json:"toolCode"`
|
||||
ToolName string `json:"toolName"`
|
||||
Arguments map[string]any `json:"arguments,omitempty"`
|
||||
ResultPreview string `json:"resultPreview,omitempty"`
|
||||
LatencyMs int64 `json:"latencyMs,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
}
|
||||
|
||||
type RetrieverTraceItem struct {
|
||||
Query string `json:"query,omitempty"`
|
||||
KnowledgeBaseID int64 `json:"knowledgeBaseId,omitempty"`
|
||||
@@ -62,6 +72,10 @@ type RuntimeTraceData struct {
|
||||
Count int `json:"count,omitempty"`
|
||||
Items []ToolSearchTraceItem `json:"items,omitempty"`
|
||||
} `json:"toolSearch"`
|
||||
GraphTools struct {
|
||||
Count int `json:"count,omitempty"`
|
||||
Items []GraphToolTraceItem `json:"items,omitempty"`
|
||||
} `json:"graphTools"`
|
||||
Output struct {
|
||||
ReplyText string `json:"replyText,omitempty"`
|
||||
FinishReason string `json:"finishReason,omitempty"`
|
||||
|
||||
@@ -67,6 +67,7 @@ func (f *AgentFactory) BuildCustomerServiceAgent(ctx context.Context, aiAgent *m
|
||||
ToolCode: item.ToolCode,
|
||||
ServerCode: item.ServerCode,
|
||||
ToolName: item.ToolName,
|
||||
SourceType: "mcp",
|
||||
}
|
||||
}
|
||||
for modelName, toolCode := range extraToolCodes {
|
||||
@@ -87,6 +88,7 @@ func (f *AgentFactory) BuildCustomerServiceAgent(ctx context.Context, aiAgent *m
|
||||
ToolCode: toolCode,
|
||||
ServerCode: serverCode,
|
||||
ToolName: toolName,
|
||||
SourceType: resolveToolSourceType(toolCode),
|
||||
}
|
||||
}
|
||||
handlers = append(handlers, einocallbacks.NewRuntimeTraceHandler(collector, toolMetadataBy))
|
||||
@@ -109,6 +111,20 @@ func (f *AgentFactory) BuildCustomerServiceAgent(ctx context.Context, aiAgent *m
|
||||
return &einoagents.CustomerServiceAgent{Inner: inner}, nil
|
||||
}
|
||||
|
||||
func resolveToolSourceType(toolCode string) string {
|
||||
toolCode = strings.TrimSpace(toolCode)
|
||||
switch {
|
||||
case toolCode == toolx.BuiltinToolSearchToolCode:
|
||||
return toolx.BuiltinToolCatalogServerCode
|
||||
case strings.HasPrefix(toolCode, toolx.GraphToolCatalogServerCode+"/"):
|
||||
return toolx.GraphToolCatalogServerCode
|
||||
case strings.HasPrefix(toolCode, toolx.BuiltinToolCatalogServerCode+"/"):
|
||||
return toolx.BuiltinToolCatalogServerCode
|
||||
default:
|
||||
return "mcp"
|
||||
}
|
||||
}
|
||||
|
||||
func buildAgentInstruction(aiAgent *models.AIAgent, selectedSkill *models.SkillDefinition, toolDefinitions []einoadapter.MCPToolDefinition, extraToolCodes map[string]string) string {
|
||||
baseInstruction := ""
|
||||
if aiAgent != nil {
|
||||
|
||||
Reference in New Issue
Block a user