Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:416rehman DeepZero LLM Backend Architecture

From Leeroopedia
Knowledge Sources
Domains LLM_Backend, Software_Architecture
Last Updated 2026-10-27 00:00 GMT

Overview

A pluggable backend architecture where LLM access is abstracted behind a registry-resolved interface, with each backend declaring its error taxonomy so the retry loop stays backend-agnostic.

Description

The LLM backend architecture decouples the pipeline's LLM calls from any specific LLM provider. Three layers form the stack:

  • LLMBackend (ABC): the contract. Defines raw_complete(), error role ClassVars, and optional pre-flight checks. Anything that can turn messages into text can be a backend.
  • CLIAgentBackend: reusable plumbing for backends that shell out to a CLI. Handles binary discovery, subprocess execution, prompt flattening, and error classification. Subclasses only declare build_argv() and parse_output().
  • LLMProvider: the retry loop. Drives a backend's raw_complete() with adaptive backoff based on the backend's declared error roles.

The registry maps model string schemes (e.g., "claude-code" in "claude-code/sonnet") to backend classes. Unregistered schemes fall through to the default backend (LiteLLM), which covers every API-key endpoint it supports.

The error taxonomy is the key abstraction. Each backend declares which exception classes fill each retry role:

  • rate_limit_error: retry with escalating backoff.
  • context_window_error: do not retry.
  • non_retryable_errors: do not retry (e.g., auth).
  • retryable_errors: retry with exponential backoff.

The LLMProvider's retry loop reasons about these roles, never about vendor-specific classes. Adding a new backend means declaring its error roles, not modifying the retry logic.

Usage

Use this architecture when:

  • A system needs to support multiple LLM providers (CLI-based, API-key-based)
  • Retry logic should be shared across backends without being hardcoded to any
  • Extension should be by subclassing, not by patching core logic
  • Model strings should transparently resolve to the correct backend

Theoretical Basis

# Abstract architecture (NOT real implementation)

# Registry: scheme -> backend class
REGISTRY = {"claude-code": ClaudeCodeBackend, "litellm": LiteLLMBackend, ...}
DEFAULT = LiteLLMBackend

def resolve(model_string):
    scheme = model_string.split("/")[0]
    return REGISTRY.get(scheme, DEFAULT)

# Provider: drives backend with role-based retry
class LLMProvider:
    def __init__(self, model):
        self.backend = resolve(model)(model)

    def complete(self, messages):
        for attempt in range(max_retries):
            try:
                return self.backend.raw_complete(messages)
            except self.backend.rate_limit_error:
                sleep(backoff); backoff *= 2
            except self.backend.context_window_error:
                raise  # not retryable

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment