禁用了知识库技能,添加了知识库memory
This commit is contained in:
1 parent
273503ddb9
commit
9e14c2e289
13 files changed
+588
-27
No files matched your search
+4
-1
@@ -227,7 +227,10 @@ class BuiltinFileProvider(MemoryProvider):
|
||||
保持系统提示词稳定,利于 prefix cache。
|
||||
"""
|
||||
blocks = [b for b in (self._snapshot.get("user"), self._snapshot.get("memory")) if b]
|
||||
return "\n\n".join(blocks)
|
||||
content = "\n\n".join(blocks)
|
||||
if not content:
|
||||
return ""
|
||||
return f"<memory>\n{content}\n</memory>"
|
||||
|
||||
def get_tool_schemas(self) -> list[dict[str, Any]]:
|
||||
"""builtin 的 ``memory`` 工具以 LangChain BaseTool 形式独立注册,
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
"""Read-only provider for the mounted policy knowledge base.
|
||||
|
||||
This provider keeps the current knowledge-base behaviour: inject the lightweight
|
||||
``routing.md`` guide and let the model decide when to read concrete files. It
|
||||
does not automatically retrieve snippets and never writes to the knowledge base.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from deerflow.agents.memory.provider import MemoryProvider
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@lru_cache(maxsize=16)
|
||||
def _read_routing_file(host_path: str) -> str:
|
||||
path = Path(host_path)
|
||||
if not path.is_file():
|
||||
return ""
|
||||
return path.read_text(encoding="utf-8").strip()
|
||||
|
||||
|
||||
class KnowledgeProvider(MemoryProvider):
|
||||
"""Injects the knowledge routing guide as a read-only context provider."""
|
||||
|
||||
def __init__(self, *, app_config: Any | None = None) -> None:
|
||||
self._app_config = app_config
|
||||
self._routing_host_path: Path | None = None
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return "knowledge"
|
||||
|
||||
def is_available(self) -> bool:
|
||||
return True
|
||||
|
||||
def initialize(
|
||||
self,
|
||||
*,
|
||||
user_id: str,
|
||||
agent_id: str | None = None,
|
||||
thread_id: str | None = None,
|
||||
base_dir: str,
|
||||
**kwargs: Any,
|
||||
) -> None:
|
||||
app_config = self._app_config or kwargs.get("app_config")
|
||||
if app_config is None:
|
||||
from deerflow.config import get_app_config
|
||||
|
||||
app_config = get_app_config()
|
||||
|
||||
self._routing_host_path = None
|
||||
for mount in app_config.sandbox.mounts or []:
|
||||
if mount.container_path.rstrip("/") == "/mnt/knowledge":
|
||||
self._routing_host_path = Path(mount.host_path) / "routing.md"
|
||||
break
|
||||
|
||||
def system_prompt_block(self) -> str:
|
||||
if self._routing_host_path is None:
|
||||
return ""
|
||||
|
||||
content = _read_routing_file(str(self._routing_host_path.resolve()))
|
||||
if not content:
|
||||
return ""
|
||||
|
||||
logger.debug("Injected knowledge routing memory from %s", self._routing_host_path)
|
||||
return f"""<knowledge_routing_memory source="/mnt/knowledge/routing.md">
|
||||
{content}
|
||||
</knowledge_routing_memory>"""
|
||||
|
||||
def prefetch(self, query: str, *, thread_id: str = "") -> str:
|
||||
return ""
|
||||
|
||||
def sync_turn(
|
||||
self,
|
||||
user_content: str,
|
||||
assistant_content: str,
|
||||
*,
|
||||
thread_id: str = "",
|
||||
turn_index: int | None = None,
|
||||
) -> None:
|
||||
return None
|
||||
|
||||
def get_tool_schemas(self) -> list[dict[str, Any]]:
|
||||
return []
|
||||
|
||||
|
||||
__all__ = ["KnowledgeProvider"]
|
||||
Reference in new issue
Block a user