mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-06 20:15:17 +02:00
refactor(agents): move connector_searchable_types, agent_cache, system_prompt + prompts to app/agents/shared (slice 7b)
Three live shared leaves discovered while taking stock after slice 7 (all are consumed by the multi-agent stack and/or live routes, not single-agent-only): - connector_searchable_types -> shared + shim (multi-agent factory uses it) - agent_cache -> shared + shim (multi-agent runtime/agent_cache uses it) - system_prompt + prompts/ (42 .md fragments) -> shared together + shim. Repointed composer's _PROMPTS_PACKAGE to app.agents.shared.prompts so importlib.resources fragment loading keeps working; system_prompt's relative ".prompts.composer" import is preserved by moving both as a unit. Each keeps a re-export shim for the frozen chat_deepagent. After this slice, new_chat/ holds only the frozen single-agent stack (chat_deepagent, subagents/, __init__) plus shims.
This commit is contained in:
parent
13a96851ef
commit
a019f18d1c
60 changed files with 627 additions and 564 deletions
133
surfsense_backend/app/agents/shared/system_prompt.py
Normal file
133
surfsense_backend/app/agents/shared/system_prompt.py
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
"""
|
||||
Thin compatibility wrapper around :mod:`app.agents.shared.prompts.composer`.
|
||||
|
||||
The composer split the previous monolithic prompt string into a fragment
|
||||
tree under ``prompts/`` plus a model-family dispatch step (see the
|
||||
composer module docstring for credits). This module preserves the public
|
||||
function surface (``build_surfsense_system_prompt`` /
|
||||
``build_configurable_system_prompt`` /
|
||||
``get_default_system_instructions`` / ``SURFSENSE_SYSTEM_PROMPT``) so
|
||||
that existing call sites — `chat_deepagent.py`, anonymous chat routes,
|
||||
and the configurable-prompt admin path — keep working without churn.
|
||||
|
||||
For new call sites prefer importing ``compose_system_prompt`` directly
|
||||
from :mod:`app.agents.shared.prompts.composer`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from app.db import ChatVisibility
|
||||
|
||||
from .prompts.composer import (
|
||||
_read_fragment,
|
||||
compose_system_prompt,
|
||||
detect_provider_variant,
|
||||
)
|
||||
|
||||
# Optional routing fragments under ``prompts/routing/`` (see composer).
|
||||
_DEFAULT_CONNECTOR_ROUTING: tuple[str, ...] = ("linear", "slack")
|
||||
|
||||
# Public re-exports for backwards compatibility (some legacy code reads the
|
||||
# raw default-instructions text directly).
|
||||
SURFSENSE_SYSTEM_INSTRUCTIONS_TEMPLATE = (
|
||||
"<system_instruction>\nDefault SurfSense agent system instructions are now\n"
|
||||
"composed from prompts/base/*.md. See compose_system_prompt() for details.\n"
|
||||
"</system_instruction>"
|
||||
)
|
||||
|
||||
# Citation block re-exposed for legacy importers that referenced this constant
|
||||
# directly. The composer is the canonical source; this is a frozen snapshot
|
||||
# loaded at module-init time.
|
||||
SURFSENSE_CITATION_INSTRUCTIONS = _read_fragment("base/citations_on.md")
|
||||
SURFSENSE_NO_CITATION_INSTRUCTIONS = _read_fragment("base/citations_off.md")
|
||||
|
||||
|
||||
def build_surfsense_system_prompt(
|
||||
today: datetime | None = None,
|
||||
thread_visibility: ChatVisibility | None = None,
|
||||
enabled_tool_names: set[str] | None = None,
|
||||
disabled_tool_names: set[str] | None = None,
|
||||
mcp_connector_tools: dict[str, list[str]] | None = None,
|
||||
*,
|
||||
model_name: str | None = None,
|
||||
) -> str:
|
||||
"""Build the default SurfSense system prompt (citations on, defaults).
|
||||
|
||||
See :func:`app.agents.shared.prompts.composer.compose_system_prompt`
|
||||
for full parameter docs.
|
||||
"""
|
||||
return compose_system_prompt(
|
||||
today=today,
|
||||
thread_visibility=thread_visibility,
|
||||
enabled_tool_names=enabled_tool_names,
|
||||
disabled_tool_names=disabled_tool_names,
|
||||
mcp_connector_tools=mcp_connector_tools,
|
||||
citations_enabled=True,
|
||||
model_name=model_name,
|
||||
connector_routing=_DEFAULT_CONNECTOR_ROUTING,
|
||||
)
|
||||
|
||||
|
||||
def build_configurable_system_prompt(
|
||||
custom_system_instructions: str | None = None,
|
||||
use_default_system_instructions: bool = True,
|
||||
citations_enabled: bool = True,
|
||||
today: datetime | None = None,
|
||||
thread_visibility: ChatVisibility | None = None,
|
||||
enabled_tool_names: set[str] | None = None,
|
||||
disabled_tool_names: set[str] | None = None,
|
||||
mcp_connector_tools: dict[str, list[str]] | None = None,
|
||||
*,
|
||||
model_name: str | None = None,
|
||||
) -> str:
|
||||
"""Build a configurable SurfSense system prompt (NewLLMConfig path).
|
||||
|
||||
See :func:`app.agents.shared.prompts.composer.compose_system_prompt`
|
||||
for full parameter docs.
|
||||
"""
|
||||
return compose_system_prompt(
|
||||
today=today,
|
||||
thread_visibility=thread_visibility,
|
||||
enabled_tool_names=enabled_tool_names,
|
||||
disabled_tool_names=disabled_tool_names,
|
||||
mcp_connector_tools=mcp_connector_tools,
|
||||
custom_system_instructions=custom_system_instructions,
|
||||
use_default_system_instructions=use_default_system_instructions,
|
||||
citations_enabled=citations_enabled,
|
||||
model_name=model_name,
|
||||
connector_routing=_DEFAULT_CONNECTOR_ROUTING,
|
||||
)
|
||||
|
||||
|
||||
def get_default_system_instructions() -> str:
|
||||
"""Return the default ``<system_instruction>`` block (no tools / citations).
|
||||
|
||||
Useful for populating the UI when seeding ``NewLLMConfig.system_instructions``.
|
||||
The output reflects the current fragment tree, not a baked-in constant.
|
||||
"""
|
||||
resolved_today = datetime.now(UTC).date().isoformat()
|
||||
from .prompts.composer import _build_system_instructions # local import
|
||||
|
||||
return _build_system_instructions(
|
||||
visibility=ChatVisibility.PRIVATE,
|
||||
resolved_today=resolved_today,
|
||||
).strip()
|
||||
|
||||
|
||||
# Backwards compatibility — some modules import the constant directly.
|
||||
SURFSENSE_SYSTEM_PROMPT = build_surfsense_system_prompt()
|
||||
|
||||
|
||||
__all__ = [
|
||||
"SURFSENSE_CITATION_INSTRUCTIONS",
|
||||
"SURFSENSE_NO_CITATION_INSTRUCTIONS",
|
||||
"SURFSENSE_SYSTEM_INSTRUCTIONS_TEMPLATE",
|
||||
"SURFSENSE_SYSTEM_PROMPT",
|
||||
"build_configurable_system_prompt",
|
||||
"build_surfsense_system_prompt",
|
||||
"compose_system_prompt",
|
||||
"detect_provider_variant",
|
||||
"get_default_system_instructions",
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue