feat: add global unified context mode configuration and implementation

Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-03 16:59:17 +00:00
parent 093dab3c98
commit b8eb110cf4
3 changed files with 49 additions and 0 deletions
+30
View File
@@ -830,6 +830,33 @@ def _get_compress_provider(
return provider
def _apply_global_context_info(event: AstrMessageEvent, req: ProviderRequest) -> None:
"""Add platform and session information to user prompt when in global unified context mode."""
from astrbot.core.config.default import GLOBAL_UNIFIED_CONTEXT_UMO
if event.unified_msg_origin != GLOBAL_UNIFIED_CONTEXT_UMO:
return
# Get original UMO from extras
original_umo = event.get_extra("original_umo")
if not original_umo:
return
# 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
except Exception as e:
logger.warning(f"Failed to parse original UMO for global context: {e}")
async def build_main_agent(
*,
event: AstrMessageEvent,
@@ -888,6 +915,9 @@ async def build_main_agent(
if isinstance(req.contexts, str):
req.contexts = json.loads(req.contexts)
# Apply global context information if enabled
_apply_global_context_info(event, req)
if config.file_extract_enabled:
try:
await _apply_file_extract(event, req, config)
+4
View File
@@ -17,11 +17,15 @@ WEBHOOK_SUPPORTED_PLATFORMS = [
"lark",
]
# Constant UMO for global unified context mode
GLOBAL_UNIFIED_CONTEXT_UMO = "global::global"
# 默认配置
DEFAULT_CONFIG = {
"config_version": 2,
"platform_settings": {
"unique_session": False,
"global_unified_context_mode": False,
"rate_limit": {
"time": 60,
"count": 30,
@@ -72,11 +72,26 @@ class WakingCheckStage(Stage):
)
platform_settings = self.ctx.astrbot_config.get("platform_settings", {})
self.unique_session = platform_settings.get("unique_session", False)
self.global_unified_context_mode = platform_settings.get(
"global_unified_context_mode", False
)
async def process(
self,
event: AstrMessageEvent,
) -> None | AsyncGenerator[None, None]:
# apply global unified context mode
if self.global_unified_context_mode:
from astrbot.core.config.default import GLOBAL_UNIFIED_CONTEXT_UMO
original_umo = event.unified_msg_origin
event.unified_msg_origin = GLOBAL_UNIFIED_CONTEXT_UMO
# Store original UMO for reference in later stages
event.set_extra("original_umo", original_umo)
logger.debug(
f"Global unified context mode enabled. Changed UMO from {original_umo} to {GLOBAL_UNIFIED_CONTEXT_UMO}"
)
# apply unique session
if self.unique_session and event.message_obj.type == MessageType.GROUP_MESSAGE:
sid = build_unique_session_id(event)