diff --git a/gateway/platforms/api_server.py b/gateway/platforms/api_server.py index 7f4c8e8d6..9687472f5 100644 --- a/gateway/platforms/api_server.py +++ b/gateway/platforms/api_server.py @@ -902,7 +902,7 @@ class APIServerAdapter(BasePlatformAdapter): return time.monotonic() # Stream content chunks as they arrive from the agent - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() while True: try: delta = await loop.run_in_executor(None, lambda: stream_q.get(timeout=0.5)) @@ -1241,7 +1241,7 @@ class APIServerAdapter(BasePlatformAdapter): await _emit_text_delta(it) # Other types (non-string, non-tuple) are silently dropped. - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() while True: try: item = await loop.run_in_executor(None, lambda: stream_q.get(timeout=0.5)) @@ -2004,7 +2004,7 @@ class APIServerAdapter(BasePlatformAdapter): callers (e.g. the SSE writer) to call ``agent.interrupt()`` from another thread to stop in-progress LLM calls. """ - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() def _run(): agent = self._create_agent( diff --git a/gateway/run.py b/gateway/run.py index 9c2b5b1db..8ea699145 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -835,7 +835,7 @@ class GatewayRunner: session_key: Optional[str] = None, ): """Run the sync memory flush in a thread pool so it won't block the event loop.""" - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() await loop.run_in_executor( None, self._flush_memories_for_session, @@ -3777,7 +3777,7 @@ class GatewayRunner: ) _hyg_agent._print_fn = lambda *a, **kw: None - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() _compressed, _ = await loop.run_in_executor( None, lambda: _hyg_agent._compress_context( @@ -6265,7 +6265,7 @@ class GatewayRunner: if compress_start >= compress_end: return "Nothing to compress yet (the transcript is still all protected context)." - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() compressed, _ = await loop.run_in_executor( None, lambda: tmp_agent._compress_context(msgs, "", approx_tokens=approx_tokens, focus_topic=focus_topic) @@ -6650,7 +6650,7 @@ class GatewayRunner: from hermes_state import SessionDB from agent.insights import InsightsEngine - loop = _asyncio.get_event_loop() + loop = _asyncio.get_running_loop() def _run_insights(): db = SessionDB() @@ -6667,7 +6667,7 @@ class GatewayRunner: async def _handle_reload_mcp_command(self, event: MessageEvent) -> str: """Handle /reload-mcp command -- disconnect and reconnect all MCP servers.""" - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() try: from tools.mcp_tool import shutdown_mcp_servers, discover_mcp_tools, _servers, _lock @@ -8388,7 +8388,7 @@ class GatewayRunner: stream_consumer_holder = [None] # Mutable container for stream consumer # Bridge sync step_callback → async hooks.emit for agent:step events - _loop_for_step = asyncio.get_event_loop() + _loop_for_step = asyncio.get_running_loop() _hooks_ref = self.hooks def _step_callback_sync(iteration: int, prev_tools: list) -> None: @@ -9740,7 +9740,7 @@ async def start_gateway(config: Optional[GatewayConfig] = None, replace: bool = def restart_signal_handler(): runner.request_restart(detached=False, via_service=True) - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() if threading.current_thread() is threading.main_thread(): for sig in (signal.SIGINT, signal.SIGTERM): try: