fix: add exception handling to prevent agent loop crash
This commit is contained in:
@@ -258,6 +258,9 @@ class AgentLoop:
|
|||||||
msg = await asyncio.wait_for(self.bus.consume_inbound(), timeout=1.0)
|
msg = await asyncio.wait_for(self.bus.consume_inbound(), timeout=1.0)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
continue
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning("Error consuming inbound message: {}, continuing...", e)
|
||||||
|
continue
|
||||||
|
|
||||||
cmd = msg.content.strip().lower()
|
cmd = msg.content.strip().lower()
|
||||||
if cmd == "/stop":
|
if cmd == "/stop":
|
||||||
|
|||||||
@@ -564,6 +564,10 @@ def gateway(
|
|||||||
)
|
)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
console.print("\nShutting down...")
|
console.print("\nShutting down...")
|
||||||
|
except Exception:
|
||||||
|
import traceback
|
||||||
|
console.print("\n[red]Error: Gateway crashed unexpectedly[/red]")
|
||||||
|
console.print(traceback.format_exc())
|
||||||
finally:
|
finally:
|
||||||
await agent.close_mcp()
|
await agent.close_mcp()
|
||||||
heartbeat.stop()
|
heartbeat.stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user