feat: Enhance Wiki Fixer agent with improved issue handling and UI updates
- Updated the agent system prompt to refine the workflow for fixing issues, emphasizing the need to verify if issues still exist before making edits. - Introduced a new `embeddedMode` prop in the frontend components to manage UI behavior based on the context of use. - Simplified issue fix prompts in multiple languages for clarity, ensuring users receive concise instructions for resolving issues. - Enhanced the WikiBrowser component to improve the display of issues and actions, including updated icons and streamlined interaction elements. These changes significantly improve the user experience and functionality of the Wiki Fixer agent, fostering more efficient issue resolution and content management.
This commit is contained in:
@@ -12,12 +12,13 @@ import (
|
||||
|
||||
type wikiReplaceTextTool struct {
|
||||
BaseTool
|
||||
wikiPageService interfaces.WikiPageService
|
||||
kbIDs []string
|
||||
wikiPageService interfaces.WikiPageService
|
||||
knowledgeService interfaces.KnowledgeService
|
||||
kbIDs []string
|
||||
}
|
||||
|
||||
// NewWikiReplaceTextTool creates a new wiki_replace_text tool
|
||||
func NewWikiReplaceTextTool(wikiPageService interfaces.WikiPageService, kbIDs []string) types.Tool {
|
||||
func NewWikiReplaceTextTool(wikiPageService interfaces.WikiPageService, kbIDs []string, knowledgeService interfaces.KnowledgeService) types.Tool {
|
||||
return &wikiReplaceTextTool{
|
||||
BaseTool: NewBaseTool(
|
||||
ToolWikiReplaceText,
|
||||
@@ -40,14 +41,15 @@ func NewWikiReplaceTextTool(wikiPageService interfaces.WikiPageService, kbIDs []
|
||||
"source_refs": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "An optional list of source knowledge IDs that justify this change. If provided, these will COMPLETELY REPLACE the existing source_refs of the page."
|
||||
"description": "An optional list of source knowledge IDs (UUIDs only) that justify this change. If provided, these will COMPLETELY REPLACE the existing source_refs of the page."
|
||||
}
|
||||
},
|
||||
"required": ["slug", "old_text", "new_text"]
|
||||
}`),
|
||||
),
|
||||
wikiPageService: wikiPageService,
|
||||
kbIDs: kbIDs,
|
||||
wikiPageService: wikiPageService,
|
||||
knowledgeService: knowledgeService,
|
||||
kbIDs: kbIDs,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,13 +87,13 @@ func (t *wikiReplaceTextTool) Execute(ctx context.Context, args json.RawMessage)
|
||||
existingPage.Content = strings.Replace(existingPage.Content, params.OldText, params.NewText, 1)
|
||||
|
||||
if len(params.SourceRefs) > 0 {
|
||||
existingPage.SourceRefs = params.SourceRefs
|
||||
existingPage.SourceRefs = resolveSourceRefs(ctx, t.knowledgeService, params.SourceRefs)
|
||||
}
|
||||
|
||||
_, err = t.wikiPageService.UpdatePage(ctx, existingPage)
|
||||
if err != nil {
|
||||
return &types.ToolResult{Success: false, Error: "Failed to update page: " + err.Error()}, nil
|
||||
}
|
||||
|
||||
|
||||
return &types.ToolResult{Success: true, Output: fmt.Sprintf("Successfully replaced text on page %s.", params.Slug)}, nil
|
||||
}
|
||||
|
||||
@@ -137,6 +137,7 @@ func (t *wikiReadPageTool) Execute(ctx context.Context, args json.RawMessage) (*
|
||||
<title>%s</title>
|
||||
<slug>%s</slug>
|
||||
<type>%s</type>
|
||||
<aliases>%s</aliases>
|
||||
</metadata>
|
||||
<relationships>
|
||||
<links_to>%s</links_to>
|
||||
@@ -153,6 +154,7 @@ func (t *wikiReadPageTool) Execute(ctx context.Context, args json.RawMessage) (*
|
||||
</content>
|
||||
</wiki_page>`,
|
||||
page.Title, page.Slug, page.PageType,
|
||||
strings.Join(page.Aliases, ", "),
|
||||
strings.Join(outLinksDesc, ", "),
|
||||
strings.Join(inLinksDesc, ", "),
|
||||
strings.Join(sourcesDesc, "\n"),
|
||||
@@ -278,10 +280,15 @@ func (t *wikiSearchTool) Execute(ctx context.Context, args json.RawMessage) (*ty
|
||||
snippetTag = fmt.Sprintf("\n<match_snippet>%s</match_snippet>", snippet)
|
||||
}
|
||||
|
||||
aliasesTag := ""
|
||||
if len(p.Aliases) > 0 {
|
||||
aliasesTag = fmt.Sprintf("\n<aliases>%s</aliases>", strings.Join(p.Aliases, ", "))
|
||||
}
|
||||
|
||||
if seen {
|
||||
fmt.Fprintf(&sb, "<page>\n<title>%s</title>\n<slug>%s</slug>\n<type>%s</type>\n<summary>(summary omitted, already seen in previous search)</summary>%s\n</page>\n", p.Title, p.Slug, p.PageType, snippetTag)
|
||||
fmt.Fprintf(&sb, "<page>\n<title>%s</title>\n<slug>%s</slug>\n<type>%s</type>%s\n<summary>(summary omitted, already seen in previous search)</summary>%s\n</page>\n", p.Title, p.Slug, p.PageType, aliasesTag, snippetTag)
|
||||
} else {
|
||||
fmt.Fprintf(&sb, "<page>\n<title>%s</title>\n<slug>%s</slug>\n<type>%s</type>\n<summary>%s</summary>%s\n</page>\n", p.Title, p.Slug, p.PageType, p.Summary, snippetTag)
|
||||
fmt.Fprintf(&sb, "<page>\n<title>%s</title>\n<slug>%s</slug>\n<type>%s</type>%s\n<summary>%s</summary>%s\n</page>\n", p.Title, p.Slug, p.PageType, aliasesTag, p.Summary, snippetTag)
|
||||
}
|
||||
}
|
||||
sb.WriteString("</search_results>")
|
||||
@@ -327,6 +334,36 @@ func parseStringOrArray(val any) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// resolveSourceRefs enriches plain knowledge UUIDs to "uuid|title" format.
|
||||
// Refs already in "uuid|title" format are left unchanged.
|
||||
func resolveSourceRefs(ctx context.Context, knowledgeService interfaces.KnowledgeService, refs []string) []string {
|
||||
if len(refs) == 0 || knowledgeService == nil {
|
||||
return refs
|
||||
}
|
||||
resolved := make([]string, 0, len(refs))
|
||||
for _, ref := range refs {
|
||||
if strings.Contains(ref, "|") {
|
||||
resolved = append(resolved, ref)
|
||||
continue
|
||||
}
|
||||
kn, err := knowledgeService.GetKnowledgeByIDOnly(ctx, ref)
|
||||
if err != nil || kn == nil {
|
||||
resolved = append(resolved, ref)
|
||||
continue
|
||||
}
|
||||
title := kn.Title
|
||||
if title == "" {
|
||||
title = kn.FileName
|
||||
}
|
||||
if title != "" {
|
||||
resolved = append(resolved, ref+"|"+title)
|
||||
} else {
|
||||
resolved = append(resolved, ref)
|
||||
}
|
||||
}
|
||||
return resolved
|
||||
}
|
||||
|
||||
func extractSnippet(content string, query string) string {
|
||||
if content == "" || query == "" {
|
||||
return ""
|
||||
|
||||
@@ -13,12 +13,13 @@ import (
|
||||
|
||||
type wikiWritePageTool struct {
|
||||
BaseTool
|
||||
wikiPageService interfaces.WikiPageService
|
||||
kbIDs []string
|
||||
wikiPageService interfaces.WikiPageService
|
||||
knowledgeService interfaces.KnowledgeService
|
||||
kbIDs []string
|
||||
}
|
||||
|
||||
// NewWikiWritePageTool creates a new wiki_write_page tool
|
||||
func NewWikiWritePageTool(wikiPageService interfaces.WikiPageService, kbIDs []string) types.Tool {
|
||||
func NewWikiWritePageTool(wikiPageService interfaces.WikiPageService, kbIDs []string, knowledgeService interfaces.KnowledgeService) types.Tool {
|
||||
return &wikiWritePageTool{
|
||||
BaseTool: NewBaseTool(
|
||||
ToolWikiWritePage,
|
||||
@@ -54,14 +55,15 @@ func NewWikiWritePageTool(wikiPageService interfaces.WikiPageService, kbIDs []st
|
||||
"source_refs": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "A list of source knowledge IDs that contributed to this page. If provided, these will COMPLETELY REPLACE the existing source_refs of the page."
|
||||
"description": "A list of source knowledge IDs (UUIDs only) that contributed to this page. If provided, these will COMPLETELY REPLACE the existing source_refs of the page."
|
||||
}
|
||||
},
|
||||
"required": ["slug", "title", "summary", "content", "page_type"]
|
||||
}`),
|
||||
),
|
||||
wikiPageService: wikiPageService,
|
||||
kbIDs: kbIDs,
|
||||
wikiPageService: wikiPageService,
|
||||
knowledgeService: knowledgeService,
|
||||
kbIDs: kbIDs,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +97,8 @@ func (t *wikiWritePageTool) Execute(ctx context.Context, args json.RawMessage) (
|
||||
return &types.ToolResult{Success: false, Error: "Failed to check existing page: " + err.Error()}, nil
|
||||
}
|
||||
|
||||
resolvedRefs := resolveSourceRefs(ctx, t.knowledgeService, params.SourceRefs)
|
||||
|
||||
var action string
|
||||
if existingPage != nil {
|
||||
// Update
|
||||
@@ -104,8 +108,8 @@ func (t *wikiWritePageTool) Execute(ctx context.Context, args json.RawMessage) (
|
||||
existingPage.PageType = params.PageType
|
||||
existingPage.Aliases = params.Aliases
|
||||
|
||||
if len(params.SourceRefs) > 0 {
|
||||
existingPage.SourceRefs = params.SourceRefs
|
||||
if len(resolvedRefs) > 0 {
|
||||
existingPage.SourceRefs = resolvedRefs
|
||||
}
|
||||
|
||||
_, err = t.wikiPageService.UpdatePage(ctx, existingPage)
|
||||
@@ -123,7 +127,7 @@ func (t *wikiWritePageTool) Execute(ctx context.Context, args json.RawMessage) (
|
||||
Content: params.Content,
|
||||
PageType: params.PageType,
|
||||
Aliases: params.Aliases,
|
||||
SourceRefs: params.SourceRefs,
|
||||
SourceRefs: resolvedRefs,
|
||||
}
|
||||
_, err = t.wikiPageService.CreatePage(ctx, newPage)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user