refactor(agents): consolidate chat runtime infra under chat/runtime

Move the lower-level runtime/infra modules out of multi_agent_chat/shared/
(they were never used by subagents, so they failed the shared-by-all-siblings
rule) and unify them with the already-relocated checkpointer:

  agents/runtime/                      -> agents/chat/runtime/
  mac/shared/errors.py                 -> chat/runtime/errors.py
  mac/shared/llm_config.py             -> chat/runtime/llm_config.py
  mac/shared/prompt_caching.py         -> chat/runtime/prompt_caching.py
  mac/shared/mention_resolver.py       -> chat/runtime/mention_resolver.py
  mac/shared/path_resolver.py          -> chat/runtime/path_resolver.py

These sit below the agent packages: the boundary + agent factory + shared
middleware depend on them, and they import no agent code (acyclic).
This commit is contained in:
CREDO23 2026-06-05 13:19:24 +02:00
parent 7d866a2279
commit f2a61bc0ef
52 changed files with 97 additions and 87 deletions

View file

@ -12,7 +12,7 @@ from typing import Any
from app.agents.chat.multi_agent_chat.shared.filesystem_selection import (
FilesystemSelection,
)
from app.agents.chat.multi_agent_chat.shared.llm_config import AgentConfig
from app.agents.chat.runtime.llm_config import AgentConfig
from app.db import ChatVisibility
from app.services.connector_service import ConnectorService

View file

@ -7,11 +7,11 @@ import logging
import time
from typing import Any, Literal
from app.agents.chat.multi_agent_chat.shared.errors import BusyError
from app.agents.chat.multi_agent_chat.shared.middleware.busy_mutex import (
get_cancel_state,
is_cancel_requested,
)
from app.agents.chat.runtime.errors import BusyError
TURN_CANCELLING_INITIAL_DELAY_MS = 200
TURN_CANCELLING_BACKOFF_FACTOR = 2

View file

@ -29,7 +29,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.future import select
from app.agents.chat.multi_agent_chat.shared.filesystem_selection import FilesystemMode
from app.agents.chat.multi_agent_chat.shared.mention_resolver import (
from app.agents.chat.runtime.mention_resolver import (
resolve_mentions,
substitute_in_text,
)

View file

@ -15,7 +15,7 @@ tells the user what to change.
from __future__ import annotations
from app.agents.chat.multi_agent_chat.shared.llm_config import AgentConfig
from app.agents.chat.runtime.llm_config import AgentConfig
from app.observability import otel as ot

View file

@ -30,7 +30,7 @@ from app.prompts import TITLE_GENERATION_PROMPT
from app.services.new_streaming_service import VercelStreamingService
if TYPE_CHECKING:
from app.agents.chat.multi_agent_chat.shared.llm_config import AgentConfig
from app.agents.chat.runtime.llm_config import AgentConfig
from app.services.token_tracking_service import TokenAccumulator

View file

@ -14,7 +14,7 @@ from typing import Any
from sqlalchemy.ext.asyncio import AsyncSession
from app.agents.chat.multi_agent_chat.shared.llm_config import (
from app.agents.chat.runtime.llm_config import (
AgentConfig,
create_chat_litellm_from_agent_config,
create_chat_litellm_from_config,

View file

@ -4,7 +4,7 @@ from __future__ import annotations
from sqlalchemy.ext.asyncio import AsyncSession
from app.agents.runtime.checkpointer import get_checkpointer
from app.agents.chat.runtime.checkpointer import get_checkpointer
from app.db import SearchSourceConnectorType
from app.services.connector_service import ConnectorService
@ -33,7 +33,7 @@ async def setup_connector_and_firecrawl(
async def get_chat_checkpointer():
"""Resolve the PostgreSQL checkpointer for persistent conversation memory.
Thin wrapper around ``app.agents.runtime.checkpointer.get_checkpointer`` so
Thin wrapper around ``app.agents.chat.runtime.checkpointer.get_checkpointer`` so
flow orchestrators can rely on a streaming-local symbol and we have a hook
point if the checkpointer source ever needs to vary per flow.
"""

View file

@ -19,7 +19,7 @@ from dataclasses import dataclass
from typing import TYPE_CHECKING
from uuid import UUID
from app.agents.chat.multi_agent_chat.shared.llm_config import AgentConfig
from app.agents.chat.runtime.llm_config import AgentConfig
from app.db import shielded_async_session
if TYPE_CHECKING:

View file

@ -14,7 +14,7 @@ import traceback
from collections.abc import Iterator
from typing import Any, Literal
from app.agents.chat.multi_agent_chat.shared.errors import BusyError
from app.agents.chat.runtime.errors import BusyError
from app.observability import metrics as ot_metrics, otel as ot
from app.services.new_streaming_service import VercelStreamingService
from app.tasks.chat.streaming.errors.classifier import classify_stream_exception