Implementation:AMAP ML SkillClaw AsyncLLMClient
| Knowledge Sources | |
|---|---|
| Domains | LLM_Client, Async_IO |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for OpenAI-compatible async chat completions with automatic retries and compatibility handling, provided by the SkillClaw evolve server package.
Description
The AsyncLLMClient class wraps the synchronous `openai` SDK, dispatching all calls to background threads via `asyncio.to_thread` so the event loop stays free during HTTP round-trips. It includes retry logic (up to 6 attempts with exponential backoff), compatibility handling (removing unsupported `temperature` parameter, falling back to streaming), and model-specific temperature normalization. Used by the evolution pipeline for all LLM calls (summarization, judging, skill evolution, verification).
Usage
Import and use when you need to:
- Make async LLM chat completion calls in the evolution pipeline
- Build a reusable LLM client with retry and compatibility logic
- Understand the OpenAI SDK wrapper pattern used by SkillClaw
Code Reference
Source Location
- Repository: SkillClaw
- File: `evolve_server/core/llm_client.py:L19-119`
Signature
class AsyncLLMClient:
"""OpenAI-compatible async chat client.
All calls are dispatched to a background thread so the event loop stays
free while the synchronous openai SDK performs the HTTP round-trip.
"""
def __init__(
self,
api_key: str = "",
base_url: str = "https://api.openai.com/v1",
model: str = "gpt-4o",
max_tokens: int = 100000,
temperature: float = 0.4,
) -> None:
async def chat(self, messages: list[dict[str, str]], **kwargs: Any) -> str:
"""Send a chat completion request and return the assistant content.
Retries up to 6 times with exponential backoff.
Handles 'temperature not supported' and 'stream must be true' errors.
"""
Import
from evolve_server.core.llm_client import AsyncLLMClient
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| api_key | str | No | API key (falls back to OPENAI_API_KEY env var) |
| base_url | str | No | API base URL (default OpenAI) |
| model | str | No | Model name (default "gpt-4o") |
| max_tokens | int | No /// Max completion tokens (default 100000) | |
| temperature | float | No /// Sampling temperature (default 0.4) | |
| messages | list[dict] | Yes (chat) | Chat messages with role and content |
| kwargs | Any | No | Additional kwargs (max_tokens, temperature overrides) |
Outputs
| Name | Type | Description |
|---|---|---|
| chat() returns | str | Assistant response content text |
Usage Examples
Basic Chat
import asyncio
from evolve_server.core.llm_client import AsyncLLMClient
llm = AsyncLLMClient(
api_key="sk-...",
base_url="https://api.openai.com/v1",
model="gpt-4o",
max_tokens=4096,
temperature=0.4,
)
response = asyncio.run(llm.chat([
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain QLoRA in one sentence."},
]))
print(response)
With Custom Parameters
response = asyncio.run(llm.chat(
messages=[
{"role": "user", "content": "Generate a skill description."},
],
max_tokens=2000,
temperature=0.7,
))
Related Pages
Implements Principle
- Principle:AMAP_ML_SkillClaw_LLM_Client_Abstraction
- Principle:AMAP_ML_SkillClaw_Distributed_Validation