feat: Implement wiki_config updates in knowledge base management

Added functionality to enable updates for the `wiki_config` field in the `KnowledgeBaseConfig` struct. This includes:

1. **Type Definition Update**: Added `WikiConfig` field to `KnowledgeBaseConfig` to allow JSON unmarshaling during update requests.
2. **Service Layer Enhancement**: Updated the `UpdateKnowledgeBase` method to persist changes to `wiki_config` when provided in the request.
3. **Frontend TypeScript Adjustments**: Enhanced type definitions in the frontend to support `wiki_config`, improving IDE autocomplete and type checking.

This fix addresses the critical issue where `wiki_config` was not being updated due to its absence in the `KnowledgeBaseConfig` struct, ensuring proper handling of wiki configurations during knowledge base updates.
This commit is contained in:
wizardchen
2026-04-07 19:36:06 +08:00
parent 33da010605
commit d4d005422d
27 changed files with 3362 additions and 530 deletions
+6
View File
@@ -34,6 +34,12 @@ const (
// produce content (e.g., thinking-only loops without KB).
// Trade-off: each retry costs ~2s of LLM latency; 2 retries = max 4s extra.
maxEmptyResponseRetries = 2
// maxRepeatedResponseRounds is the maximum number of consecutive rounds
// where the LLM returns identical content without any tool calls before
// the loop is forcibly terminated. This catches stuck loops caused by
// unhandled finish reasons (e.g., content_filter not caught elsewhere).
maxRepeatedResponseRounds = 2
)
// transientErrorMarkers are substrings that indicate a transient (retryable) error.
+23
View File
@@ -271,6 +271,8 @@ func (e *AgentEngine) executeLoop(
"max_iterations": e.config.MaxIterations,
})
emptyRetries := 0
consecutiveSameContent := 0
lastResponseContent := ""
for state.CurrentRound < e.config.MaxIterations {
// Check for context cancellation (request timeout, user cancel, etc.)
select {
@@ -326,6 +328,27 @@ func (e *AgentEngine) executeLoop(
response.Usage.CompletionTokens, response.Usage.TotalTokens)
}
// Detect stuck loops: if the LLM keeps returning the same content
// without tool calls (e.g., an unhandled finish reason), break early.
if len(response.ToolCalls) == 0 && response.Content != "" {
if response.Content == lastResponseContent {
consecutiveSameContent++
} else {
consecutiveSameContent = 0
}
lastResponseContent = response.Content
if consecutiveSameContent >= maxRepeatedResponseRounds {
logger.Warnf(ctx, "[Agent][Round-%d] Detected stuck loop: same content repeated %d times (finish=%s), stopping",
state.CurrentRound+1, consecutiveSameContent+1, response.FinishReason)
state.FinalAnswer = response.Content
state.IsComplete = true
break
}
} else {
consecutiveSameContent = 0
lastResponseContent = ""
}
// Create agent step
step := types.AgentStep{
Iteration: state.CurrentRound,
+48 -9
View File
@@ -15,11 +15,14 @@ const WikiSummaryPrompt = `You are a wiki editor. Given the following document c
## Document Content
{{.Content}}
## Available Wiki Pages (use these exact slugs for links)
{{.ExtractedSlugs}}
## Instructions
1. Write a comprehensive summary of the document in Markdown format.
2. Include the key facts, arguments, and conclusions.
3. Use proper heading hierarchy (## for sections, ### for subsections).
4. Where relevant, use [[wiki-link]] syntax to reference entities and concepts that might have their own wiki pages. Use lowercase slugs with hyphens, e.g. [[entity/company-name]] or [[concept/machine-learning]].
4. Use [[wiki-link]] syntax to reference the available wiki pages listed above. Use the EXACT slugs provided — do NOT invent new slugs.
5. At the end, include a "## Key Takeaways" section with bullet points.
6. Write in {{.Language}}.
7. Keep the summary concise but thorough (500-1500 words depending on document length).
@@ -37,24 +40,35 @@ const WikiKnowledgeExtractPrompt = `You are a knowledge extraction system. Analy
## Document Content
{{.Content}}
## Previously Extracted Slugs (from earlier version of this document)
{{.PreviousSlugs}}
## Instructions
Return a JSON object with two arrays: "entities" and "concepts".
**IMPORTANT: Write ALL names, descriptions, and details in {{.Language}}.**
### Slug Continuity Rules
If a "Previously Extracted Slugs" list is provided above, you MUST follow these rules:
- If an entity or concept from the previous extraction still exists in the current document, **reuse its exact slug** from the previous list. Do NOT generate a new slug for the same thing.
- If an entity or concept no longer appears in the document, **do NOT include it** in the output.
- Only generate new slugs for entities/concepts that are genuinely new (not present in the previous list).
- This ensures slug stability across document updates.
### Entities (people, organizations, products, places, technologies, events, etc.)
Each entity should have:
- "name": The entity name (human-readable)
- "slug": URL-friendly slug, format "entity/<lowercase-hyphenated-name>"
- "description": A one-sentence description based on what the document says
- "details": A 2-5 sentence summary of key facts from the document
- "name": The entity name in {{.Language}} (human-readable)
- "slug": URL-friendly slug, format "entity/<lowercase-hyphenated-name>" (use romanized/pinyin form for non-Latin names). **Reuse previous slug if the entity was extracted before.**
- "description": A one-sentence description in {{.Language}} based on what the document says
- "details": A 2-5 sentence summary in {{.Language}} of key facts from the document
Only include entities that are substantively discussed (mentioned at least twice or described in detail). Do NOT include generic terms.
### Concepts (topics, themes, methodologies, theories, etc.)
Each concept should have:
- "name": The concept name (human-readable)
- "slug": URL-friendly slug, format "concept/<lowercase-hyphenated-name>"
- "description": A one-sentence definition or description
- "details": A 2-5 sentence explanation as discussed in the document
- "name": The concept name in {{.Language}} (human-readable)
- "slug": URL-friendly slug, format "concept/<lowercase-hyphenated-name>" (use romanized/pinyin form for non-Latin names). **Reuse previous slug if the concept was extracted before.**
- "description": A one-sentence definition or description in {{.Language}}
- "details": A 2-5 sentence explanation in {{.Language}} as discussed in the document
Only include concepts that are substantively discussed. Skip trivial or overly generic concepts.
@@ -104,6 +118,31 @@ const WikiPageUpdatePrompt = `You are a wiki editor tasked with updating an exis
Output ONLY the updated Markdown content. Do not include any preamble or explanation.`
// WikiPageRetractPrompt removes information contributed by a deleted document from an existing wiki page.
const WikiPageRetractPrompt = `You are a wiki editor. A source document has been DELETED from the knowledge base. You must update the existing wiki page to remove any information that came exclusively from this deleted document.
## Existing Page Content
{{.ExistingContent}}
## Deleted Document Title
{{.DeletedDocTitle}}
## Remaining Source Documents
{{.RemainingSources}}
## Instructions
1. Carefully review the existing page content.
2. Remove any facts, claims, or details that were ONLY sourced from "{{.DeletedDocTitle}}".
3. If a fact is also supported by the remaining source documents, KEEP it.
4. If you are unsure whether a fact came from the deleted document, keep it but add a note: "> *This information may need verification after source removal.*"
5. Update or remove the "Source: {{.DeletedDocTitle}}" reference line if present.
6. Remove any [[wiki-link]] references that point to pages that no longer exist, if you can identify them.
7. Maintain the existing page structure, formatting style, and language.
8. If after removing the deleted document's contributions the page becomes nearly empty, output just: "# [Title]\n\n*This page has been archived — the primary source document was removed.*"
9. Write in {{.Language}}.
Output ONLY the updated Markdown content. Do not include any preamble or explanation.`
// WikiIndexRebuildPrompt generates the index page content from a list of all pages.
const WikiIndexRebuildPrompt = `You are a wiki editor. Generate an index page (table of contents) for a wiki based on the following page listing.