diff --git a/surfsense_backend/app/agents/new_chat/middleware/memory_injection.py b/surfsense_backend/app/agents/new_chat/middleware/memory_injection.py index cd09e6b45..137a71edf 100644 --- a/surfsense_backend/app/agents/new_chat/middleware/memory_injection.py +++ b/surfsense_backend/app/agents/new_chat/middleware/memory_injection.py @@ -111,7 +111,9 @@ class MemoryInjectionMiddleware(AgentMiddleware): # type: ignore[type-arg] return {"messages": new_messages} - async def _load_user_memory(self, session: AsyncSession) -> tuple[str | None, str | None]: + async def _load_user_memory( + self, session: AsyncSession + ) -> tuple[str | None, str | None]: """Return (memory_content, display_name).""" try: result = await session.execute( diff --git a/surfsense_backend/app/agents/new_chat/tools/update_memory.py b/surfsense_backend/app/agents/new_chat/tools/update_memory.py index b487fb4a0..e8eb967fa 100644 --- a/surfsense_backend/app/agents/new_chat/tools/update_memory.py +++ b/surfsense_backend/app/agents/new_chat/tools/update_memory.py @@ -134,7 +134,9 @@ async def _forced_rewrite(content: str, llm: Any) -> str | None: Returns the rewritten string, or ``None`` if the call fails. """ try: - prompt = _FORCED_REWRITE_PROMPT.format(target=MEMORY_HARD_LIMIT, content=content) + prompt = _FORCED_REWRITE_PROMPT.format( + target=MEMORY_HARD_LIMIT, content=content + ) response = await llm.ainvoke( [HumanMessage(content=prompt)], config={"tags": ["surfsense:internal"]}, diff --git a/surfsense_backend/app/routes/search_spaces_routes.py b/surfsense_backend/app/routes/search_spaces_routes.py index e66fc5f0c..d29315c80 100644 --- a/surfsense_backend/app/routes/search_spaces_routes.py +++ b/surfsense_backend/app/routes/search_spaces_routes.py @@ -359,9 +359,7 @@ async def edit_team_memory( ).strip() except Exception as e: logger.exception("Team memory edit LLM call failed: %s", e) - raise HTTPException( - status_code=500, detail="Team memory edit failed." - ) from e + raise HTTPException(status_code=500, detail="Team memory edit failed.") from e if not updated: raise HTTPException(status_code=400, detail="LLM returned empty result.") @@ -370,9 +368,7 @@ async def edit_team_memory( updated_memory=updated, old_memory=current_memory, llm=llm, - apply_fn=lambda content: setattr( - db_search_space, "shared_memory_md", content - ), + apply_fn=lambda content: setattr(db_search_space, "shared_memory_md", content), commit_fn=session.commit, rollback_fn=session.rollback, label="team memory", diff --git a/surfsense_backend/app/tasks/chat/stream_new_chat.py b/surfsense_backend/app/tasks/chat/stream_new_chat.py index e12d189ac..3c7b9af7e 100644 --- a/surfsense_backend/app/tasks/chat/stream_new_chat.py +++ b/surfsense_backend/app/tasks/chat/stream_new_chat.py @@ -30,7 +30,6 @@ from sqlalchemy.orm import selectinload from app.agents.new_chat.chat_deepagent import create_surfsense_deep_agent from app.agents.new_chat.checkpointer import get_checkpointer -from app.agents.new_chat.memory_extraction import extract_and_save_memory from app.agents.new_chat.llm_config import ( AgentConfig, create_chat_litellm_from_agent_config, @@ -38,6 +37,7 @@ from app.agents.new_chat.llm_config import ( load_agent_config, load_llm_config_from_yaml, ) +from app.agents.new_chat.memory_extraction import extract_and_save_memory from app.db import ( ChatVisibility, NewChatMessage, diff --git a/surfsense_web/app/dashboard/[search_space_id]/user-settings/components/MemoryContent.tsx b/surfsense_web/app/dashboard/[search_space_id]/user-settings/components/MemoryContent.tsx index 4d1274282..dae79afd1 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/user-settings/components/MemoryContent.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/user-settings/components/MemoryContent.tsx @@ -106,9 +106,7 @@ export function MemoryContent() { if (!memory) { return (
Nothing yet. SurfSense picks up on your preferences and context as you chat.
diff --git a/surfsense_web/components/settings/team-memory-manager.tsx b/surfsense_web/components/settings/team-memory-manager.tsx index 01cb7bbdb..4c5d619e8 100644 --- a/surfsense_web/components/settings/team-memory-manager.tsx +++ b/surfsense_web/components/settings/team-memory-manager.tsx @@ -18,9 +18,11 @@ import { cacheKeys } from "@/lib/query-client/cache-keys"; const MEMORY_HARD_LIMIT = 25_000; -const SearchSpaceSchema = z.object({ - shared_memory_md: z.string().optional().default(""), -}).passthrough(); +const SearchSpaceSchema = z + .object({ + shared_memory_md: z.string().optional().default(""), + }) + .passthrough(); interface TeamMemoryManagerProps { searchSpaceId: number; @@ -67,7 +69,7 @@ export function TeamMemoryManager({ searchSpaceId }: TeamMemoryManagerProps) { await baseApiService.post( `/api/v1/searchspaces/${searchSpaceId}/memory/edit`, SearchSpaceSchema, - { body: { query } }, + { body: { query } } ); setEditQuery(""); await queryClient.invalidateQueries({