Add API timeout to all backends + mesh-aware system prompt

All three LLM backends (Google, OpenAI, Anthropic) now wrap API calls
in asyncio.wait_for() using config.timeout (default 30s). Previously
Gemini could hang indefinitely with grounding+AFC enabled.

Router catches TimeoutError with user-friendly "request timed out" message.
Empty context buffer now injects "[No recent mesh traffic observed yet.]"
so the LLM knows the capability exists even when buffer is empty.
Default system prompt updated to mention mesh awareness.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ubuntu 2026-02-25 07:27:39 +00:00
commit 1172b9b67f
5 changed files with 54 additions and 17 deletions

View file

@ -1,5 +1,6 @@
"""Message routing logic for MeshAI."""
import asyncio
import logging
import re
from dataclasses import dataclass
@ -159,6 +160,10 @@ class MessageRouter:
"\n\n--- Recent mesh traffic (for context only, not messages to you) ---\n"
+ context_block
)
else:
system_prompt += (
"\n\n[No recent mesh traffic observed yet.]"
)
try:
response = await self.llm.generate(
@ -166,6 +171,9 @@ class MessageRouter:
system_prompt=system_prompt,
max_tokens=500,
)
except asyncio.TimeoutError:
logger.error("LLM request timed out")
response = "Sorry, request timed out. Try again."
except Exception as e:
logger.error(f"LLM generation error: {e}")
response = "Sorry, I encountered an error. Please try again."