Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 0 additions & 118 deletions surfsense_backend/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions surfsense_backend/app/agents/researcher/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,16 @@ class SearchMode(Enum):
DOCUMENTS = "DOCUMENTS"


class ResearchMode(Enum):
"""Enum defining the type of research mode."""

QNA = "QNA"
REPORT_GENERAL = "REPORT_GENERAL"
REPORT_DEEP = "REPORT_DEEP"
REPORT_DEEPER = "REPORT_DEEPER"


@dataclass(kw_only=True)
class Configuration:
"""The configuration for the agent."""

# Input parameters provided at invocation
user_query: str
num_sections: int
connectors_to_search: list[str]
user_id: str
search_space_id: int
search_mode: SearchMode
research_mode: ResearchMode
document_ids_to_add_in_context: list[int]
language: str | None = None

Expand Down
55 changes: 8 additions & 47 deletions surfsense_backend/app/agents/researcher/graph.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
from typing import Any, TypedDict

from langgraph.graph import StateGraph

from .configuration import Configuration, ResearchMode
from .configuration import Configuration
from .nodes import (
generate_further_questions,
handle_qna_workflow,
process_sections,
reformulate_user_query,
write_answer_outline,
)
from .state import State


# Define what keys are in our state dict
class GraphState(TypedDict):
# Intermediate data produced during workflow
answer_outline: Any | None
# Final output
final_written_report: str | None


def build_graph():
"""
Build and return the LangGraph workflow.

This function constructs the researcher agent graph with conditional routing
based on research_mode - QNA mode uses a direct Q&A workflow while other modes
use the full report generation pipeline. Both paths generate follow-up questions
at the end using the reranked documents from the sub-agents.
This function constructs the researcher agent graph for Q&A workflow.
The workflow follows a simple path:
1. Reformulate user query based on chat history
2. Handle QNA workflow (fetch documents and generate answer)
3. Generate follow-up questions

Returns:
A compiled LangGraph workflow
Expand All @@ -39,40 +28,12 @@ def build_graph():
# Add nodes to the graph
workflow.add_node("reformulate_user_query", reformulate_user_query)
workflow.add_node("handle_qna_workflow", handle_qna_workflow)
workflow.add_node("write_answer_outline", write_answer_outline)
workflow.add_node("process_sections", process_sections)
workflow.add_node("generate_further_questions", generate_further_questions)

# Define the edges
# Define the edges - simple linear flow for QNA
workflow.add_edge("__start__", "reformulate_user_query")

# Add conditional edges from reformulate_user_query based on research mode
def route_after_reformulate(state: State, config) -> str:
"""Route based on research_mode after reformulating the query."""
configuration = Configuration.from_runnable_config(config)

if configuration.research_mode == ResearchMode.QNA.value:
return "handle_qna_workflow"
else:
return "write_answer_outline"

workflow.add_conditional_edges(
"reformulate_user_query",
route_after_reformulate,
{
"handle_qna_workflow": "handle_qna_workflow",
"write_answer_outline": "write_answer_outline",
},
)

# QNA workflow path: handle_qna_workflow -> generate_further_questions -> __end__
workflow.add_edge("reformulate_user_query", "handle_qna_workflow")
workflow.add_edge("handle_qna_workflow", "generate_further_questions")

# Report generation workflow path: write_answer_outline -> process_sections -> generate_further_questions -> __end__
workflow.add_edge("write_answer_outline", "process_sections")
workflow.add_edge("process_sections", "generate_further_questions")

# Both paths end after generating further questions
workflow.add_edge("generate_further_questions", "__end__")

# Compile the workflow into an executable graph
Expand Down
Loading
Loading