mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-07 06:42:39 +02:00
Gate chat on MULTI_AGENT_CHAT_ENABLED and route to the multi-agent graph when on.
This commit is contained in:
parent
8f8d7540f0
commit
c077939522
3 changed files with 73 additions and 28 deletions
|
|
@ -252,6 +252,9 @@ LANGSMITH_PROJECT=surfsense
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# OPTIONAL: New-chat agent feature flags
|
# OPTIONAL: New-chat agent feature flags
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
# Multi-agent orchestrator switch for authenticated chat streaming.
|
||||||
|
# MULTI_AGENT_CHAT_ENABLED=false
|
||||||
|
|
||||||
# Master kill-switch — when true, every flag below is forced OFF.
|
# Master kill-switch — when true, every flag below is forced OFF.
|
||||||
# SURFSENSE_DISABLE_NEW_AGENT_STACK=false
|
# SURFSENSE_DISABLE_NEW_AGENT_STACK=false
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -399,6 +399,9 @@ class Config:
|
||||||
|
|
||||||
# Anonymous / no-login mode settings
|
# Anonymous / no-login mode settings
|
||||||
NOLOGIN_MODE_ENABLED = os.getenv("NOLOGIN_MODE_ENABLED", "FALSE").upper() == "TRUE"
|
NOLOGIN_MODE_ENABLED = os.getenv("NOLOGIN_MODE_ENABLED", "FALSE").upper() == "TRUE"
|
||||||
|
MULTI_AGENT_CHAT_ENABLED = (
|
||||||
|
os.getenv("MULTI_AGENT_CHAT_ENABLED", "FALSE").upper() == "TRUE"
|
||||||
|
)
|
||||||
ANON_TOKEN_LIMIT = int(os.getenv("ANON_TOKEN_LIMIT", "500000"))
|
ANON_TOKEN_LIMIT = int(os.getenv("ANON_TOKEN_LIMIT", "500000"))
|
||||||
ANON_TOKEN_WARNING_THRESHOLD = int(
|
ANON_TOKEN_WARNING_THRESHOLD = int(
|
||||||
os.getenv("ANON_TOKEN_WARNING_THRESHOLD", "400000")
|
os.getenv("ANON_TOKEN_WARNING_THRESHOLD", "400000")
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ from app.agents.new_chat.llm_config import (
|
||||||
load_agent_config,
|
load_agent_config,
|
||||||
load_global_llm_config_by_id,
|
load_global_llm_config_by_id,
|
||||||
)
|
)
|
||||||
|
from app.agents.multi_agent_chat.integration import create_multi_agent_chat
|
||||||
from app.agents.new_chat.memory_extraction import (
|
from app.agents.new_chat.memory_extraction import (
|
||||||
extract_and_save_memory,
|
extract_and_save_memory,
|
||||||
extract_and_save_team_memory,
|
extract_and_save_team_memory,
|
||||||
|
|
@ -1558,22 +1559,45 @@ async def stream_new_chat(
|
||||||
)
|
)
|
||||||
|
|
||||||
visibility = thread_visibility or ChatVisibility.PRIVATE
|
visibility = thread_visibility or ChatVisibility.PRIVATE
|
||||||
|
from app.config import config as _app_config
|
||||||
|
|
||||||
|
use_multi_agent = bool(_app_config.MULTI_AGENT_CHAT_ENABLED and not disabled_tools)
|
||||||
|
if _app_config.MULTI_AGENT_CHAT_ENABLED and disabled_tools:
|
||||||
|
logger.info(
|
||||||
|
"MULTI_AGENT_CHAT_ENABLED is on, but falling back to new_chat because disabled_tools are requested."
|
||||||
|
)
|
||||||
|
|
||||||
_t0 = time.perf_counter()
|
_t0 = time.perf_counter()
|
||||||
agent = await create_surfsense_deep_agent(
|
if use_multi_agent:
|
||||||
llm=llm,
|
agent = await create_multi_agent_chat(
|
||||||
search_space_id=search_space_id,
|
llm=llm,
|
||||||
db_session=session,
|
db_session=session,
|
||||||
connector_service=connector_service,
|
search_space_id=search_space_id,
|
||||||
checkpointer=checkpointer,
|
user_id=str(user_id),
|
||||||
user_id=user_id,
|
checkpointer=checkpointer,
|
||||||
thread_id=chat_id,
|
thread_id=str(chat_id),
|
||||||
agent_config=agent_config,
|
firecrawl_api_key=firecrawl_api_key,
|
||||||
firecrawl_api_key=firecrawl_api_key,
|
connector_service=connector_service,
|
||||||
thread_visibility=visibility,
|
thread_visibility=visibility,
|
||||||
disabled_tools=disabled_tools,
|
filesystem_selection=filesystem_selection,
|
||||||
mentioned_document_ids=mentioned_document_ids,
|
mentioned_document_ids=mentioned_document_ids,
|
||||||
filesystem_selection=filesystem_selection,
|
)
|
||||||
)
|
else:
|
||||||
|
agent = await create_surfsense_deep_agent(
|
||||||
|
llm=llm,
|
||||||
|
search_space_id=search_space_id,
|
||||||
|
db_session=session,
|
||||||
|
connector_service=connector_service,
|
||||||
|
checkpointer=checkpointer,
|
||||||
|
user_id=user_id,
|
||||||
|
thread_id=chat_id,
|
||||||
|
agent_config=agent_config,
|
||||||
|
firecrawl_api_key=firecrawl_api_key,
|
||||||
|
thread_visibility=visibility,
|
||||||
|
disabled_tools=disabled_tools,
|
||||||
|
mentioned_document_ids=mentioned_document_ids,
|
||||||
|
filesystem_selection=filesystem_selection,
|
||||||
|
)
|
||||||
_perf_log.info(
|
_perf_log.info(
|
||||||
"[stream_new_chat] Agent created in %.3fs", time.perf_counter() - _t0
|
"[stream_new_chat] Agent created in %.3fs", time.perf_counter() - _t0
|
||||||
)
|
)
|
||||||
|
|
@ -2266,21 +2290,36 @@ async def stream_resume_chat(
|
||||||
)
|
)
|
||||||
|
|
||||||
visibility = thread_visibility or ChatVisibility.PRIVATE
|
visibility = thread_visibility or ChatVisibility.PRIVATE
|
||||||
|
from app.config import config as _app_config
|
||||||
|
|
||||||
_t0 = time.perf_counter()
|
_t0 = time.perf_counter()
|
||||||
agent = await create_surfsense_deep_agent(
|
if _app_config.MULTI_AGENT_CHAT_ENABLED:
|
||||||
llm=llm,
|
agent = await create_multi_agent_chat(
|
||||||
search_space_id=search_space_id,
|
llm=llm,
|
||||||
db_session=session,
|
db_session=session,
|
||||||
connector_service=connector_service,
|
search_space_id=search_space_id,
|
||||||
checkpointer=checkpointer,
|
user_id=str(user_id),
|
||||||
user_id=user_id,
|
checkpointer=checkpointer,
|
||||||
thread_id=chat_id,
|
thread_id=str(chat_id),
|
||||||
agent_config=agent_config,
|
firecrawl_api_key=firecrawl_api_key,
|
||||||
firecrawl_api_key=firecrawl_api_key,
|
connector_service=connector_service,
|
||||||
thread_visibility=visibility,
|
thread_visibility=visibility,
|
||||||
filesystem_selection=filesystem_selection,
|
filesystem_selection=filesystem_selection,
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
agent = await create_surfsense_deep_agent(
|
||||||
|
llm=llm,
|
||||||
|
search_space_id=search_space_id,
|
||||||
|
db_session=session,
|
||||||
|
connector_service=connector_service,
|
||||||
|
checkpointer=checkpointer,
|
||||||
|
user_id=user_id,
|
||||||
|
thread_id=chat_id,
|
||||||
|
agent_config=agent_config,
|
||||||
|
firecrawl_api_key=firecrawl_api_key,
|
||||||
|
thread_visibility=visibility,
|
||||||
|
filesystem_selection=filesystem_selection,
|
||||||
|
)
|
||||||
_perf_log.info(
|
_perf_log.info(
|
||||||
"[stream_resume] Agent created in %.3fs", time.perf_counter() - _t0
|
"[stream_resume] Agent created in %.3fs", time.perf_counter() - _t0
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue