LLM actor: pool, circuit breaker, retries, metrics
Project description
LLM Actor: High-Performance Orchestration for Self-Hosted Inference
Documentation: English | Russian
LLM Actor is an efficient actor pool for shared self-hosted inference (vLLM, Ollama) or proxy services. It covers the “last mile”: managing concurrent requests, prioritizing them, and delivering guaranteed structured output without extra boilerplate.
Why LLM Actor?
While cloud providers have their own rate limits, production self-hosted inference (or shared cloud endpoints) hits other bottlenecks:
- GPU Oversaturation: Too many concurrent requests crash the inference engine.
- Queue Hoarding: Background batch tasks block high-priority user UI requests.
- Unreliable Structuring: Getting guaranteed Structured Output from local models is hard.
- Lack of Resilience: One slow response shouldn't hang your entire orchestration layer.
LLM Actor addresses these via Global Concurrency Control (actor pool) and a Global Circuit Breaker. It prioritizes reactive resilience over proactive token counting, making it a perfect fit for private cloud infrastructure.
Key Features
- Configurable Actor Pool: Efficiently queue and dispatch requests across a pool of managed workers.
- Global Resilience:
- Circuit Breaker: Failure state is shared within the process. If one worker detects a provider failure, all workers in the pool "fail fast" immediately to protect your infrastructure.
- Exponential Backoff: Automatic retries for transient HTTP errors (429, 502, 503).
- Semantic Validation: Typed response validation with Pydantic; auto-retry on schema mismatch.
- Built-in Tool Calling Loop: Native support for complex agentic flows. Run multiple tools in parallel to slash latency.
- Global Priority Queue: Assign priorities to tasks. Ensure user-facing interactions always jump to the front of the line.
- Multi-Provider Support:
- Native adapters: OpenAI, Anthropic, Sber GigaChat.
- Proxy support: vLLM, Ollama, and any OpenAI-compatible endpoint.
- Deep Observability: Full OpenTelemetry integration. Trace every request from the queue through the actor to the final provider response.
- Caller context & extra HTTP headers: Python
contextvarsset beforegenerate()are restored in the worker when your LLM client runs;LLMRequest.extra_headersis forwarded to the OpenAI and Anthropic SDKs (GigaChat logs a warning and ignores extra headers).
Limitations
To keep LLM Actor lightweight and universal, we made specific architectural trade-offs:
- In-process state: Circuit Breaker status and Queue state are local to the process. Designed for single-node deployment or vertical scaling.
- No proactive token rate limiting: We don't counting tokens before sending them. Ideal for self-hosted inference (vLLM/Ollama) where TPM quotas aren't the primary bottleneck. For external APIs with strict TPM limits, we rely on Reactive Resilience (Backoff + CB).
- Single-provider per pool: A pool is tied to a single client instance. For multi-provider routing with independent circuit breaking, use separate
LLMActorServiceinstances.
Installation
# Install core package
pip install llm-actor
# Install with your preferred providers
pip install "llm-actor[openai,anthropic]"
# Full installation (all providers + metrics)
pip install "llm-actor[all]"
Quick Start: 60 Seconds to Scale
Create a service and start processing tasks with priority and auto-recovery:
from llm_actor import LLMActorService, LLMActorSettings, Priority
from pydantic import BaseModel
# 1. Setup Service
service = LLMActorService.from_openai(
api_key="sk-...",
model="gpt-4o",
settings=LLMActorSettings(LLM_NUM_ACTORS=10) # 10 concurrent workers
)
# 2. Define Output Schema
class UserProfile(BaseModel):
name: str
skills: list[str]
# 3. Use via Context Manager (handles Start/Stop automatically)
async with service:
# 4. Queue a High-Priority Task
request = service.request(
"Extract profile from: Alex is a Senior Python Dev with LLM expertise.",
response_model=UserProfile,
priority=Priority.HIGH
)
# 5. Get Your Results (Blocking or Async)
result = request.get()
print(f"Found: {result.name} with skills: {result.skills}")
Provider Support Matrix
| Provider | Generations | Parallel Tools | Tested |
|---|---|---|---|
| OpenAI / compatible | Yes | Yes | Yes Full |
| Anthropic | Yes | Yes | Yes Full |
| vLLM / Ollama | Yes | Yes* | Yes Full |
| Sber GigaChat | Yes | Warning | Experimental |
*Tool calling in vLLM requires specific server-side flags.
Architecture: Reactive Resilience
LLM Actor is built as an In-Process Orchestrator. Instead of complex pre-emptive traffic shaping, we use a reactive chain: Exponential Backoff (managed by the client) -> Circuit Breaker (managed by the pool).
This approach minimizes internal overhead and is ideal for self-hosted inference (like vLLM), where TPM quotas are absent and reactive 429 handling is sufficient. It prevents GPU memory saturation by limiting active connections (LLM_NUM_ACTORS) while ensuring high-priority requests are always processed first.
Contributing
We love contributions! Whether it's adding a new provider adapter, fixing a bug, or improving documentation.
- Fork the repo.
- Install dev dependencies:
uv sync --all-extras --group dev - Run tests:
pytest tests/unit - Submit your PR!
License
Distributed under the MIT License. See LICENSE for more information.
Examples & Advanced Usage
Check out the examples/ directory for complete, runnable scripts:
- Basic Generation: Quick start with any provider.
- Structured Output: Extract data into Pydantic models.
- Tool Calling: Orchestrate complex agentic loops with parallel tool execution.
Built for the AI Developer Community.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_actor-0.2.0.tar.gz.
File metadata
- Download URL: llm_actor-0.2.0.tar.gz
- Upload date:
- Size: 27.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e932bb56e7a0ef860bbc22da0ac410df0626e38a069184ab66f3c2a655f0005
|
|
| MD5 |
33f305eb2183b521cbc01509d41a78a3
|
|
| BLAKE2b-256 |
e3d10183a09c5b935d8a855e381446c7dc0cff84a6fc203ce0e36aea89bc9d69
|
File details
Details for the file llm_actor-0.2.0-py3-none-any.whl.
File metadata
- Download URL: llm_actor-0.2.0-py3-none-any.whl
- Upload date:
- Size: 39.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c1e27cf67623b20bbf887622d845234a8816c4fa6c089806849e5452b84df5a
|
|
| MD5 |
1a2888f6eb83980cf023019e973f63ca
|
|
| BLAKE2b-256 |
fbc61cbb0cee1e6ccc05e43ee9acc21fa0b7e3ca0848e0a77707544d712654ac
|