♻️ refactor(core): 重构 AI 编排框架与记忆及 RAG 子系统 (#2149)

* ♻️ refactor(core): 重构 AI 编排框架与记忆及 RAG 子系统

- 【重构】重构 `BaseRunnable` 并引入统一的 `RunIntent` 意图载体,规范 Agent、Team 和 Workflow 的执行流
- 【解耦】将中期记忆槽和长期向量记忆从 `MemoryConfig` 中解耦,转为独立的能力组件与工具箱进行管理
- 【记忆】移除 `MemoryReader` 和 `MemoryWriter`,统一封装为 `SessionMemoryContext` 会话记忆门面
- 【RAG】重构检索器与存储后端接口,统一采用 `QueryRequest` 进行多维度联合检索,并引入 `InMemoryScorer` 提升打分性能
- 【事件】优化 `EventBus` 异步事件分发机制,引入队列机制确保事件按序处理,避免并发竞态问题
- 【依赖注入】移除 `memory` 注入项,优化 `DependencyInjector` 的签名解析缓存以提升性能

* 🚨 auto fix by pre-commit hooks

---------

Co-authored-by: webjoin111 <455457521@qq.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Rumio
2026-07-14 16:48:33 +08:00
committed by GitHub
co-authored by webjoin111 pre-commit-ci[bot]
parent 922d092650
commit 52f7dbdedf
66 changed files with 2131 additions and 2353 deletions
+61 -1
View File
@@ -60,7 +60,7 @@ class ContextUtils:
context: Any, scope: Any, default_session_id: str
) -> str:
"""根据并发隔离范围 scope 动态计算并返回当前会话的并发锁 ID"""
from zhenxun.services.ai.flow.base import ConcurrencyScope
from zhenxun.services.ai.flow.core.models import ConcurrencyScope
scope = scope or ConcurrencyScope.GROUP
@@ -135,6 +135,66 @@ class ContextUtils:
isolation_level=scope_builder,
)
@staticmethod
def build_session_meta(
context: Any,
target_builder: Any | None = None,
extra_scopes: dict[str, Any] | None = None,
custom_namespace: str | None = None,
) -> Any:
"""基于 RunContext 动态提取并生成 SessionMetadata"""
from zhenxun.services.ai.context.memory.types import Isolation, SessionMetadata
ns = custom_namespace or getattr(
getattr(context, "session", None), "namespace", "global"
)
agent_name = getattr(getattr(context, "run", None), "agent_name", None)
deps = getattr(context, "deps", None)
if target_builder is None:
target_builder = Isolation.AGENT_USER()
selector = target_builder.resolve(
deps=deps,
prefix="",
default_namespace=ns,
default_agent=agent_name,
)
all_scopes = {"/"}
parts = selector.get_scope_parts()
current_path = ""
for part in parts:
current_path += f"/{part}"
all_scopes.add(current_path)
scope_name_mapping = {}
if extra_scopes:
for name, builder in extra_scopes.items():
sel = builder.resolve(
deps=deps, prefix="", default_namespace=ns, default_agent=agent_name
)
all_scopes.add(sel.scope_prefix)
scope_name_mapping[sel.scope_prefix] = name
accessible_scopes = list(all_scopes)
accessible_scopes.sort(key=lambda x: len(x.split("/")))
session_id = (
getattr(context, "session_id", None)
or getattr(getattr(context, "session", None), "session_id", None)
or selector.scope_prefix
)
return SessionMetadata(
session_id=session_id,
selector=selector,
scope_prefix=selector.scope_prefix,
accessible_scopes=accessible_scopes,
scope_name_mapping=scope_name_mapping,
isolation_level=target_builder,
)
class PermissionUtils:
"""运行时权限校验通用工具类"""