How the LLM Service works
masterThe LLM service (app/services/llm/) provides a resilient wrapper for all language model calls. Instead of calling model providers directly, you call llm_service.call(messages).
The service manages:
- Automatic Retries: Handles transient errors like rate limits or timeouts using exponential backoff.
- Circular Fallback: If a model fails after its maximum retries, the service automatically switches to the next model in the registry. It follows a circular path through the registry and stops after one full cycle.
- Total Timeout: A global timeout (
LLM_TOTAL_TIMEOUT) ensures the entire operation (including all retries and fallbacks) does not exceed a specific duration. - Tool Binding: Tools are bound to the model at startup and are automatically re-bound whenever the service switches to a fallback model.