Skip to content

refactor(app_dsl_service): extract knowledge base parsing logic into a standalone utility function - #1997

Open
wanxunyang wants to merge 1 commit into
release/v0.4.1from
fix/wxy-release
Open

refactor(app_dsl_service): extract knowledge base parsing logic into a standalone utility function#1997
wanxunyang wants to merge 1 commit into
release/v0.4.1from
fix/wxy-release

Conversation

@wanxunyang

@wanxunyang wanxunyang commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Extract the knowledge base parsing code from the original workflow node into the _resolve_kb_entries private method, simplifying the code structure while reusing the parsing logic, and supporting knowledge base configuration handling for Agent nodes.

由 Sourcery 生成的总结

将工作流节点的知识库解析逻辑重构为可复用的辅助方法,并在相关节点类型中统一使用。

改进内容:

  • 将知识库解析与解析结果提取到专用的 _resolve_kb_entries 辅助方法中,以便在多个节点间复用。
  • 将统一的知识库解析逻辑应用于知识检索节点和智能体节点,包括旧版配置和嵌套配置结构。
Original summary in English

Summary by Sourcery

Refactor workflow node knowledge base resolution into a reusable helper and apply it across relevant node types.

Enhancements:

  • Extract knowledge base parsing and resolution into a dedicated _resolve_kb_entries helper for reuse across nodes.
  • Apply unified knowledge base resolution to knowledge retrieval and agent nodes, including legacy and nested configuration layouts.

…a standalone utility function

Extract the knowledge base parsing code from the original workflow node into the _resolve_kb_entries private method, simplifying the code structure while reusing the parsing logic, and supporting knowledge base configuration handling for Agent nodes.
@sourcery-ai

sourcery-ai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

将知识库解析逻辑重构为可复用的辅助方法,并扩展至 Agent 节点,确保在 Knowledge Retrieval 和 Agent 节点配置中对知识库引用进行校验和清洗。

KnowledgeRetrieval 和 Agent 节点中知识库解析的流程图

flowchart TD
    A_resolve_nodes[_resolve_workflow_nodes] --> B_check_type{node_type}

    B_check_type -->|KNOWLEDGE_RETRIEVAL| C_kb_node["config.knowledge_bases = _resolve_kb_entries(config.knowledge_bases)"]

    B_check_type -->|AGENT| D_agent["Agent node config"]

    D_agent --> E_nested_kb{knowledge_retrieval.knowledge_bases}
    E_nested_kb -->|present| F_nested["knowledge_retrieval.knowledge_bases = _resolve_kb_entries(knowledge_retrieval.knowledge_bases)"]

    D_agent --> G_legacy_kb{config.knowledge_bases}
    G_legacy_kb -->|present| H_legacy["config.knowledge_bases = _resolve_kb_entries(config.knowledge_bases)"]

    subgraph S[_resolve_kb_entries]
        I_for_each[[for kb in knowledge_bases]] --> J_build_ref[build kb_ref from kb.kb_id]
        J_build_ref --> K_call_resolve["_resolve_kb(kb_ref, workspace_id, empty list)"]
        K_call_resolve --> L_match{resolved_id}
        L_match -->|yes| M_keep[append kb with resolved kb_id]
        L_match -->|no| N_warn[append warning for node_label]
    end
Loading

File-Level Changes

Change Details Files
抽取可复用的知识库解析辅助方法,并应用于引用知识库的 workflow 节点。
  • 引入私有方法 _resolve_kb_entries,用于规范化 kb_id 输入,通过 _resolve_kb 进行解析,累积已解析的条目,并为未匹配到的知识库追加警告。
  • 用对 _resolve_kb_entries 的调用替换 KNOWLEDGE_RETRIEVAL 节点中内联的知识库解析逻辑,以复用解析逻辑。
  • 更新 AGENT 节点处理逻辑,使用 _resolve_kb_entries 清洗并解析嵌套的 knowledge_retrieval 配置以及传统的顶层 knowledge_bases 字段中的知识库引用。
api/app/services/app_dsl_service.py

Tips and commands

Interacting with Sourcery

  • 触发新的评审: 在 pull request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的评审评论。
  • 从评审评论生成 GitHub Issue: 回复 Sourcery 的评审评论,请其从该评论创建一个 issue。你也可以在评审评论中回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 pull request 上评论 @sourcery-ai title 以(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文的任意位置写上 @sourcery-ai summary,即可在对应位置生成 PR 摘要。你也可以在 pull request 上评论 @sourcery-ai summary 以在任意时间(重新)生成摘要。
  • 生成评审者指南: 在 pull request 上评论 @sourcery-ai guide,即可在任意时间(重新)生成评审者指南。
  • 解决所有 Sourcery 评论: 在 pull request 上评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会非常有用。
  • 撤销所有 Sourcery 评审: 在 pull request 上评论 @sourcery-ai dismiss,即可撤销所有现有的 Sourcery 评审。如果你想从一个新的评审开始,这尤其有用——别忘了评论 @sourcery-ai review 以触发新的评审!

Customizing Your Experience

访问你的 dashboard 以:

  • 启用或禁用评审功能,例如 Sourcery 自动生成的 pull request 摘要、评审者指南等。
  • 更改评审语言。
  • 添加、删除或编辑自定义评审说明。
  • 调整其他评审设置。

Getting Help

Original review guide in English

Reviewer's Guide

Refactors knowledge base resolution logic into a reusable helper and extends it to Agent nodes, ensuring knowledge base references are validated and cleaned for both Knowledge Retrieval and Agent node configurations.

Flow diagram for knowledge base resolution in KnowledgeRetrieval and Agent nodes

flowchart TD
    A_resolve_nodes[_resolve_workflow_nodes] --> B_check_type{node_type}

    B_check_type -->|KNOWLEDGE_RETRIEVAL| C_kb_node["config.knowledge_bases = _resolve_kb_entries(config.knowledge_bases)"]

    B_check_type -->|AGENT| D_agent["Agent node config"]

    D_agent --> E_nested_kb{knowledge_retrieval.knowledge_bases}
    E_nested_kb -->|present| F_nested["knowledge_retrieval.knowledge_bases = _resolve_kb_entries(knowledge_retrieval.knowledge_bases)"]

    D_agent --> G_legacy_kb{config.knowledge_bases}
    G_legacy_kb -->|present| H_legacy["config.knowledge_bases = _resolve_kb_entries(config.knowledge_bases)"]

    subgraph S[_resolve_kb_entries]
        I_for_each[[for kb in knowledge_bases]] --> J_build_ref[build kb_ref from kb.kb_id]
        J_build_ref --> K_call_resolve["_resolve_kb(kb_ref, workspace_id, empty list)"]
        K_call_resolve --> L_match{resolved_id}
        L_match -->|yes| M_keep[append kb with resolved kb_id]
        L_match -->|no| N_warn[append warning for node_label]
    end
Loading

File-Level Changes

Change Details Files
Extracted reusable knowledge base resolution helper and applied it to workflow nodes that reference knowledge bases.
  • Introduced a private _resolve_kb_entries method that normalizes kb_id inputs, resolves them via _resolve_kb, accumulates resolved entries, and appends warnings for unmatched knowledge bases.
  • Replaced inline knowledge base resolution in KNOWLEDGE_RETRIEVAL nodes with calls to _resolve_kb_entries to reuse the parsing logic.
  • Updated AGENT node handling to clean and resolve knowledge base references in both nested knowledge_retrieval configuration and legacy top-level knowledge_bases fields using _resolve_kb_entries.
api/app/services/app_dsl_service.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗨——我已经Review了你的改动,看起来非常棒!


Sourcery 对开源项目是免费的——如果你觉得我们的 Review 有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进之后的 Review。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions

Copy link
Copy Markdown

API Breaking Change Report

Comparing against release/v0.4.1 baseline.

Breaking change approval label: api-breaking-approved = false.

Tool Result
oasdiff ✅ PASS
openapi-diff ✅ PASS

oasdiff

Output
No breaking changes to report, but the specs are different.
Run 'oasdiff diff' to see structural differences.

openapi-diff

Output
Unable to find image 'openapitools/openapi-diff:2.1.0-beta.11' locally
2.1.0-beta.11: Pulling from openapitools/openapi-diff
4abcf2066143: Pulling fs layer
a21a63612cbe: Pulling fs layer
92d6f603e71e: Pulling fs layer
b8be18af9f33: Pulling fs layer
704a4a6d46b8: Pulling fs layer
ffabcbe5d181: Pulling fs layer
c2a172360f79: Pulling fs layer
6b9cfc1f0b01: Pulling fs layer
397b98d1dbc3: Pulling fs layer
6b9cfc1f0b01: Waiting
ffabcbe5d181: Waiting
c2a172360f79: Waiting
397b98d1dbc3: Waiting
b8be18af9f33: Waiting
704a4a6d46b8: Waiting
4abcf2066143: Download complete
a21a63612cbe: Verifying Checksum
a21a63612cbe: Download complete
4abcf2066143: Pull complete
92d6f603e71e: Verifying Checksum
92d6f603e71e: Download complete
b8be18af9f33: Verifying Checksum
b8be18af9f33: Download complete
704a4a6d46b8: Verifying Checksum
704a4a6d46b8: Download complete
ffabcbe5d181: Verifying Checksum
ffabcbe5d181: Download complete
c2a172360f79: Verifying Checksum
c2a172360f79: Download complete
6b9cfc1f0b01: Verifying Checksum
6b9cfc1f0b01: Download complete
397b98d1dbc3: Verifying Checksum
397b98d1dbc3: Download complete
a21a63612cbe: Pull complete
92d6f603e71e: Pull complete
b8be18af9f33: Pull complete
704a4a6d46b8: Pull complete
ffabcbe5d181: Pull complete
c2a172360f79: Pull complete
6b9cfc1f0b01: Pull complete
397b98d1dbc3: Pull complete
Digest: sha256:6c6b662418e021d13be871dc5a2e8b09936abce02ce05d377caf426663650aa9
Status: Downloaded newer image for openapitools/openapi-diff:2.1.0-beta.11
==========================================================================
==                            API CHANGE LOG                            ==
==========================================================================
                                MemoryBear                                
--------------------------------------------------------------------------
--                              What's New                              --
--------------------------------------------------------------------------
- POST   /v1/memory/merge

--------------------------------------------------------------------------
--                            What's Changed                            --
--------------------------------------------------------------------------
- GET    /v1/app/annotations
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/app/annotations/settings
  Request:
        - Changed application/json
          Schema: Backward compatible
- DELETE /v1/app/annotations/{annotation_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/app/variable
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/app/conversations
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/app/conversations/{conversation_id}/messages
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/app/messages/{message_id}/suggested
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/app/info
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/app/conversations/{conversation_id}/messages/feedbacks
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/knowledges/knowledge_graph_entity_types
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/knowledges/knowledges
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/knowledges/{knowledge_id}/knowledge_graph
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/knowledges/{knowledge_id}/knowledge_graph
  Request:
        - Changed application/json
          Schema: Backward compatible
- DELETE /v1/knowledges/{knowledge_id}/knowledge_graph
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/knowledges/check/yuque/auth
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/knowledges/check/feishu/auth
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/knowledges/{knowledge_id}/sync
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/documents/{kb_id}/documents
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/documents/{document_id}/chunks
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/files/{kb_id}/{parent_id}/files
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/files/folder
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/chunks/{kb_id}/{document_id}/previewchunks
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/chunks/{kb_id}/{document_id}/chunks
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/end_user/mapping
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/end_user/info
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory_config/read_all_config
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory_config/scenes/simple
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory_config/read_config_extracted
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory_config/read_config_forgetting
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory_config/read_config_emotion
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory_config/read_config_reflection
  Request:
        - Changed application/json
          Schema: Backward compatible
- DELETE /v1/memory_config/delete_config
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory/analytics/graph_data
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory/analytics/community_graph
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory/analytics/node_statistics
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory/analytics/user_summary
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory/analytics/memory_insight
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory/analytics/interest_distribution
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory/analytics/end_user_info
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/dashboard/end_users
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory/ontology/scenes/simple
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory/ontology/scenes
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory/ontology/classes
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/app/chat
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/app/workflow/interventions/{execution_id}/submit
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/app/files
  Request:
        - Changed multipart/form-data
          Schema: Backward compatible
- POST   /v1/app/messages/{message_id}/feedback
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/knowledges/knowledge
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/knowledges/{knowledge_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- DELETE /v1/knowledges/{knowledge_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- PUT    /v1/knowledges/{knowledge_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/documents/document
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/documents/{document_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- DELETE /v1/documents/{document_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- PUT    /v1/documents/{document_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/files/file
  Request:
        - Changed multipart/form-data
          Schema: Backward compatible
- POST   /v1/files/customtext
  Request:
        - Changed application/json
          Schema: Backward compatible
- DELETE /v1/files/{file_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- PUT    /v1/files/{file_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/chunks/{kb_id}/{document_id}/chunk
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/chunks/{kb_id}/{document_id}/chunk/batch
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/chunks/{kb_id}/{document_id}/{doc_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- DELETE /v1/chunks/{kb_id}/{document_id}/{doc_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- PUT    /v1/chunks/{kb_id}/{document_id}/{doc_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/chunks/retrieval
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/chunks/{kb_id}/import_qa
  Request:
        - Changed multipart/form-data
          Schema: Backward compatible
- POST   /v1/memory/read/sync
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/memory/read/internal
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/memory/write
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/end_user/create
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/end_user/info/update
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/memory_config/create_config
  Request:
        - Changed application/json
          Schema: Backward compatible
- PUT    /v1/memory_config/update_config
  Request:
        - Changed application/json
          Schema: Backward compatible
- PUT    /v1/memory_config/update_config_extracted
  Request:
        - Changed application/json
          Schema: Backward compatible
- PUT    /v1/memory_config/update_config_forgetting
  Request:
        - Changed application/json
          Schema: Backward compatible
- PUT    /v1/memory_config/update_config_emotion
  Request:
        - Changed application/json
          Schema: Backward compatible
- PUT    /v1/memory_config/update_config_reflection
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/memory/analytics/generate_cache
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/memory/ontology/extract
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/memory/ontology/scene
  Request:
        - Changed application/json
          Schema: Backward compatible
- DELETE /v1/memory/ontology/scene/{scene_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- PUT    /v1/memory/ontology/scene/{scene_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/memory/ontology/class
  Request:
        - Changed application/json
          Schema: Backward compatible
- GET    /v1/memory/ontology/class/{class_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- DELETE /v1/memory/ontology/class/{class_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- PUT    /v1/memory/ontology/class/{class_id}
  Request:
        - Changed application/json
          Schema: Backward compatible
- POST   /v1/memory/ontology/import
  Request:
        - Changed multipart/form-data
          Schema: Backward compatible
- POST   /v1/memory/ontology/export
  Request:
        - Changed application/json
          Schema: Backward compatible
--------------------------------------------------------------------------
--                                Result                                --
--------------------------------------------------------------------------
                   API changes are backward compatible                    
--------------------------------------------------------------------------

Gate decision

No breaking changes detected. The check passed without approval override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant