fix: add exception handling to prevent agent loop crash

This commit is contained in:
chengyongru
2026-03-14 18:14:35 +08:00
committed by Xubin Ren
parent a1241ee68c
commit a2acacd8f2
2 changed files with 7 additions and 0 deletions

View File

@@ -258,6 +258,9 @@ class AgentLoop:
msg = await asyncio.wait_for(self.bus.consume_inbound(), timeout=1.0)
except asyncio.TimeoutError:
continue
except Exception as e:
logger.warning("Error consuming inbound message: {}, continuing...", e)
continue
cmd = msg.content.strip().lower()
if cmd == "/stop":

View File

@@ -564,6 +564,10 @@ def gateway(
)
except KeyboardInterrupt:
console.print("\nShutting down...")
except Exception:
import traceback
console.print("\n[red]Error: Gateway crashed unexpectedly[/red]")
console.print(traceback.format_exc())
finally:
await agent.close_mcp()
heartbeat.stop()