refactor(backend): 更新 agent 服务和配置层
This commit is contained in:
@@ -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,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user