feat: restore original UMO in respond stage and update send_message_to_user tool

Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-03 17:14:25 +00:00
parent eb667d310c
commit 3091b92158
2 changed files with 16 additions and 1 deletions
+8 -1
View File
@@ -212,6 +212,10 @@ class SendMessageToUserTool(FunctionTool[AstrAgentContext]):
"required": ["type"],
},
},
"session": {
"type": "string",
"description": "Target session ID in format 'platform:type:session_id'. If not specified, sends to the current session.",
},
},
"required": ["messages"],
}
@@ -253,7 +257,10 @@ class SendMessageToUserTool(FunctionTool[AstrAgentContext]):
async def call(
self, context: ContextWrapper[AstrAgentContext], **kwargs
) -> ToolExecResult:
session = kwargs.get("session") or context.context.event.unified_msg_origin
# In global context mode, default to original UMO if session not specified
original_umo = context.context.event.get_extra("original_umo")
default_session = original_umo or context.context.event.unified_msg_origin
session = kwargs.get("session") or default_session
messages = kwargs.get("messages")
if not isinstance(messages, list) or not messages:
+8
View File
@@ -169,6 +169,14 @@ class RespondStage(Stage):
f"Prepare to send - {event.get_sender_name()}/{event.get_sender_id()}: {event._outline_chain(result.chain)}",
)
# Restore original UMO before sending if in global context mode
original_umo = event.get_extra("original_umo")
if original_umo:
logger.debug(
f"Restoring original UMO before sending: {event.unified_msg_origin} -> {original_umo}"
)
event.unified_msg_origin = original_umo
if result.result_content_type == ResultContentType.STREAMING_RESULT:
if result.async_stream is None:
logger.warning("async_stream 为空,跳过发送。")