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
@@ -17,9 +17,7 @@ class _FakeAgentService:
def __init__(self) -> None:
self._stream_called = False
async def enqueue_run(
self, *, run_input: RunAgentInput, current_user: CurrentUser
):
async def enqueue_run(self, *, run_input: RunAgentInput, current_user: CurrentUser):
del current_user
return SimpleNamespace(
task_id="task-run-1",
@@ -287,3 +285,64 @@ def test_run_rejects_oversized_user_text_payload() -> None:
assert response.status_code == 422
finally:
app.dependency_overrides = {}
def test_run_rejects_client_supplied_history_messages() -> None:
app.dependency_overrides[get_agent_service] = lambda: _FakeAgentService()
app.dependency_overrides[get_current_user] = lambda: CurrentUser(
id=uuid4(), email="user@example.com"
)
client = TestClient(app)
try:
response = client.post(
"/api/v1/agent/runs",
json={
"threadId": "00000000-0000-0000-0000-000000000001",
"runId": "run-history",
"state": {},
"messages": [
{"id": "a1", "role": "assistant", "content": "old"},
{"id": "u1", "role": "user", "content": "new"},
],
"tools": [],
"context": [],
"forwardedProps": {},
},
)
assert response.status_code == 422
finally:
app.dependency_overrides = {}
def test_resume_accepts_tool_message_without_user_message() -> None:
app.dependency_overrides[get_agent_service] = lambda: _FakeAgentService()
app.dependency_overrides[get_current_user] = lambda: CurrentUser(
id=uuid4(), email="user@example.com"
)
client = TestClient(app)
try:
response = client.post(
"/api/v1/agent/runs/00000000-0000-0000-0000-000000000001/resume",
json={
"threadId": "00000000-0000-0000-0000-000000000001",
"runId": "run-resume-1",
"state": {},
"messages": [
{
"id": "tool-1",
"role": "tool",
"toolCallId": "call-1",
"content": '{"toolName":"navigate_to_route","toolArgs":{"target":"/calendar/dayweek"},"nonce":"n1","result":{"ok":true}}',
}
],
"tools": [],
"context": [],
"forwardedProps": {},
},
)
assert response.status_code == 202
assert response.json()["taskId"] == "task-resume-1"
finally:
app.dependency_overrides = {}