mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-06 20:15:17 +02:00
refactor(agents): move MAC graph-state schema into multi_agent_chat/shared/state/
filesystem_state.py (the multi-agent graph state) and state_reducers.py (its merge reducers) are consumed only by multi_agent_chat (filesystem tools/middleware, kb projection, and the MAC-only shared middleware) plus two unit tests -- no external app code. Relocate them into a dedicated multi_agent_chat/shared/state/ package (filesystem_state.py + reducers.py) and repoint every importer. No behavior change; import-all + the full unit/middleware + unit/agents suites (1066 tests) stay green.
This commit is contained in:
parent
2db4ad479e
commit
1d2519730e
30 changed files with 82 additions and 34 deletions
|
|
@ -7,8 +7,10 @@ from typing import Any
|
|||
from deepagents import FilesystemMiddleware
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.filesystem_selection import FilesystemMode
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.shared.sandbox import is_sandbox_enabled
|
||||
|
||||
from ..system_prompt import build_system_prompt
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ from typing import TYPE_CHECKING
|
|||
|
||||
from langchain.tools import ToolRuntime
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.path_resolver import DOCUMENTS_ROOT
|
||||
|
||||
from ..shared.paths import TEMP_PREFIX, basename
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ from typing import TYPE_CHECKING
|
|||
|
||||
from langchain.tools import ToolRuntime
|
||||
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.filesystem_selection import FilesystemMode
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.shared.middleware.multi_root_local_folder_backend import (
|
||||
MultiRootLocalFolderBackend,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ from langchain_core.messages import ToolMessage
|
|||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.path_resolver import DOCUMENTS_ROOT
|
||||
|
||||
from ...middleware.async_dispatch import run_async_blocking
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ from langchain_core.messages import ToolMessage
|
|||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.middleware.kb_postgres_backend import KBPostgresBackend
|
||||
|
||||
from ...middleware.async_dispatch import run_async_blocking
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ from typing import TYPE_CHECKING
|
|||
from daytona.common.errors import DaytonaError
|
||||
from langchain.tools import ToolRuntime
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.sandbox import (
|
||||
_evict_sandbox_cache,
|
||||
delete_sandbox,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ from typing import TYPE_CHECKING, Annotated
|
|||
from langchain.tools import ToolRuntime
|
||||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
|
||||
from ...middleware.async_dispatch import run_async_blocking
|
||||
from .description import select_description
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ from deepagents.backends.utils import validate_path
|
|||
from langchain.tools import ToolRuntime
|
||||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.middleware.kb_postgres_backend import KBPostgresBackend
|
||||
|
||||
from ...middleware.async_dispatch import run_async_blocking
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ from deepagents.backends.utils import validate_path
|
|||
from langchain.tools import ToolRuntime
|
||||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.middleware.kb_postgres_backend import paginate_listing
|
||||
|
||||
from ...middleware.async_dispatch import run_async_blocking
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ from langchain_core.messages import ToolMessage
|
|||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.path_resolver import DOCUMENTS_ROOT
|
||||
|
||||
from ...middleware.async_dispatch import run_async_blocking
|
||||
|
|
|
|||
|
|
@ -8,10 +8,12 @@ from langchain.tools import ToolRuntime
|
|||
from langchain_core.messages import ToolMessage
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.multi_agent_chat.shared.state.reducers import _CLEAR
|
||||
from app.agents.shared.middleware.kb_postgres_backend import KBPostgresBackend
|
||||
from app.agents.shared.path_resolver import DOCUMENTS_ROOT
|
||||
from app.agents.shared.state_reducers import _CLEAR
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ...middleware import SurfSenseFilesystemMiddleware
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ from langchain_core.messages import ToolMessage
|
|||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
|
||||
from ...middleware.async_dispatch import run_async_blocking
|
||||
from ...middleware.mode import is_cloud
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ from typing import TYPE_CHECKING
|
|||
from langchain.tools import ToolRuntime
|
||||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
|
||||
from ...middleware.path_resolution import current_cwd
|
||||
from .description import select_description
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ from langchain_core.messages import ToolMessage
|
|||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.middleware.kb_postgres_backend import KBPostgresBackend
|
||||
|
||||
from ...middleware.async_dispatch import run_async_blocking
|
||||
|
|
|
|||
|
|
@ -12,10 +12,12 @@ from langchain.tools import ToolRuntime
|
|||
from langchain_core.messages import ToolMessage
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.multi_agent_chat.shared.state.reducers import _CLEAR
|
||||
from app.agents.shared.middleware.kb_postgres_backend import KBPostgresBackend
|
||||
from app.agents.shared.path_resolver import DOCUMENTS_ROOT
|
||||
from app.agents.shared.state_reducers import _CLEAR
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ...middleware import SurfSenseFilesystemMiddleware
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ from langchain.tools import ToolRuntime
|
|||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
|
||||
from ...middleware.async_dispatch import run_async_blocking
|
||||
from ...middleware.mode import is_cloud
|
||||
|
|
|
|||
|
|
@ -13,10 +13,12 @@ from langchain.tools import ToolRuntime
|
|||
from langchain_core.messages import ToolMessage
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.multi_agent_chat.shared.state.reducers import _CLEAR
|
||||
from app.agents.shared.middleware.kb_postgres_backend import KBPostgresBackend
|
||||
from app.agents.shared.path_resolver import DOCUMENTS_ROOT
|
||||
from app.agents.shared.state_reducers import _CLEAR
|
||||
|
||||
from ...middleware.path_resolution import current_cwd
|
||||
from ...shared.paths import is_ancestor_of
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ from langchain.tools import ToolRuntime
|
|||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
|
||||
from ...middleware.async_dispatch import run_async_blocking
|
||||
from ...middleware.mode import is_cloud
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ from langchain_core.messages import ToolMessage
|
|||
from langchain_core.tools import BaseTool, StructuredTool
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
|
||||
from ...middleware.async_dispatch import run_async_blocking
|
||||
from ...middleware.mode import is_cloud
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ from langchain.agents.middleware import AgentMiddleware, AgentState
|
|||
from langchain_core.messages import SystemMessage
|
||||
from langgraph.runtime import Runtime
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.middleware.knowledge_search import _render_priority_message
|
||||
from app.utils.perf import get_perf_logger
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ extra fields needed to implement Postgres-backed virtual filesystem semantics:
|
|||
* ``workspace_tree_text`` — pre-rendered ``<workspace_tree>`` body for the turn.
|
||||
|
||||
Tools mutate these fields ONLY via ``Command(update=...)`` returns; the
|
||||
reducers in :mod:`app.agents.shared.state_reducers` handle merging.
|
||||
reducers in :mod:`app.agents.multi_agent_chat.shared.state.reducers` handle merging.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
|
@ -30,7 +30,7 @@ from typing import Annotated, Any, NotRequired
|
|||
from deepagents.middleware.filesystem import FilesystemState
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from app.agents.shared.state_reducers import (
|
||||
from app.agents.multi_agent_chat.shared.state.reducers import (
|
||||
_add_unique_reducer,
|
||||
_dict_merge_with_tombstones_reducer,
|
||||
_int_counter_merge_reducer,
|
||||
|
|
@ -24,7 +24,9 @@ from typing import Any
|
|||
from langchain.agents.middleware import AgentMiddleware, AgentState
|
||||
from langgraph.runtime import Runtime
|
||||
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.path_resolver import DOCUMENTS_ROOT, safe_filename
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
|
|||
|
|
@ -45,16 +45,18 @@ from sqlalchemy import delete, select, update
|
|||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.multi_agent_chat.shared.state.reducers import _CLEAR
|
||||
from app.agents.shared.feature_flags import get_flags
|
||||
from app.agents.shared.filesystem_selection import FilesystemMode
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.shared.path_resolver import (
|
||||
DOCUMENTS_ROOT,
|
||||
parse_documents_path,
|
||||
safe_folder_segment,
|
||||
virtual_path_to_doc,
|
||||
)
|
||||
from app.agents.shared.state_reducers import _CLEAR
|
||||
from app.agents.shared.receipt import Receipt, make_receipt
|
||||
from app.db import (
|
||||
AgentActionLog,
|
||||
|
|
|
|||
|
|
@ -45,9 +45,11 @@ from app.agents.multi_agent_chat.shared.date_filters import (
|
|||
parse_date_or_datetime,
|
||||
resolve_date_range,
|
||||
)
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.feature_flags import get_flags
|
||||
from app.agents.shared.filesystem_selection import FilesystemMode
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.shared.path_resolver import (
|
||||
PathIndex,
|
||||
build_path_index,
|
||||
|
|
|
|||
|
|
@ -33,8 +33,10 @@ from langchain_core.messages import SystemMessage
|
|||
from langgraph.runtime import Runtime
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.agents.multi_agent_chat.shared.state.filesystem_state import (
|
||||
SurfSenseFilesystemState,
|
||||
)
|
||||
from app.agents.shared.filesystem_selection import FilesystemMode
|
||||
from app.agents.shared.filesystem_state import SurfSenseFilesystemState
|
||||
from app.agents.shared.path_resolver import (
|
||||
DOCUMENTS_ROOT,
|
||||
PathIndex,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ participate in the verification teaching from
|
|||
``multi_agent_chat/subagents/shared/snippets/verifiable_handle.md`` those
|
||||
tools now also need to write a :class:`Receipt` into the parent's
|
||||
``state['receipts']`` list (declared on
|
||||
:class:`~app.agents.shared.filesystem_state.SurfSenseFilesystemState`
|
||||
:class:`~app.agents.multi_agent_chat.shared.state.filesystem_state.SurfSenseFilesystemState`
|
||||
and backed by the append reducer).
|
||||
|
||||
:func:`with_receipt` wraps both behaviours: it returns the tool payload as
|
||||
|
|
@ -51,7 +51,7 @@ def with_receipt(
|
|||
"""Return a Command that ships ``payload`` as a ToolMessage AND appends ``receipt``.
|
||||
|
||||
The append happens via the ``_list_append_reducer`` on the ``receipts``
|
||||
field of :class:`~app.agents.shared.filesystem_state.SurfSenseFilesystemState`,
|
||||
field of :class:`~app.agents.multi_agent_chat.shared.state.filesystem_state.SurfSenseFilesystemState`,
|
||||
so concurrent subagent batches (item 4 in the plan) won't clobber each
|
||||
other's receipts.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||
|
||||
import pytest
|
||||
|
||||
from app.agents.shared.state_reducers import (
|
||||
from app.agents.multi_agent_chat.shared.state.reducers import (
|
||||
_CLEAR,
|
||||
_add_unique_reducer,
|
||||
_dict_merge_with_tombstones_reducer,
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@ import pytest
|
|||
from app.agents.multi_agent_chat.shared.middleware.filesystem import (
|
||||
build_filesystem_mw,
|
||||
)
|
||||
from app.agents.multi_agent_chat.shared.state.reducers import _CLEAR
|
||||
from app.agents.shared.filesystem_backends import build_backend_resolver
|
||||
from app.agents.shared.filesystem_selection import FilesystemMode, FilesystemSelection
|
||||
from app.agents.shared.middleware.kb_postgres_backend import KBPostgresBackend
|
||||
from app.agents.shared.state_reducers import _CLEAR
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue