Implementation:416rehman DeepZero LLMProvider
| Knowledge Sources | |
|---|---|
| Domains | LLM_Backend, Retry_Logic |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
LLM completion provider with adaptive retry and backoff, driving a backend's retry roles (rate-limit, context-window, non-retryable, retryable) without knowledge of any specific backend.
Description
The LLMProvider class is the LLM abstraction layer between pipeline stages (which call ctx.llm.complete()) and concrete backends (which implement raw_complete()). The provider resolves the backend from the model string at construction time, then drives a retry loop over the backend's declared error roles.
The retry loop reasons about four error roles, each declared by the backend:
- rate_limit_error: rate/usage limit hit. Retry with exponential backoff. Backoff doubles on each rate-limit, capped at max_backoff.
- context_window_error: prompt exceeded the context window. Do not retry—this will not improve. Raise immediately.
- non_retryable_errors: e.g., auth failures. Surface immediately without burning retries.
- retryable_errors: e.g., network errors, server errors. Retry with exponential backoff (2^attempt).
On success, backoff decays toward initial_backoff (multiplied by backoff_decay), so a subsequent rate-limit after a successful call starts from a lower backoff.
The provider is backend-agnostic: it knows nothing about litellm, the claude CLI, or any specific vendor. It only reads the error role ClassVars the backend declares. This is the key extension point: adding a new backend means declaring its error roles, not modifying the retry logic.
Usage
- Pipeline use: ctx.llm.complete(messages, max_retries=3, initial_backoff=2.0, max_backoff=60.0, backoff_decay=0.7)
- The provider is constructed by the CLI's _build_runner() and passed to processors via ProcessorContext.llm.
Code Reference
Source Location
- Repository: DeepZero
- File: src/deepzero/engine/llm.py
Signature
class LLMProvider:
def __init__(self, model: str, **kwargs: Any): ...
def complete(
self,
messages: list[dict[str, str]],
max_retries: int = 3,
initial_backoff: float = 2.0,
max_backoff: float = 60.0,
backoff_decay: float = 0.7,
**kwargs: Any,
) -> str: ...
def check_auth(self) -> str | None: ...
@property
def provider_name(self) -> str: ...
@property
def model_name(self) -> str: ...
Import
from deepzero.engine.llm import LLMProvider
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | str | Yes | Model string (e.g., "claude-code/claude-opus-5", "openai/gpt-4o") |
| messages | list[dict] | Yes (complete) | Chat messages: [{"role": "user", "content": "..."}] |
| max_retries | int | No | Max retry attempts (default 3) |
| initial_backoff | float | No | Initial backoff seconds (default 2.0) |
| max_backoff | float | No | Max backoff seconds (default 60.0) |
| backoff_decay | float | No | Backoff decay on success (default 0.7) |
Outputs
| Name | Type | Description |
|---|---|---|
| complete() returns | str | LLM response text |
| check_auth() returns | None | None if ready, else human-readable reason |
Usage Examples
Direct Use
from deepzero.engine.llm import LLMProvider
provider = LLMProvider("openai/gpt-4o")
response = provider.complete(
messages=[{"role": "user", "content": "Analyze this driver for vulnerabilities: ..."}],
max_retries=3,
initial_backoff=2.0,
max_backoff=60.0,
)
print(response)
Pipeline Context (Automatic)
# The provider is built by the CLI and passed to processors via ctx.llm.
# In a processor's process() method:
def process(self, ctx, entry):
response = ctx.llm.complete(
[{"role": "user", "content": prompt_text}],
max_retries=3,
)
return ProcessorResult.ok(data={"assessment": response})
Related Pages
Implements Principle
- Principle:416rehman_DeepZero_Adaptive_Retry_Backoff
- Principle:416rehman_DeepZero_LLM_Backend_Dispatch
- Principle:416rehman_DeepZero_LLM_Backend_Architecture
- Principle:416rehman_DeepZero_LLM_Provider_Interface