Skip to content

feat: new file based agent#1029

Merged
MODSetter merged 2 commits intodevfrom
dev_mod
Mar 28, 2026
Merged

feat: new file based agent#1029
MODSetter merged 2 commits intodevfrom
dev_mod

Conversation

@MODSetter
Copy link
Copy Markdown
Owner

@MODSetter MODSetter commented Mar 28, 2026

Description

Motivation and Context

FIX #

Screenshots

API Changes

  • This PR includes API changes

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation
  • Dependency/Build system
  • Breaking change
  • Other (specify):

Testing Performed

  • Tested locally
  • Manual/QA verification

Checklist

  • Follows project coding standards and conventions
  • Documentation updated as needed
  • Dependencies updated as needed
  • No lint/build errors or new warnings
  • All relevant tests are passing

High-level PR Summary

This PR introduces a new file-based agent architecture for SurfSense chat, replacing the previous tool-based knowledge search with a pre-seeded filesystem middleware approach. The agent now automatically loads relevant documents into a virtual /documents/ filesystem at the start of each conversation turn using hybrid search, then uses file operations (ls, read_file, grep, glob) instead of calling search_knowledge_base directly. Major changes include: removing the Daytona sandbox backend and execute tool; implementing KnowledgeBaseSearchMiddleware that pre-populates a filesystem with search results formatted as XML with citation-friendly chunk indexes; adding SurfSenseFilesystemMiddleware with a save_document tool that persists new documents to the database; upgrading to deepagents>=0.4.12 and manually constructing the middleware stack (switching from create_deep_agent to create_agent for full control); overhauling system prompts to instruct the LLM to read files efficiently using line offsets and chunk indexes; optimizing hybrid search retrievers with SQL-level per-document chunk limits and column pruning; implementing placeholder document creation for instant UI feedback during connector indexing; adding frontend support for bulk folder selection/deletion and real-time document creation events; and removing the search_knowledge_base tool entirely from the agent's toolset.

⏱️ Estimated Review Time: 1-3 hours

💡 Review Order Suggestion
Order File Path
1 surfsense_backend/pyproject.toml
2 surfsense_backend/app/agents/new_chat/middleware/__init__.py
3 surfsense_backend/app/agents/new_chat/middleware/filesystem.py
4 surfsense_backend/app/agents/new_chat/middleware/knowledge_search.py
5 surfsense_backend/app/agents/new_chat/chat_deepagent.py
6 surfsense_backend/app/agents/new_chat/system_prompt.py
7 surfsense_backend/app/agents/new_chat/__init__.py
8 surfsense_backend/app/agents/new_chat/tools/__init__.py
9 surfsense_backend/app/agents/new_chat/tools/knowledge_base.py
10 surfsense_backend/app/agents/new_chat/tools/registry.py
11 surfsense_backend/app/tasks/chat/stream_new_chat.py
12 surfsense_backend/app/indexing_pipeline/indexing_pipeline_service.py
13 surfsense_backend/app/retriever/chunks_hybrid_search.py
14 surfsense_backend/app/retriever/documents_hybrid_search.py
15 surfsense_backend/.env.example
16 surfsense_backend/app/routes/editor_routes.py
17 surfsense_backend/app/routes/search_source_connectors_routes.py
18 surfsense_backend/app/tasks/connector_indexers/google_drive_indexer.py
19 surfsense_backend/app/tasks/connector_indexers/confluence_indexer.py
20 surfsense_backend/app/tasks/connector_indexers/google_gmail_indexer.py
21 surfsense_backend/app/tasks/connector_indexers/google_calendar_indexer.py
22 surfsense_backend/app/tasks/connector_indexers/jira_indexer.py
23 surfsense_backend/app/tasks/connector_indexers/linear_indexer.py
24 surfsense_backend/app/tasks/connector_indexers/notion_indexer.py
25 surfsense_web/atoms/documents/ui.atoms.ts
26 surfsense_web/components/assistant-ui/thread.tsx
27 surfsense_web/components/layout/ui/sidebar/DocumentsSidebar.tsx
28 surfsense_web/components/documents/FolderTreeView.tsx
29 surfsense_web/components/documents/FolderNode.tsx
30 surfsense_web/components/documents/DocumentNode.tsx
31 surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx
32 surfsense_backend/tests/unit/middleware/test_knowledge_search.py
33 surfsense_backend/tests/unit/indexing_pipeline/test_create_placeholder_documents.py
34 surfsense_backend/tests/unit/indexing_pipeline/test_prepare_placeholder_dedup.py
35 surfsense_backend/tests/integration/retriever/test_optimized_chunk_retriever.py
36 surfsense_backend/tests/integration/retriever/test_optimized_doc_retriever.py

Need help? Join our Discord

Analyze latest changes

- Updated DocumentNode to use a div instead of a button for better accessibility and added keyboard interaction for selection.
- Introduced Checkbox component in FolderNode for selecting folders, with state management for selection (all, some, none).
- Implemented folder selection state logic in FolderTreeView to manage document selection across nested folders.
- Added handleToggleFolderSelect function in DocumentsSidebar to manage selection of documents based on folder selection.
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
surf-sense-frontend Ready Ready Preview, Comment Mar 29, 2026 9:54am

Request Review

@MODSetter MODSetter merged commit ba283bd into dev Mar 28, 2026
8 checks passed
Copy link
Copy Markdown

@recurseml recurseml bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by RecurseML

🔍 Review performed on 947def5..2cc2d33

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (49)

surfsense_backend/.env.example
surfsense_backend/app/agents/new_chat/__init__.py
surfsense_backend/app/agents/new_chat/chat_deepagent.py
surfsense_backend/app/agents/new_chat/middleware/__init__.py
surfsense_backend/app/agents/new_chat/middleware/knowledge_search.py
surfsense_backend/app/agents/new_chat/system_prompt.py
surfsense_backend/app/agents/new_chat/tools/__init__.py
surfsense_backend/app/agents/new_chat/tools/google_calendar/update_event.py
surfsense_backend/app/agents/new_chat/tools/knowledge_base.py
surfsense_backend/app/agents/new_chat/tools/registry.py
surfsense_backend/app/agents/new_chat/tools/report.py
surfsense_backend/app/connectors/google_drive/change_tracker.py
surfsense_backend/app/connectors/google_drive/client.py
surfsense_backend/app/connectors/google_drive/content_extractor.py
surfsense_backend/app/indexing_pipeline/document_hashing.py
surfsense_backend/app/indexing_pipeline/indexing_pipeline_service.py
surfsense_backend/app/retriever/chunks_hybrid_search.py
surfsense_backend/app/retriever/documents_hybrid_search.py
surfsense_backend/app/routes/editor_routes.py
surfsense_backend/app/routes/search_source_connectors_routes.py
surfsense_backend/app/tasks/chat/stream_new_chat.py
surfsense_backend/app/tasks/connector_indexers/confluence_indexer.py
surfsense_backend/app/tasks/connector_indexers/google_calendar_indexer.py
surfsense_backend/app/tasks/connector_indexers/google_drive_indexer.py
surfsense_backend/app/tasks/connector_indexers/google_gmail_indexer.py
surfsense_backend/app/tasks/connector_indexers/jira_indexer.py
surfsense_backend/app/tasks/connector_indexers/linear_indexer.py
surfsense_backend/app/tasks/connector_indexers/notion_indexer.py
surfsense_backend/pyproject.toml
surfsense_backend/tests/integration/indexing_pipeline/test_calendar_pipeline.py
surfsense_backend/tests/integration/indexing_pipeline/test_drive_pipeline.py
surfsense_backend/tests/integration/indexing_pipeline/test_gmail_pipeline.py
surfsense_backend/tests/integration/indexing_pipeline/test_index_batch.py
surfsense_backend/tests/integration/retriever/conftest.py
surfsense_backend/tests/integration/retriever/test_optimized_chunk_retriever.py
surfsense_backend/tests/integration/retriever/test_optimized_doc_retriever.py
surfsense_backend/tests/unit/connector_indexers/test_confluence_parallel.py
surfsense_backend/tests/unit/connector_indexers/test_google_drive_parallel.py
surfsense_backend/tests/unit/connector_indexers/test_jira_parallel.py
surfsense_backend/tests/unit/connector_indexers/test_linear_parallel.py
surfsense_backend/tests/unit/connector_indexers/test_notion_parallel.py
surfsense_backend/tests/unit/indexing_pipeline/test_create_placeholder_documents.py
surfsense_backend/tests/unit/indexing_pipeline/test_index_batch.py
surfsense_backend/tests/unit/indexing_pipeline/test_index_batch_parallel.py
surfsense_backend/tests/unit/indexing_pipeline/test_prepare_placeholder_dedup.py
surfsense_backend/tests/unit/middleware/test_knowledge_search.py
surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx
surfsense_web/app/dashboard/[search_space_id]/new-chat/loading.tsx
surfsense_web/atoms/documents/ui.atoms.ts

⏭️ Files skipped (16)
  Locations  
surfsense_backend/tests/integration/retriever/__init__.py
surfsense_backend/uv.lock
surfsense_web/components/assistant-ui/connector-popup.tsx
surfsense_web/components/assistant-ui/markdown-text.tsx
surfsense_web/components/assistant-ui/thread.tsx
surfsense_web/components/documents/CreateFolderDialog.tsx
surfsense_web/components/documents/DocumentNode.tsx
surfsense_web/components/documents/FolderNode.tsx
surfsense_web/components/documents/FolderTreeView.tsx
surfsense_web/components/layout/ui/sidebar/DocumentsSidebar.tsx
surfsense_web/components/onboarding-tour.tsx
surfsense_web/components/report-panel/report-panel.tsx
surfsense_web/components/shared/ExportMenuItems.tsx
surfsense_web/components/tool-ui/google-calendar/update-event.tsx
surfsense_web/contracts/enums/toolIcons.tsx
surfsense_web/hooks/use-zero-document-type-counts.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant