mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-08 15:22:39 +02:00
refactor(multi-agent): add shared middleware factory per concept
This commit is contained in:
parent
91701bb49a
commit
67036448f9
7 changed files with 96 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
||||||
|
"""Anthropic prompt caching annotations on system/tool/message blocks."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from langchain_anthropic.middleware import AnthropicPromptCachingMiddleware
|
||||||
|
|
||||||
|
|
||||||
|
def build_anthropic_cache_mw() -> AnthropicPromptCachingMiddleware:
|
||||||
|
return AnthropicPromptCachingMiddleware(unsupported_model_behavior="ignore")
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
"""Context-window summarization with SurfSense protected sections."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from deepagents.backends import StateBackend
|
||||||
|
from langchain_core.language_models import BaseChatModel
|
||||||
|
|
||||||
|
from app.agents.new_chat.middleware import create_surfsense_compaction_middleware
|
||||||
|
|
||||||
|
|
||||||
|
def build_compaction_mw(llm: BaseChatModel) -> Any:
|
||||||
|
return create_surfsense_compaction_middleware(llm, StateBackend)
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
"""File-intent classifier that gates strict write contracts."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from langchain_core.language_models import BaseChatModel
|
||||||
|
|
||||||
|
from app.agents.new_chat.middleware import FileIntentMiddleware
|
||||||
|
|
||||||
|
|
||||||
|
def build_file_intent_mw(llm: BaseChatModel) -> FileIntentMiddleware:
|
||||||
|
return FileIntentMiddleware(llm=llm)
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
"""SurfSense filesystem tools/middleware."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from app.agents.new_chat.filesystem_selection import FilesystemMode
|
||||||
|
from app.agents.new_chat.middleware import SurfSenseFilesystemMiddleware
|
||||||
|
|
||||||
|
|
||||||
|
def build_filesystem_mw(
|
||||||
|
*,
|
||||||
|
backend_resolver: Any,
|
||||||
|
filesystem_mode: FilesystemMode,
|
||||||
|
search_space_id: int,
|
||||||
|
user_id: str | None,
|
||||||
|
thread_id: int | None,
|
||||||
|
) -> SurfSenseFilesystemMiddleware:
|
||||||
|
return SurfSenseFilesystemMiddleware(
|
||||||
|
backend=backend_resolver,
|
||||||
|
filesystem_mode=filesystem_mode,
|
||||||
|
search_space_id=search_space_id,
|
||||||
|
created_by_id=user_id,
|
||||||
|
thread_id=thread_id,
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
"""User/team memory injection prepended to the conversation."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from app.agents.new_chat.middleware import MemoryInjectionMiddleware
|
||||||
|
from app.db import ChatVisibility
|
||||||
|
|
||||||
|
|
||||||
|
def build_memory_mw(
|
||||||
|
*,
|
||||||
|
user_id: str | None,
|
||||||
|
search_space_id: int,
|
||||||
|
visibility: ChatVisibility,
|
||||||
|
) -> MemoryInjectionMiddleware:
|
||||||
|
return MemoryInjectionMiddleware(
|
||||||
|
user_id=user_id,
|
||||||
|
search_space_id=search_space_id,
|
||||||
|
thread_visibility=visibility,
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
"""Repair dangling tool-call sequences before each agent turn."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from deepagents.middleware.patch_tool_calls import PatchToolCallsMiddleware
|
||||||
|
|
||||||
|
|
||||||
|
def build_patch_tool_calls_mw() -> PatchToolCallsMiddleware:
|
||||||
|
return PatchToolCallsMiddleware()
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
"""Todo-list middleware (each consumer needs its own instance)."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from langchain.agents.middleware import TodoListMiddleware
|
||||||
|
|
||||||
|
|
||||||
|
def build_todos_mw() -> TodoListMiddleware:
|
||||||
|
return TodoListMiddleware()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue