refactor: Remove agent_test command-line tool and associated files to streamline project structure and eliminate unused components
This commit is contained in:
@@ -98,6 +98,7 @@ func (t *GetDocumentInfoTool) Execute(ctx context.Context, args map[string]inter
|
||||
}
|
||||
}
|
||||
|
||||
// Check if knowledge IDs are valid
|
||||
if len(knowledgeIDs) == 0 {
|
||||
return &types.ToolResult{
|
||||
Success: false,
|
||||
@@ -116,6 +117,7 @@ func (t *GetDocumentInfoTool) Execute(ctx context.Context, args map[string]inter
|
||||
var mu sync.Mutex
|
||||
results := make(map[string]*docInfo)
|
||||
|
||||
// Concurrently get info for each knowledge ID
|
||||
for _, knowledgeID := range knowledgeIDs {
|
||||
wg.Add(1)
|
||||
go func(id string) {
|
||||
@@ -195,10 +197,7 @@ func (t *GetDocumentInfoTool) Execute(ctx context.Context, args map[string]inter
|
||||
for i, doc := range successDocs {
|
||||
k := doc.knowledge
|
||||
|
||||
// Get file type icon
|
||||
typeIcon := getTypeIcon(k.Type, k.FileType)
|
||||
|
||||
output += fmt.Sprintf("【文档 #%d】 %s\n", i+1, typeIcon)
|
||||
output += fmt.Sprintf("【文档 #%d】\n", i+1)
|
||||
output += fmt.Sprintf(" ID: %s\n", k.ID)
|
||||
output += fmt.Sprintf(" 标题: %s\n", k.Title)
|
||||
|
||||
@@ -240,7 +239,6 @@ func (t *GetDocumentInfoTool) Execute(ctx context.Context, args map[string]inter
|
||||
"parse_status": k.ParseStatus,
|
||||
"chunk_count": doc.chunkCount,
|
||||
"metadata": k.GetMetadata(),
|
||||
"type_icon": typeIcon,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -264,36 +262,6 @@ func (t *GetDocumentInfoTool) Execute(ctx context.Context, args map[string]inter
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
|
||||
func getTypeIcon(knowledgeType, fileType string) string {
|
||||
switch knowledgeType {
|
||||
case "file":
|
||||
switch fileType {
|
||||
case "pdf", "PDF":
|
||||
return "📄 PDF"
|
||||
case "docx", "doc", "DOCX", "DOC":
|
||||
return "📝 Word"
|
||||
case "txt", "TXT":
|
||||
return "📃 Text"
|
||||
case "md", "MD", "markdown":
|
||||
return "📋 Markdown"
|
||||
case "xlsx", "xls", "XLSX", "XLS":
|
||||
return "📊 Excel"
|
||||
case "pptx", "ppt", "PPTX", "PPT":
|
||||
return "📊 PowerPoint"
|
||||
default:
|
||||
return "📄 File"
|
||||
}
|
||||
case "url":
|
||||
return "🌐 URL"
|
||||
case "passage":
|
||||
return "📝 Passage"
|
||||
default:
|
||||
return "📄 Document"
|
||||
}
|
||||
}
|
||||
|
||||
func formatSource(knowledgeType, source string) string {
|
||||
switch knowledgeType {
|
||||
case "file":
|
||||
|
||||
@@ -1173,44 +1173,6 @@ func (t *KnowledgeSearchTool) formatOutput(
|
||||
output += fmt.Sprintf(" 已召回: %d 个 (%.1f%%)\n", retrievedCount, percentage)
|
||||
output += fmt.Sprintf(" 未召回: %d 个\n", remaining)
|
||||
|
||||
if remaining > 0 {
|
||||
output += " 建议: 使用 list_knowledge_chunks 工具获取完整内容\n"
|
||||
|
||||
// Find missing chunk ranges (gaps in retrieved chunks)
|
||||
missingRanges := t.findMissingChunkRanges(retrievedChunks, int(totalChunks))
|
||||
|
||||
if len(missingRanges) == 0 {
|
||||
// No gaps found (shouldn't happen if remaining > 0, but handle it)
|
||||
output += fmt.Sprintf(
|
||||
" - 获取全部内容: list_knowledge_chunks(knowledge_id=\"%s\", offset=0, limit=%d)\n",
|
||||
knowledgeID,
|
||||
totalChunks,
|
||||
)
|
||||
} else if len(missingRanges) == 1 && missingRanges[0].start == 0 && missingRanges[0].end == int(totalChunks)-1 {
|
||||
// All chunks are missing (shouldn't happen, but handle it)
|
||||
output += fmt.Sprintf(" - 获取全部内容: list_knowledge_chunks(knowledge_id=\"%s\", offset=0, limit=%d)\n", knowledgeID, totalChunks)
|
||||
} else {
|
||||
// Suggest getting each missing range
|
||||
for idx, r := range missingRanges {
|
||||
rangeSize := r.end - r.start + 1
|
||||
if rangeSize <= 100 {
|
||||
// Small range, get all at once
|
||||
output += fmt.Sprintf(" - 区间 %d: chunk_index %d-%d (%d 个) → list_knowledge_chunks(knowledge_id=\"%s\", offset=%d, limit=%d)\n",
|
||||
idx+1, r.start, r.end, rangeSize, knowledgeID, r.start, rangeSize)
|
||||
} else {
|
||||
// Large range, suggest getting in batches
|
||||
output += fmt.Sprintf(" - 区间 %d: chunk_index %d-%d (%d 个,建议分批获取):\n",
|
||||
idx+1, r.start, r.end, rangeSize)
|
||||
output += fmt.Sprintf(" 首次: list_knowledge_chunks(knowledge_id=\"%s\", offset=%d, limit=100)\n",
|
||||
knowledgeID, r.start)
|
||||
if rangeSize > 100 {
|
||||
output += " 继续: 根据返回结果调整 offset 继续获取剩余内容\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output += "\n"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +168,7 @@ func (t *ListKnowledgeChunksTool) Execute(ctx context.Context, args map[string]i
|
||||
}, nil
|
||||
}
|
||||
|
||||
// lookupKnowledgeTitle looks up the title of a knowledge document
|
||||
func (t *ListKnowledgeChunksTool) lookupKnowledgeTitle(ctx context.Context, knowledgeID string) string {
|
||||
if t.knowledgeService == nil {
|
||||
return ""
|
||||
@@ -179,6 +180,7 @@ func (t *ListKnowledgeChunksTool) lookupKnowledgeTitle(ctx context.Context, know
|
||||
return strings.TrimSpace(knowledge.Title)
|
||||
}
|
||||
|
||||
// buildOutput builds the output for the list knowledge chunks tool
|
||||
func (t *ListKnowledgeChunksTool) buildOutput(
|
||||
knowledgeID string,
|
||||
knowledgeTitle string,
|
||||
@@ -226,6 +228,7 @@ func (t *ListKnowledgeChunksTool) buildOutput(
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// summarizeContent summarizes the content of a chunk
|
||||
func summarizeContent(content string) string {
|
||||
cleaned := strings.TrimSpace(content)
|
||||
if cleaned == "" {
|
||||
|
||||
@@ -85,7 +85,7 @@ func (t *QueryKnowledgeGraphTool) Parameters() map[string]interface{} {
|
||||
}
|
||||
}
|
||||
|
||||
// Execute queries the knowledge graph with concurrent KB processing
|
||||
// Execute performs the knowledge graph query with concurrent KB processing
|
||||
func (t *QueryKnowledgeGraphTool) Execute(ctx context.Context, args map[string]interface{}) (*types.ToolResult, error) {
|
||||
// Extract knowledge_base_ids array
|
||||
kbIDsRaw, ok := args["knowledge_base_ids"].([]interface{})
|
||||
@@ -394,14 +394,10 @@ func buildGraphVisualizationData(
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Extract actual entities and relations when graph extraction is fully implemented
|
||||
// For now, create placeholder structure
|
||||
|
||||
return map[string]interface{}{
|
||||
"nodes": nodes,
|
||||
"edges": edges,
|
||||
"total_nodes": len(nodes),
|
||||
"total_edges": len(edges),
|
||||
"visualization_note": "完整的图可视化功能开发中,当前显示文档节点",
|
||||
"nodes": nodes,
|
||||
"edges": edges,
|
||||
"total_nodes": len(nodes),
|
||||
"total_edges": len(edges),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
// SequentialThinkingTool implements a dynamic and reflective problem-solving tool
|
||||
// SequentialThinkingTool is a dynamic and reflective problem-solving tool
|
||||
// This tool helps analyze problems through a flexible thinking process that can adapt and evolve
|
||||
type SequentialThinkingTool struct {
|
||||
BaseTool
|
||||
|
||||
@@ -19,29 +19,31 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
webFetchTimeout = 60 * time.Second
|
||||
webFetchMaxChars = 100000
|
||||
webFetchTimeout = 60 * time.Second // timeout for web fetch
|
||||
webFetchMaxChars = 100000 // maximum number of characters to fetch
|
||||
)
|
||||
|
||||
// webFetchParams is the parameters for the web fetch tool
|
||||
type webFetchParams struct {
|
||||
URL string
|
||||
Prompt string
|
||||
}
|
||||
|
||||
// webFetchItemResult is the result for a web fetch item
|
||||
type webFetchItemResult struct {
|
||||
output string
|
||||
data map[string]interface{}
|
||||
err error
|
||||
}
|
||||
|
||||
// WebFetchTool 拉取网页内容并根据提示执行总结
|
||||
// WebFetchTool fetches web page content and summarizes it using an LLM
|
||||
type WebFetchTool struct {
|
||||
BaseTool
|
||||
client *http.Client
|
||||
chatModel chat.Chat
|
||||
}
|
||||
|
||||
// NewWebFetchTool 创建 web_fetch 工具实例
|
||||
// NewWebFetchTool creates a new web_fetch tool instance
|
||||
func NewWebFetchTool(chatModel chat.Chat) *WebFetchTool {
|
||||
description := `Fetch detailed web content from previously discovered URLs and analyze it with an LLM.
|
||||
|
||||
@@ -226,6 +228,7 @@ func (t *WebFetchTool) Execute(ctx context.Context, args map[string]interface{})
|
||||
}, nil
|
||||
}
|
||||
|
||||
// parseParams parses the parameters for a web fetch item
|
||||
func (t *WebFetchTool) parseParams(item interface{}) webFetchParams {
|
||||
params := webFetchParams{}
|
||||
if m, ok := item.(map[string]interface{}); ok {
|
||||
@@ -239,6 +242,7 @@ func (t *WebFetchTool) parseParams(item interface{}) webFetchParams {
|
||||
return params
|
||||
}
|
||||
|
||||
// validateParams validates the parameters for a web fetch item
|
||||
func (t *WebFetchTool) validateParams(p webFetchParams) error {
|
||||
if p.URL == "" {
|
||||
return fmt.Errorf("url is required")
|
||||
@@ -252,6 +256,7 @@ func (t *WebFetchTool) validateParams(p webFetchParams) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// executeFetch executes a web fetch item
|
||||
func (t *WebFetchTool) executeFetch(
|
||||
ctx context.Context,
|
||||
params webFetchParams,
|
||||
@@ -294,6 +299,7 @@ func (t *WebFetchTool) executeFetch(
|
||||
return output, resultData, summaryErr
|
||||
}
|
||||
|
||||
// normalizeGitHubURL normalizes a GitHub URL
|
||||
func (t *WebFetchTool) normalizeGitHubURL(source string) string {
|
||||
if strings.Contains(source, "github.com") && strings.Contains(source, "/blob/") {
|
||||
source = strings.Replace(source, "github.com", "raw.githubusercontent.com", 1)
|
||||
@@ -302,6 +308,7 @@ func (t *WebFetchTool) normalizeGitHubURL(source string) string {
|
||||
return source
|
||||
}
|
||||
|
||||
// processWithLLM processes the content with an LLM
|
||||
func (t *WebFetchTool) processWithLLM(ctx context.Context, params webFetchParams, content string) (string, error) {
|
||||
if t.chatModel == nil {
|
||||
return "", fmt.Errorf("chat model not available for web_fetch")
|
||||
@@ -336,6 +343,7 @@ func (t *WebFetchTool) processWithLLM(ctx context.Context, params webFetchParams
|
||||
return strings.TrimSpace(response.Content), nil
|
||||
}
|
||||
|
||||
// buildOutputText builds the output text for a web fetch item
|
||||
func (t *WebFetchTool) buildOutputText(params webFetchParams, content string, summary string, summaryErr error) string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString(fmt.Sprintf("URL: %s\n", params.URL))
|
||||
@@ -354,6 +362,7 @@ func (t *WebFetchTool) buildOutputText(params webFetchParams, content string, su
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// fetchHTMLContent fetches the HTML content for a web fetch item
|
||||
func (t *WebFetchTool) fetchHTMLContent(ctx context.Context, targetURL string) (string, string, error) {
|
||||
html, err := t.fetchWithChromedp(ctx, targetURL)
|
||||
if err == nil && strings.TrimSpace(html) != "" {
|
||||
@@ -375,6 +384,7 @@ func (t *WebFetchTool) fetchHTMLContent(ctx context.Context, targetURL string) (
|
||||
return html, "http", nil
|
||||
}
|
||||
|
||||
// fetchWithChromedp fetches the HTML content with Chromedp
|
||||
func (t *WebFetchTool) fetchWithChromedp(ctx context.Context, targetURL string) (string, error) {
|
||||
logger.Debugf(ctx, "[Tool][WebFetch] Chromedp 抓取开始 url=%s", targetURL)
|
||||
|
||||
@@ -414,6 +424,7 @@ func (t *WebFetchTool) fetchWithChromedp(ctx context.Context, targetURL string)
|
||||
return html, nil
|
||||
}
|
||||
|
||||
// fetchWithHTTP fetches the HTML content with HTTP
|
||||
func (t *WebFetchTool) fetchWithHTTP(ctx context.Context, targetURL string) (string, error) {
|
||||
resp, err := t.fetchWithTimeout(ctx, targetURL)
|
||||
if err != nil {
|
||||
@@ -434,6 +445,7 @@ func (t *WebFetchTool) fetchWithHTTP(ctx context.Context, targetURL string) (str
|
||||
return string(htmlBytes), nil
|
||||
}
|
||||
|
||||
// fetchWithTimeout fetches the HTML content with a timeout
|
||||
func (t *WebFetchTool) fetchWithTimeout(ctx context.Context, targetURL string) (*http.Response, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, targetURL, nil)
|
||||
if err != nil {
|
||||
@@ -451,6 +463,7 @@ func (t *WebFetchTool) fetchWithTimeout(ctx context.Context, targetURL string) (
|
||||
return t.client.Do(req)
|
||||
}
|
||||
|
||||
// convertHTMLToText converts the HTML content to text
|
||||
func (t *WebFetchTool) convertHTMLToText(html string) string {
|
||||
doc, err := goquery.NewDocumentFromReader(strings.NewReader(html))
|
||||
if err != nil {
|
||||
@@ -469,6 +482,7 @@ func (t *WebFetchTool) convertHTMLToText(html string) string {
|
||||
return strings.TrimSpace(result)
|
||||
}
|
||||
|
||||
// processNode processes a node in the HTML content
|
||||
func (t *WebFetchTool) processNode(s *goquery.Selection, markdown *strings.Builder) {
|
||||
s.Contents().Each(func(i int, node *goquery.Selection) {
|
||||
nodeName := goquery.NodeName(node)
|
||||
@@ -578,6 +592,7 @@ func (t *WebFetchTool) processNode(s *goquery.Selection, markdown *strings.Build
|
||||
})
|
||||
}
|
||||
|
||||
// basicTextExtraction extracts the text from the HTML content
|
||||
func (t *WebFetchTool) basicTextExtraction(html string) string {
|
||||
re := regexp.MustCompile(`<[^>]*>`)
|
||||
text := re.ReplaceAllString(html, " ")
|
||||
|
||||
Reference in New Issue
Block a user