Principle:AMAP ML SkillClaw LLM Client Abstraction
| Knowledge Sources | |
|---|---|
| Domains | LLM_Client, Async_IO |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
An LLM client abstraction that wraps synchronous OpenAI-compatible SDKs with async dispatch, automatic retries, exponential backoff, and compatibility handling for provider-specific quirks.
Description
LLM client abstraction addresses the problem of making reliable LLM API calls from async applications. The SkillClaw pattern wraps the synchronous `openai` SDK in `asyncio.to_thread` calls, keeping the event loop free during HTTP round-trips. It includes retry logic (up to 6 attempts with exponential backoff and jitter), compatibility handling (removing unsupported `temperature` parameter, falling back to streaming when required), and model-specific normalization. Two variants exist: `AsyncLLMClient` (evolve server, async) and `run_llm` (client proxy, synchronous, supports Bedrock).
Usage
Use this principle when designing systems that need:
- Async LLM clients in event-loop-based applications
- Retry logic with exponential backoff
- Provider compatibility handling
- Multi-provider routing (OpenAI, Bedrock)
Theoretical Basis
The retry pattern with exponential backoff:
# Abstract algorithm (NOT real implementation)
async def chat_with_retries(client, messages, max_retries=6):
for attempt in range(max_retries):
try:
return await asyncio.to_thread(client.chat, messages)
except RetryableError:
if attempt < max_retries - 1:
await sleep(min(2**attempt + random(), 30))
else:
raise