refactor: 重命名 automation worker 为 general worker 并完善错误处理

This commit is contained in:
qzl
2026-04-01 17:24:52 +08:00
parent 0fe28a1c62
commit 24eda6ff51
19 changed files with 760 additions and 25 deletions
@@ -5,6 +5,7 @@ from typing import Any, Awaitable, Callable, Protocol
from ag_ui.core.types import RunAgentInput
from agentscope.message import Msg
from openai import APIConnectionError
from core.agentscope.runtime.runner import AgentScopeRunner
from core.logging import get_logger
from schemas.domain.automation import RuntimeConfig
@@ -106,6 +107,23 @@ class AgentScopeRuntimeOrchestrator:
},
)
raise
except APIConnectionError:
logger.warning(
"agentscope upstream connection failed",
thread_id=thread_id,
run_id=run_id,
)
await self._pipeline.emit(
session_id=thread_id,
event={
"type": "RUN_ERROR",
"threadId": thread_id,
"runId": run_id,
"message": "network error",
"code": "AGENT_UPSTREAM_CONNECTION_ERROR",
},
)
raise
except Exception:
logger.exception(
"agentscope runtime execution failed",
+3 -3
View File
@@ -26,7 +26,7 @@ from core.auth.models import CurrentUser
from core.config.settings import config
from core.db.session import AsyncSessionLocal
from core.logging import get_logger
from core.taskiq.app import worker_agent_broker, worker_automation_broker
from core.taskiq.app import worker_agent_broker, worker_general_broker
from schemas.agent.forwarded_props import (
RuntimeMode,
parse_forwarded_props_runtime_mode,
@@ -345,6 +345,6 @@ async def run_command_task_agent(command: dict[str, object]) -> dict[str, object
return await run_agentscope_task(command)
@worker_automation_broker.task(task_name="tasks.agentscope.run_command.automation")
async def run_command_task_automation(command: dict[str, object]) -> dict[str, object]:
@worker_general_broker.task(task_name="tasks.agentscope.run_command.general")
async def run_command_task_general(command: dict[str, object]) -> dict[str, object]:
return await run_agentscope_task(command)
+2 -2
View File
@@ -1,3 +1,3 @@
from core.taskiq.app import broker, worker_agent_broker, worker_automation_broker
from core.taskiq.app import broker, worker_agent_broker, worker_general_broker
__all__ = ["broker", "worker_agent_broker", "worker_automation_broker"]
__all__ = ["broker", "worker_agent_broker", "worker_general_broker"]
+3 -2
View File
@@ -12,6 +12,7 @@ log_service_banner(
environment=config.runtime.environment,
)
def _build_broker(queue_name: str) -> ListQueueBroker:
return ListQueueBroker(
url=config.taskiq_broker_url,
@@ -22,8 +23,8 @@ def _build_broker(queue_name: str) -> ListQueueBroker:
worker_agent_broker = _build_broker("agent")
worker_automation_broker = _build_broker("automation")
worker_general_broker = _build_broker("general")
broker = worker_agent_broker
__all__ = ["broker", "worker_agent_broker", "worker_automation_broker"]
__all__ = ["broker", "worker_agent_broker", "worker_general_broker"]
+1 -1
View File
@@ -142,7 +142,7 @@ class AgentService:
metadata=user_message_metadata,
)
queue = "automation" if runtime_mode == RuntimeMode.AUTOMATION else "agent"
queue = "general" if runtime_mode == RuntimeMode.AUTOMATION else "agent"
task_id = await self._queue.enqueue(
command={
"command": "run",
+2 -2
View File
@@ -5,13 +5,13 @@ import sys
import pytest
from core.taskiq.app import broker, worker_agent_broker, worker_automation_broker
from core.taskiq.app import broker, worker_agent_broker, worker_general_broker
def test_taskiq_broker_is_configured() -> None:
assert broker is not None
assert worker_agent_broker is broker
assert worker_automation_broker is not None
assert worker_general_broker is not None
def test_taskiq_app_configures_logging_on_import(