Skip to main content

LLM actor: pool, circuit breaker, retries, metrics

Project description

LLM Actor: Resilient Throughput, Structured Output & Tool Calling

PyPI version Tests status License: MIT Python 3.13

Documentation: English | Russian

LLM Actor is a high-performance orchestration layer designed to handle Large Language Model (LLM) requests at scale. Inspired by the Actor Model, it solves the "last mile" of production LLM integration: handling concurrency, ensuring resilience, and providing guaranteed structured output and agentic tool calling without the boilerplate.


Why LLM Actor?

Most developers start with simple API calls. But when you move to production, you quickly hit:

  • Rate Limit Exhaustion: No global coordination for token usage.
  • Provider Outages: One slow response can hang your entire app.
  • Unreliable Parsing: Hard to get guaranteed Structured Output from raw strings.
  • Complex Agentic Flows: Orchestrating Tool Calling (especially in parallel) is error-prone.
  • Lack of Priority: Background tasks block high-priority user UI requests.

LLM Actor fixes this. It’s not just a wrapper; it’s a resilient worker pool built to sit between your application logic and your LLM providers.


Key Features

  • High Throughput Actor Pool: Efficiently manage hundreds of concurrent requests using a dedicated worker pool.
  • Intelligent Resilience:
    • Circuit Breaker: Detects provider failures and "fails fast" 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 & Self-Hosted:
    • Native support: 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.

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.


Built for Reliability

Mechanism Description
Actor Supervision If a worker process crashes, it's automatically restarted by the supervisor.
Backpressure Prevents system overload by limiting the number of active tasks.
Otel Tracing Visualize latency including "Queue Wait Time" vs "In-LLM Time".

Contributing

We love contributions! Whether it's adding a new provider adapter, fixing a bug, or improving documentation.

  1. Fork the repo.
  2. Install dev dependencies: uv sync --all-extras --group dev
  3. Run tests: pytest tests/unit
  4. 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:

  1. Basic Generation: Quick start with any provider.
  2. Structured Output: Extract data into Pydantic models.
  3. 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

llm_actor-0.1.0.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_actor-0.1.0-py3-none-any.whl (38.2 kB view details)

Uploaded Python 3

File details

Details for the file llm_actor-0.1.0.tar.gz.

File metadata

  • Download URL: llm_actor-0.1.0.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.3

File hashes

Hashes for llm_actor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 18aa00cc91f2234c6fbfd73df210c89d41b3d069f178d8e14f09620bd656d468
MD5 24dfe91f14a2459a0a30b5f5d9bb1512
BLAKE2b-256 5f228506aa9ce5d8ed914e715f1fd3218ecbc9717f653657b26f4229e82eec6c

See more details on using hashes here.

File details

Details for the file llm_actor-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: llm_actor-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 38.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.3

File hashes

Hashes for llm_actor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9e3bb0c121b5c051c94fee378dfa68f4f315d0038b2ac0204163beb6e0cc187
MD5 8ee6fcdb31c0558ccf6f81bd1c521154
BLAKE2b-256 5e4e89728c021516d1d45cbf0dab59a9c12aff2f78075b3f03b015f0a8684295

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page