backends.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """虚拟文件系统 Backend(存储后端)配置。"""
  2. from __future__ import annotations
  3. from pathlib import Path
  4. from deepagents import FilesystemPermission
  5. from deepagents.backends import (
  6. CompositeBackend,
  7. FilesystemBackend,
  8. StateBackend,
  9. StoreBackend,
  10. )
  11. def build_backend(project_root: Path, namespace: tuple[str, ...]) -> CompositeBackend:
  12. """按路径划分真实文件、线程文件和长期记忆。"""
  13. return CompositeBackend(
  14. default=FilesystemBackend(
  15. root_dir=str(project_root.resolve()),
  16. virtual_mode=True,
  17. ),
  18. routes={
  19. "/workspace/": StateBackend(),
  20. "/memories/": StoreBackend(namespace=lambda _runtime: namespace),
  21. },
  22. )
  23. def build_permissions() -> list[FilesystemPermission]:
  24. """保护原始资料、组织政策和 Skill,允许写报告与临时文件。"""
  25. return [
  26. FilesystemPermission(
  27. operations=["write"],
  28. paths=["/data-room/**", "/policies/**", "/skills/**"],
  29. mode="deny",
  30. )
  31. ]