2026-05-25 21:48:20 +02:00
|
|
|
"""Single per-thread agent (re)build path.
|
|
|
|
|
|
|
|
|
|
A graph swap mid-turn would corrupt checkpointer state for the same
|
|
|
|
|
``thread_id``, so both the initial build and any mid-stream 429 recovery rebuild
|
|
|
|
|
must funnel through this single function.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
refactor(agents): introduce chat/ category; dissolve top-level agents/shared
Recursive shared-folder rule: a shared/ must be shared by ALL siblings at its
level. The kernel (context, compaction, retry_after, web_search) was shared by
only 2 of the agents -- anonymous_chat + multi_agent_chat -- never by podcaster
or video_presentation. Those 2 are the "chat" category, so their shared code
belongs in that category's shared/, not the top-level one.
app/agents/anonymous_chat/ -> app/agents/chat/anonymous_chat/
app/agents/multi_agent_chat/ -> app/agents/chat/multi_agent_chat/
app/agents/shared/ -> app/agents/chat/shared/ (anon<->mac kernel)
Top-level app/agents/shared/ is gone: nothing was shared across all three
categories (chat / podcaster / video_presentation).
~289 import sites rewritten (app.agents.{anonymous_chat,multi_agent_chat,shared}
-> app.agents.chat.*); all moves are git renames (history preserved).
app/agents/ now: chat/, podcaster/, video_presentation/, runtime/.
2026-06-05 12:54:02 +02:00
|
|
|
from app.agents.chat.multi_agent_chat.shared.filesystem_selection import (
|
|
|
|
|
FilesystemSelection,
|
|
|
|
|
)
|
2026-06-05 13:19:24 +02:00
|
|
|
from app.agents.chat.runtime.llm_config import AgentConfig
|
2026-05-25 21:48:20 +02:00
|
|
|
from app.db import ChatVisibility
|
|
|
|
|
from app.services.connector_service import ConnectorService
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def build_main_agent_for_thread(
|
|
|
|
|
agent_factory: Any,
|
|
|
|
|
*,
|
|
|
|
|
llm: Any,
|
|
|
|
|
search_space_id: int,
|
|
|
|
|
db_session: Any,
|
|
|
|
|
connector_service: ConnectorService,
|
|
|
|
|
checkpointer: Any,
|
|
|
|
|
user_id: str | None,
|
|
|
|
|
thread_id: int | None,
|
|
|
|
|
agent_config: AgentConfig | None,
|
|
|
|
|
firecrawl_api_key: str | None,
|
|
|
|
|
thread_visibility: ChatVisibility | None,
|
|
|
|
|
filesystem_selection: FilesystemSelection | None,
|
|
|
|
|
disabled_tools: list[str] | None = None,
|
|
|
|
|
mentioned_document_ids: list[int] | None = None,
|
|
|
|
|
) -> Any:
|
|
|
|
|
return await agent_factory(
|
|
|
|
|
llm=llm,
|
|
|
|
|
search_space_id=search_space_id,
|
|
|
|
|
db_session=db_session,
|
|
|
|
|
connector_service=connector_service,
|
|
|
|
|
checkpointer=checkpointer,
|
|
|
|
|
user_id=user_id,
|
|
|
|
|
thread_id=thread_id,
|
|
|
|
|
agent_config=agent_config,
|
|
|
|
|
firecrawl_api_key=firecrawl_api_key,
|
|
|
|
|
thread_visibility=thread_visibility,
|
|
|
|
|
filesystem_selection=filesystem_selection,
|
|
|
|
|
disabled_tools=disabled_tools,
|
|
|
|
|
mentioned_document_ids=mentioned_document_ids,
|
|
|
|
|
)
|