feat(agent): 增强多模态链路与工具调用能力
This commit is contained in:
@@ -107,6 +107,10 @@ class AgentRepository:
|
||||
raise HTTPException(status_code=404, detail="Session not found")
|
||||
|
||||
next_seq = int(session_row.message_count or 0) + 1
|
||||
if not _has_title(session_row.title):
|
||||
session_title = _derive_session_title(content_text)
|
||||
if session_title is not None:
|
||||
session_row.title = session_title
|
||||
payload_metadata = dict(metadata or {})
|
||||
payload_metadata["run_id"] = run_id
|
||||
message = AgentChatMessage(
|
||||
@@ -264,3 +268,14 @@ class AgentRepository:
|
||||
if rendered:
|
||||
payload["attachments"] = rendered
|
||||
return payload
|
||||
|
||||
|
||||
def _has_title(title: object) -> bool:
|
||||
return isinstance(title, str) and bool(title.strip())
|
||||
|
||||
|
||||
def _derive_session_title(content_text: str) -> str | None:
|
||||
normalized = " ".join(content_text.split())
|
||||
if not normalized:
|
||||
return None
|
||||
return normalized[:80]
|
||||
|
||||
@@ -203,6 +203,11 @@ async def stream_events(
|
||||
user_id=str(current_user.id),
|
||||
reason=str(exc),
|
||||
)
|
||||
if "Timeout reading from" in str(exc):
|
||||
idle_polls += 1
|
||||
yield ": keep-alive\n\n"
|
||||
await asyncio.sleep(0.2)
|
||||
continue
|
||||
break
|
||||
|
||||
if not rows:
|
||||
|
||||
@@ -212,12 +212,19 @@ class AgentService:
|
||||
content_type=mime_type,
|
||||
)
|
||||
except Exception: # noqa: BLE001
|
||||
bucket_name = "private"
|
||||
stored_path = await self._attachment_storage.upload_bytes(
|
||||
bucket=bucket_name,
|
||||
path=path,
|
||||
content=payload,
|
||||
content_type=mime_type,
|
||||
logger.exception(
|
||||
"Attachment upload failed",
|
||||
extra={
|
||||
"bucket": bucket_name,
|
||||
"path": path,
|
||||
"mime_type": mime_type,
|
||||
"thread_id": run_input.thread_id,
|
||||
"run_id": run_input.run_id,
|
||||
},
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=502,
|
||||
detail="Failed to upload attachment",
|
||||
)
|
||||
attachments.append(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user