refactor(backend): 更新 agentscope 事件存储和编解码
This commit is contained in:
@@ -131,7 +131,7 @@ def _build_tool_result(event: dict[str, Any]) -> ToolCallResultEvent:
|
||||
data = event.get("data", {})
|
||||
content = data.get("result")
|
||||
if not isinstance(content, str):
|
||||
content = data.get("toolAgentOutput", "")
|
||||
content = ""
|
||||
return ToolCallResultEvent(
|
||||
message_id=data.get("messageId", ""),
|
||||
tool_call_id=data.get("toolCallId", ""),
|
||||
|
||||
@@ -8,7 +8,7 @@ from core.agentscope.events.persistence import MessageRepository, SessionReposit
|
||||
from core.logging import get_logger
|
||||
from models.agent_chat_message import AgentChatMessageRole
|
||||
from models.agent_chat_session import AgentChatSessionStatus
|
||||
from schemas.agent.runtime_models import ToolAgentOutput, WorkerAgentOutputRich
|
||||
from schemas.agent.runtime_models import AgentOutput, ToolAgentOutput
|
||||
from schemas.agent.system_agent import AgentType
|
||||
from schemas.messages.chat_message import AgentChatMessageMetadata
|
||||
|
||||
@@ -136,11 +136,22 @@ class SqlAlchemyEventStore:
|
||||
return
|
||||
|
||||
try:
|
||||
worker_output = WorkerAgentOutputRich.model_validate(worker_output_payload)
|
||||
worker_output = AgentOutput.model_validate(worker_output_payload)
|
||||
raw_agent_type = self._event_value(event, "stage")
|
||||
normalized_agent_type = (
|
||||
str(raw_agent_type).strip().lower()
|
||||
if isinstance(raw_agent_type, str)
|
||||
else AgentType.WORKER.value
|
||||
)
|
||||
agent_type = (
|
||||
AgentType.MEMORY
|
||||
if normalized_agent_type == AgentType.MEMORY.value
|
||||
else AgentType.WORKER
|
||||
)
|
||||
metadata_model = AgentChatMessageMetadata(
|
||||
run_id=run_id_value,
|
||||
agent_type=AgentType.WORKER,
|
||||
worker_agent_output=worker_output,
|
||||
agent_type=agent_type,
|
||||
agent_output=worker_output,
|
||||
)
|
||||
except Exception:
|
||||
self._logger.warning(
|
||||
|
||||
Reference in New Issue
Block a user