refactor(backend): 更新 agent 服务和配置层

This commit is contained in:
zl-q
2026-03-19 00:52:12 +08:00
parent c8e51d1329
commit 522b53c993
10 changed files with 189 additions and 415 deletions
+8 -39
View File
@@ -168,10 +168,18 @@ class AgentService:
)
await self._repository.commit()
forwarded_props = getattr(run_input, "forwarded_props", None)
system_agent_mode = "worker"
if isinstance(forwarded_props, dict):
raw_mode = forwarded_props.get("system_agent_mode")
if isinstance(raw_mode, str) and raw_mode.strip():
system_agent_mode = raw_mode.strip().lower()
task_id = await self._queue.enqueue(
command={
"command": "run",
"owner_id": str(current_user.id),
"system_agent_mode": system_agent_mode,
"run_input": run_input.model_dump(
mode="json", by_alias=True, exclude_none=True
),
@@ -185,45 +193,6 @@ class AgentService:
created=created,
)
async def load_agent_input_messages(
self,
*,
thread_id: str,
) -> dict[str, object] | None:
"""Load recent messages for runtime agent input.
Returns messages from today and yesterday (if exists).
"""
today = await self._repository.get_history_day(
session_id=thread_id,
before=None,
)
if not today:
return None
yesterday = await self._repository.get_history_day(
session_id=thread_id,
before=self._parse_history_day(today.get("day")),
)
messages: list[dict[str, object]] = []
if yesterday and yesterday.get("messages"):
messages.extend(yesterday["messages"]) # type: ignore
if today.get("messages"):
messages.extend(today["messages"]) # type: ignore
return {"messages": messages}
def _parse_history_day(self, value: object) -> date | None:
if isinstance(value, date):
return value
if isinstance(value, str):
try:
return date.fromisoformat(value)
except ValueError:
return None
return None
async def _prepare_user_message(
self,
*,