From eb667d310c4dc05129b4d8e826a8f3df69e01937 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 17:01:47 +0000 Subject: [PATCH] refactor: improve error handling in global context info function Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com> --- astrbot/core/astr_main_agent.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/astrbot/core/astr_main_agent.py b/astrbot/core/astr_main_agent.py index 13ea6ac70..5abd3eda3 100644 --- a/astrbot/core/astr_main_agent.py +++ b/astrbot/core/astr_main_agent.py @@ -845,14 +845,16 @@ def _apply_global_context_info(event: AstrMessageEvent, req: ProviderRequest) -> # Parse the original UMO to extract platform, message type, and session info try: parts = original_umo.split(":", 2) - if len(parts) == 3: - platform_id, message_type, session_id = parts - context_info = f"[Context: Platform={platform_id}, Type={message_type}, Session={session_id}]" - # Prepend context info to the user prompt - if req.prompt: - req.prompt = f"{context_info} {req.prompt}" - else: - req.prompt = context_info + if len(parts) != 3: + logger.warning( + f"Original UMO format is invalid (expected 3 parts): {original_umo}" + ) + return + + platform_id, message_type, session_id = parts + context_info = f"[Context: Platform={platform_id}, Type={message_type}, Session={session_id}]" + # Prepend context info to the user prompt + req.prompt = f"{context_info} {req.prompt or ''}" except Exception as e: logger.warning(f"Failed to parse original UMO for global context: {e}")