RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix(go-agent): read Keenable result content from snippet (#20480)
Denis Ermakov08d056e3dcdc
diff --git a/internal/agent/tool/keenable.go b/internal/agent/tool/keenable.goindex 43c8eb0731..41790cb471 100644--- a/internal/agent/tool/keenable.go+++ b/internal/agent/tool/keenable.go@@ -357,8 +357,8 @@ func buildKeenableReferences(envelope map[string]any) ([]map[string]any, []map[sif !ok {continue}- content := truncateKeenableRunes(strings.TrimSpace(keenableValueString(result["description"])), 10000)- if content == "" || content == "None" {+ content := truncateKeenableRunes(keenableResultContent(result), 10000)+ if content == "" {continue}documentID := strconv.FormatInt(keenableHashInt(content, 100000000), 10)@@ -387,6 +387,18 @@ func buildKeenableReferences(envelope map[string]any) ([]map[string]any, []map[sreturn chunks, docAggs}+// keenableResultContent returns a result's page text. Keenable carries it in+// "snippet" and often leaves "description" empty, so "description" is only+// the fallback.+func keenableResultContent(result map[string]any) string {+ for _, field := range []string{"snippet", "description"} {+ if content := keenableValueString(result[field]); content != "" && content != "None" {+ return content+ }+ }+ return ""+}+func renderKeenableReferences(chunks []map[string]any) string {blocks := make([]string, 0, len(chunks))for _, chunk := range chunks {diff --git a/internal/agent/tool/keenable_test.go b/internal/agent/tool/keenable_test.goindex f5ccb49a1e..3d9f00f745 100644--- a/internal/agent/tool/keenable_test.go+++ b/internal/agent/tool/keenable_test.go@@ -464,6 +464,56 @@ func TestKeenable_ComponentContractReferencesAndOutputs(t *testing.T) {}}+// TestKeenable_ReferencesReadSnippet verifies that a result's content comes+// from "snippet", which carries the page text in Keenable responses, and+// falls back to "description" only when "snippet" is empty.+func TestKeenable_ReferencesReadSnippet(t *testing.T) {+ t.Parallel()+ ctx := t.Context()++ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ w.Header().Set("Content-Type", "application/json")+ _, _ = w.Write([]byte(`{"results":[+ {"title":"A","url":"https://a","description":"","snippet":"alpha page text"},+ {"title":"B","url":"https://b","description":"beta description","snippet":""},+ {"title":"C","url":"https://c","description":"gamma description"},+ {"title":"D","url":"https://d","description":"delta description","snippet":"delta page text"},+ {"title":"E","url":"https://e","description":"","snippet":""}+ ]}`))+ }))+ defer srv.Close()++ helper := NewHTTPHelper().WithClient(&http.Client{+ Transport: rewriteHostTransport(srv.URL),+ })+ tool := NewKeenableToolWithEnvBaseURL(helper, func() string { return "https://" + srv.URL[len("http://"):] })++ out, err := tool.InvokableRun(ctx, `{"query":"x"}`)+ if err != nil {+ t.Fatalf("InvokableRun: %v", err)+ }+ var envelope map[string]any+ if jerr := json.Unmarshal([]byte(out), &envelope); jerr != nil {+ t.Fatalf("output not valid JSON: %v (raw=%s)", jerr, out)+ }++ chunks, docAggs := tool.BuildReferences(ctx, envelope)+ want := []struct{ title, content string }{+ {"A", "alpha page text"},+ {"B", "beta description"},+ {"C", "gamma description"},+ {"D", "delta page text"},+ }+ if len(chunks) != len(want) || len(docAggs) != len(want) {+ t.Fatalf("references = %#v / %#v, want %d of each", chunks, docAggs, len(want))+ }+ for i, w := range want {+ if chunks[i]["document_name"] != w.title || chunks[i]["content"] != w.content {+ t.Errorf("chunks[%d] = %q/%q, want %q/%q", i, chunks[i]["document_name"], chunks[i]["content"], w.title, w.content)+ }+ }+}+func TestKeenable_BuildByNameAcceptsCanvasParams(t *testing.T) {t.Parallel()