refactor(backend): 重构 agentscope 运行时模块

This commit is contained in:
zl-q
2026-03-19 00:52:05 +08:00
parent 9219e8d047
commit f709023b6d
7 changed files with 261 additions and 255 deletions
+11 -3
View File
@@ -12,6 +12,7 @@ from core.agentscope.events import (
RedisStreamBus,
SqlAlchemyEventStore,
)
from core.agentscope.runtime.context_service import AgentContextService
from core.agentscope.runtime.orchestrator import AgentScopeRuntimeOrchestrator
from core.agentscope.schemas.agui_input import parse_run_input
from core.auth.models import CurrentUser
@@ -26,7 +27,7 @@ from schemas.messages.chat_message import (
from schemas.user import UserContext
from services.base.redis import get_or_init_redis_client
from services.base.supabase import supabase_service
from v1.agent.dependencies import get_agent_service
from v1.agent.repository import AgentRepository
from v1.users.dependencies import get_user_service
logger = get_logger("core.agentscope.runtime.tasks")
@@ -78,9 +79,13 @@ async def _build_recent_context_messages(
*,
session: Any,
thread_id: str,
system_agent_mode: str,
) -> list[Msg]:
agent_service = get_agent_service(session)
result = await agent_service.load_agent_input_messages(thread_id=thread_id)
context_service = AgentContextService(repository=AgentRepository(session))
result = await context_service.load_context_messages(
thread_id=thread_id,
system_agent_mode=system_agent_mode,
)
if not result:
return []
@@ -165,6 +170,7 @@ async def run_agentscope_task(command: dict[str, Any]) -> dict[str, object]:
command_type = str(command.get("command", "run")).strip().lower()
raw_owner_id = command.get("owner_id")
run_input_raw = command.get("run_input")
system_agent_mode = str(command.get("system_agent_mode", "worker")).strip().lower()
if not isinstance(raw_owner_id, str) or not raw_owner_id.strip():
raise ValueError("owner_id is required")
@@ -205,12 +211,14 @@ async def run_agentscope_task(command: dict[str, Any]) -> dict[str, object]:
context_messages = await _build_recent_context_messages(
session=session,
thread_id=thread_id,
system_agent_mode=system_agent_mode,
)
await runtime.run(
run_input=run_input,
context_messages=context_messages,
user_context=user_context,
system_agent_mode=system_agent_mode,
)
logger.info(
"agentscope runtime task completed",