feat(agent): 增强多模态链路与工具调用能力

This commit is contained in:
zl-q
2026-03-12 00:18:45 +08:00
parent 18db6c50e7
commit 21ba8e4a44
35 changed files with 2057 additions and 829 deletions
@@ -1,6 +1,8 @@
from __future__ import annotations
import base64
import os
from pathlib import Path
from uuid import UUID, uuid4
import httpx
@@ -12,6 +14,9 @@ from models.agent_chat_message import AgentChatMessage
from models.agent_chat_session import AgentChatSession
BASE_URL = os.getenv("AGENT_LIVE_BASE_URL", "http://localhost:5775")
FIXTURE_IMAGE_PATH = (
Path(__file__).resolve().parents[3] / "fixtures" / "images" / "calendar_text_cn.png"
)
async def _live_access_token(client: httpx.AsyncClient) -> str:
@@ -108,6 +113,8 @@ async def test_agent_runs_events_history_live_with_image_input() -> None:
if os.getenv("AGENT_LIVE_INTEGRATION") != "1":
pytest.skip("set AGENT_LIVE_INTEGRATION=1 to run live integration test")
image_data = base64.b64encode(FIXTURE_IMAGE_PATH.read_bytes()).decode("ascii")
async with httpx.AsyncClient(timeout=30.0) as client:
token = await _live_access_token(client)
headers = {"Authorization": f"Bearer {token}"}
@@ -128,7 +135,7 @@ async def test_agent_runs_events_history_live_with_image_input() -> None:
{"type": "text", "text": "请描述图片里的内容"},
{
"type": "binary",
"data": "aGVsbG8=",
"data": image_data,
"mimeType": "image/png",
},
],
@@ -142,19 +149,20 @@ async def test_agent_runs_events_history_live_with_image_input() -> None:
assert run_resp.status_code == 202
events_url = f"{BASE_URL}/api/v1/agent/runs/{thread_id}/events"
sse_resp = await client.get(
events_url,
headers=headers,
params={"idle_limit": 150},
timeout=60.0,
)
assert sse_resp.status_code == 200
assert sse_resp.headers.get("content-type", "").startswith("text/event-stream")
event_names = [
line.split(":", 1)[1].strip()
for line in sse_resp.text.splitlines()
if line.startswith("event:")
]
event_names: list[str] = []
async with client.stream(
"GET", events_url, headers=headers, timeout=90.0
) as sse_resp:
assert sse_resp.status_code == 200
assert sse_resp.headers.get("content-type", "").startswith(
"text/event-stream"
)
async for line in sse_resp.aiter_lines():
if line.startswith("event:"):
event_name = line.split(":", 1)[1].strip()
event_names.append(event_name)
if event_name in {"RUN_FINISHED", "RUN_ERROR"}:
break
assert "RUN_STARTED" in event_names
assert "RUN_FINISHED" in event_names or "RUN_ERROR" in event_names
@@ -194,7 +202,14 @@ async def test_agent_runs_events_history_live_with_image_input() -> None:
)
all_messages = list(rows.scalars().all())
assert all_messages
user_rows = [row for row in all_messages if str(row.role) == "user"]
user_rows = [
row
for row in all_messages
if (
getattr(row.role, "value", row.role) == "user"
or str(getattr(row.role, "value", row.role)) == "user"
)
]
assert user_rows
metadata = user_rows[0].metadata_json or {}
attachments = metadata.get("attachments")