feat(agent): migrate to native CrewAI tool loop and async resume enqueue

This commit is contained in:
zl-q
2026-03-08 16:01:16 +08:00
parent 120df903d2
commit 8a23018b6d
29 changed files with 2234 additions and 1115 deletions
+14 -14
View File
@@ -13,7 +13,10 @@ from fastapi import HTTPException
from fastapi.responses import StreamingResponse
from core.agent.infrastructure.agui.stream import to_sse_event
from core.agent.domain.agui_input import parse_run_input
from core.agent.domain.agui_input import (
parse_run_input,
validate_run_request_messages_contract,
)
from core.auth.models import CurrentUser
from services.base.redis import get_or_init_redis_client
from v1.agent.dependencies import get_agent_service
@@ -76,7 +79,8 @@ async def enqueue_run(
current_user: Annotated[CurrentUser, Depends(get_current_user)],
) -> TaskAcceptedResponse:
try:
parse_run_input(request.model_dump(mode="json", by_alias=True))
normalized = parse_run_input(request.model_dump(mode="json", by_alias=True))
validate_run_request_messages_contract(normalized)
except ValueError as exc:
raise HTTPException(status_code=422, detail=str(exc)) from exc
allowed = await _allow_run_request(user_id=str(current_user.id))
@@ -88,9 +92,9 @@ async def enqueue_run(
current_user=current_user,
)
return TaskAcceptedResponse(
task_id=task.task_id,
thread_id=task.thread_id,
run_id=task.run_id,
taskId=task.task_id,
threadId=task.thread_id,
runId=task.run_id,
created=task.created,
)
@@ -118,9 +122,9 @@ async def enqueue_resume(
current_user=current_user,
)
return TaskAcceptedResponse(
task_id=task.task_id,
thread_id=task.thread_id,
run_id=task.run_id,
taskId=task.task_id,
threadId=task.thread_id,
runId=task.run_id,
created=task.created,
)
@@ -134,12 +138,8 @@ async def stream_events(
last_event_id: str | None = Header(default=None, alias="Last-Event-ID"),
idle_limit: int = Query(default=300, ge=1, le=3600),
) -> StreamingResponse:
if (
last_event_id is not None
and (
len(last_event_id) > 32
or _LAST_EVENT_ID_RE.fullmatch(last_event_id) is None
)
if last_event_id is not None and (
len(last_event_id) > 32 or _LAST_EVENT_ID_RE.fullmatch(last_event_id) is None
):
raise HTTPException(status_code=422, detail="Invalid Last-Event-ID")