SurfSense/surfsense_backend/app/routes/agent_flags_route.py
CREDO23 2beafbdec8 agent: retire eager KB priority/planner path and its dead flags
The pull-based KB design (on-demand search_knowledge_base tool + pre-injected
workspace tree) fully replaced the old eager retrieval path. Remove its last
remnants:

- Delete KnowledgePriorityMiddleware (knowledge_search.py) and its tests.
- Drop the kb_priority state field + reducer default; trim
  KbContextProjectionMiddleware to project only workspace_tree_text.
- Remove the now-dead feature flags enable_kb_priority_preinjection and
  enable_kb_planner_runnable across backend (flags, route schema, tests,
  env examples) and frontend (settings toggle, zod schema).
- Scrub <priority_documents> and stale KnowledgePriorityMiddleware references
  from prompts, docstrings, and the ADR.

No functional change: nothing wrote kb_priority and neither flag gated live
behavior after the cutover. Full backend suite green (pre-existing unrelated
failures aside).
2026-06-25 18:37:14 +02:00

79 lines
2.3 KiB
Python

"""``GET /api/agent/flags``: read-only feature-flag status.
Surfaces :class:`AgentFeatureFlags` to the frontend so the UI can:
* Render conditional surfaces (e.g. show the action-log button only when
``enable_action_log`` is on).
* Display an admin diagnostics card so operators can verify which
middleware tier is active without shelling into the box.
The endpoint is *read-only*. Flipping flags requires an env-var change
plus a process restart — by design, since the values are baked into the
agent factory at build time. The route does not require any special
permission (any authenticated user can see them) since the flag values
do not leak data, and the UI surfaces are conditionally rendered based
on them anyway.
"""
from __future__ import annotations
from dataclasses import asdict
from fastapi import APIRouter, Depends
from pydantic import BaseModel
from app.agents.chat.multi_agent_chat.shared.feature_flags import (
AgentFeatureFlags,
get_flags,
)
from app.auth.context import AuthContext
from app.config import config
from app.users import require_session_context
router = APIRouter()
class AgentFeatureFlagsRead(BaseModel):
"""Mirror of :class:`AgentFeatureFlags`. Updated together with it."""
disable_new_agent_stack: bool
enable_context_editing: bool
enable_compaction_v2: bool
enable_retry_after: bool
enable_model_fallback: bool
enable_model_call_limit: bool
enable_tool_call_limit: bool
enable_tool_call_repair: bool
enable_doom_loop: bool
enable_permission: bool
enable_busy_mutex: bool
enable_llm_tool_selector: bool
enable_skills: bool
enable_specialized_subagents: bool
enable_action_log: bool
enable_revert_route: bool
enable_plugin_loader: bool
enable_otel: bool
enable_desktop_local_filesystem: bool
@classmethod
def from_flags(cls, flags: AgentFeatureFlags) -> AgentFeatureFlagsRead:
# asdict() avoids missing-field bugs when AgentFeatureFlags grows.
return cls(
**asdict(flags),
enable_desktop_local_filesystem=config.ENABLE_DESKTOP_LOCAL_FILESYSTEM,
)
@router.get("/agent/flags", response_model=AgentFeatureFlagsRead)
async def get_agent_flags(
_auth: AuthContext = Depends(require_session_context),
) -> AgentFeatureFlagsRead:
return AgentFeatureFlagsRead.from_flags(get_flags())