Run the agent loop, processing messages from the bus.
(self)
| 126 | logger.info(f"DeepCode tools registered (API: {deepcode_url})") |
| 127 | |
| 128 | async def run(self) -> None: |
| 129 | """Run the agent loop, processing messages from the bus.""" |
| 130 | self._running = True |
| 131 | logger.info("Agent loop started") |
| 132 | |
| 133 | while self._running: |
| 134 | try: |
| 135 | # Wait for next message |
| 136 | msg = await asyncio.wait_for(self.bus.consume_inbound(), timeout=1.0) |
| 137 | |
| 138 | # Process it |
| 139 | try: |
| 140 | response = await self._process_message(msg) |
| 141 | if response: |
| 142 | await self.bus.publish_outbound(response) |
| 143 | except Exception as e: |
| 144 | logger.error(f"Error processing message: {e}") |
| 145 | # Send error response |
| 146 | await self.bus.publish_outbound( |
| 147 | OutboundMessage( |
| 148 | channel=msg.channel, |
| 149 | chat_id=msg.chat_id, |
| 150 | content=f"Sorry, I encountered an error: {str(e)}", |
| 151 | ) |
| 152 | ) |
| 153 | except asyncio.TimeoutError: |
| 154 | continue |
| 155 | |
| 156 | def stop(self) -> None: |
| 157 | """Stop the agent loop.""" |
no test coverage detected