Skip to content

L0 for Python - Initial Release (Full Lifecycle + Event Compatibility)

Choose a tag to compare

@LZL0 LZL0 released this 08 Dec 04:19

This is the first release of L0 for Python, the deterministic execution substrate for reliable AI streaming - now with full lifecycle parity and event-type compatibility with the TypeScript implementation.

L0 provides the missing reliability layer for all AI streams: deterministic token delivery, retries, fallbacks, guardrails, drift detection, checkpoint resumption, network protection, and full observability - all transparently wrapped around any LLM provider stream.

This release is built for production workloads and ships with 1,800+ tests, real adapter integrations for OpenAI and LiteLLM (100+ providers), and a fully instrumented streaming runtime covering 25+ structured lifecycle events.


🔥 Key Highlights

Full Lifecycle Compatibility

The Python version now includes the complete deterministic lifecycle flow - retries, fallbacks, checkpoints, resume logic, guardrail phases, drift detection, tool-call phases, and completion flow identical in semantics to the TypeScript implementation.
All lifecycle callbacks (on_start, on_event, on_violation, on_retry, on_fallback, on_resume, on_timeout, etc.) are implemented and follow the same event order and guarantees.

🎛️ Central Event Bus with 25+ Structured Event Types

This release introduces the full observability and event-sourcing infrastructure:

  • SESSION_START, STREAM_INIT, ADAPTER_DETECTED
  • TIMEOUT_*, RETRY_*, FALLBACK_*
  • GUARDRAIL_*, DRIFT_*, CHECKPOINT_SAVED
  • TOOL_REQUESTED, TOOL_RESULT, TOOL_ERROR
  • SESSION_SUMMARY & SESSION_END

These events enable complete introspection, replay, debugging, supervision, and telemetry in production systems.

Deterministic Streaming Runtime

  • Token-by-token normalization
  • Timeout enforcement (initial + inter-token)
  • Checkpointing and last-known-good-token resumption
  • Drift detection & pattern-based guardrails
  • Network protection across 12+ failure patterns

🔁 Smart Retries & Fallbacks

  • Distinguishes model errors from network/transient errors
  • Sequential fallback chain with on_fallback telemetry
  • AWS-style fixed-jitter backoff by default
  • Full retry/fallback reasoning surfaced through lifecycle events

🧱 Structured Output with Automatic Repair

  • Native Pydantic integration
  • Corrects malformed JSON (missing braces, broken fences, trailing commas)
  • Guaranteed schema validity

🔌 Adapters

  • OpenAI adapter (auto-detected)
  • LiteLLM adapter (100+ providers)
  • Full API-compatible adapter protocol for custom providers

🧪 Battle-Tested

  • 1,800+ unit tests
  • 100+ integration tests simulating real streaming conditions

📦 Installation

pip install ai2070-l0
# or
pip install ai2070-l0[openai]
pip install ai2070-l0[litellm]

🏁 Quick Example

import asyncio
from openai import AsyncOpenAI
import l0

async def main():
    client = l0.wrap(AsyncOpenAI())

    response = await client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": "Hello!"}],
        stream=True,
    )

    async for event in response:
        if event.is_token:
            print(event.text, end="", flush=True)

asyncio.run(main())