@@ -227,10 +227,18 @@ def _set_llm_error_message(event: AstrMessageEvent, message: str) -> None:
227227 event .set_extra (LLM_ERROR_MESSAGE_EXTRA_KEY , message )
228228
229229
230- def _select_provider (
230+ async def _select_provider (
231231 event : AstrMessageEvent , plugin_context : Context
232232) -> Provider | None :
233- """Select chat provider for the event."""
233+ """Select the chat provider for an event.
234+
235+ Args:
236+ event: Message event that may contain an explicit provider selection.
237+ plugin_context: Plugin context used to resolve configured providers.
238+
239+ Returns:
240+ Selected chat provider, or None if selection fails.
241+ """
234242 sel_provider = event .get_extra ("selected_provider" )
235243 if sel_provider and isinstance (sel_provider , str ):
236244 provider = plugin_context .get_provider_by_id (sel_provider )
@@ -252,7 +260,9 @@ def _select_provider(
252260 return None
253261 return provider
254262 try :
255- return plugin_context .get_using_provider (umo = event .unified_msg_origin )
263+ return await plugin_context .get_using_provider_async (
264+ umo = event .unified_msg_origin
265+ )
256266 except ValueError as exc :
257267 logger .error ("Error occurred while selecting provider: %s" , exc )
258268 _set_llm_error_message (event , f"LLM 请求失败:{ exc } " )
@@ -916,7 +926,9 @@ async def _process_quote_message(
916926 compress_path = None
917927 prov = plugin_context .get_provider_by_id (img_cap_prov_id )
918928 if prov is None :
919- prov = plugin_context .get_using_provider (event .unified_msg_origin )
929+ prov = await plugin_context .get_using_provider_async (
930+ event .unified_msg_origin
931+ )
920932
921933 if prov and isinstance (prov , Provider ):
922934 path = await image_seg .convert_to_file_path ()
@@ -1292,11 +1304,21 @@ def _apply_web_search_citation_prompt(
12921304 req .system_prompt = f"{ system_prompt } \n { WEB_SEARCH_CITATION_PROMPT } \n "
12931305
12941306
1295- def _get_compress_provider (
1307+ async def _get_compress_provider (
12961308 config : MainAgentBuildConfig ,
12971309 plugin_context : Context ,
12981310 event : AstrMessageEvent | None = None ,
12991311) -> Provider | None :
1312+ """Resolve the provider used for context compression.
1313+
1314+ Args:
1315+ config: Main agent build configuration.
1316+ plugin_context: Plugin context used to resolve providers.
1317+ event: Optional event used for session-specific fallback selection.
1318+
1319+ Returns:
1320+ Compression provider, or None if compression is disabled or unavailable.
1321+ """
13001322 if config .context_limit_reached_strategy != "llm_compress" :
13011323 return None
13021324 if config .llm_compress_provider_id :
@@ -1310,7 +1332,9 @@ def _get_compress_provider(
13101332 # fallback: use current chat provider for this session
13111333 if event :
13121334 try :
1313- return plugin_context .get_using_provider (umo = event .unified_msg_origin )
1335+ return await plugin_context .get_using_provider_async (
1336+ umo = event .unified_msg_origin
1337+ )
13141338 except ValueError :
13151339 pass
13161340 return None
@@ -1398,7 +1422,7 @@ async def build_main_agent(
13981422
13991423 If apply_reset is False, will not call reset on the agent runner.
14001424 """
1401- provider = provider or _select_provider (event , plugin_context )
1425+ provider = provider or await _select_provider (event , plugin_context )
14021426 if provider is None :
14031427 logger .info ("未找到任何对话模型(提供商),跳过 LLM 请求处理。" )
14041428 if not event .get_extra (LLM_ERROR_MESSAGE_EXTRA_KEY ):
@@ -1699,7 +1723,11 @@ async def build_main_agent(
16991723 streaming = config .streaming_response ,
17001724 llm_compress_instruction = config .llm_compress_instruction ,
17011725 llm_compress_keep_recent_ratio = config .llm_compress_keep_recent_ratio ,
1702- llm_compress_provider = _get_compress_provider (config , plugin_context , event ),
1726+ llm_compress_provider = await _get_compress_provider (
1727+ config ,
1728+ plugin_context ,
1729+ event ,
1730+ ),
17031731 truncate_turns = config .dequeue_context_length ,
17041732 enforce_max_turns = config .max_context_length ,
17051733 tool_schema_mode = config .tool_schema_mode ,
0 commit comments