Skip to main content

The kernel layer for production AI agents - protocol-based, type-safe, zero framework lock-in

Project description

lionpride

PyPI version Python License CI codecov Code style: ruff

Production-ready primitives for multi-agent workflow orchestration.

⚠️ Alpha/Experimental - API unstable. For research and development use. Originated from lionagi v0.

Features

  • Model Agnostic - Built-in providers for OpenAI-compatible APIs, Anthropic, Gemini
  • LNDL - Domain-specific language for LLM structured output and enhanced reasoning
  • Declarative Workflows - Report/Form system for multi-step agent pipelines
  • Async Native - Operation graph building, dependency-aware execution
  • Modular Architecture - Protocol-based composition, zero framework lock-in
  • 99%+ Test Coverage - Production-hardened with comprehensive test suites

Installation

pip install lionpride

Quick Start

import asyncio
from lionpride import Session, iModel
from lionpride.operations.operate import generate, GenerateParams

# Create model and session
model = iModel(provider="openai", model="gpt-4o-mini")
session = Session(default_generate_model=model)
branch = session.create_branch(name="main", resources={model.name})

async def main():
    # Simple text generation
    result = await generate(
        session, branch,
        params=GenerateParams(instruction="What is 2 + 2?", return_as="text"),
    )
    print(result)  # "4" or similar

asyncio.run(main())

Core Concepts

Session & Branch

Session orchestrates messages, services, and operations. Branch is a named conversation thread with capability-based access control.

from lionpride import Session, iModel

# Session with default model
model = iModel(provider="openai", model="gpt-4o-mini")
session = Session(default_generate_model=model)

# Branch with capability and resource restrictions
branch = session.create_branch(
    name="restricted",
    capabilities={"AnalysisModel"},  # Only these output types allowed
    resources={"gpt-4o-mini"},        # Only these services allowed
)

Operations

Operations are composable building blocks for agent workflows:

from pydantic import BaseModel
from lionpride.operations.operate import operate, OperateParams, GenerateParams

class Insights(BaseModel):
    summary: str
    score: float

# Branch must have capability for output field
branch = session.create_branch(capabilities={"insights"}, resources={model.name})

# Structured output with validation
params = OperateParams(
    generate=GenerateParams(
        instruction="Analyze this data",
        request_model=Insights,
    ),
    capabilities={"insights"},  # Explicit capability declaration
)

result = await operate(session, branch, params)
print(result.insights)  # Insights(summary="...", score=0.85)

Services

ServiceRegistry manages models and tools with O(1) name lookup:

from lionpride import Session, iModel, ServiceRegistry

# Register multiple models
registry = ServiceRegistry()
registry.register(iModel(provider="openai", model="gpt-4o", name="gpt4"))
registry.register(iModel(provider="anthropic", model="claude-3-5-sonnet", name="claude"))

session = Session(services=registry)
branch = session.create_branch(resources={"gpt4", "claude"})  # Access to both

Declarative Workflows

Report and Form enable multi-step agent pipelines with automatic dependency resolution. Model docstrings serve as agent instructions:

from pydantic import BaseModel
from lionpride.work import Report, flow_report

class Analysis(BaseModel):
    '''Analyze the topic and provide insights.
    Focus on actionable recommendations.'''
    summary: str
    recommendations: list[str]

class MyReport(Report):
    analysis: Analysis | None = None  # Schema attribute (docstring = instruction)

    assignment: str = "topic -> analysis"
    form_assignments: list[str] = ["topic -> analysis"]

report = MyReport()
report.initialize(topic="AI coding assistants")
result = await flow_report(session, report, branch=branch)

Architecture

lionpride/
├── core/           # Primitives: Element, Pile, Flow, Graph, Event
├── session/        # Session, Branch, Message management
├── services/       # iModel, Tool, ServiceRegistry, MCP integration
├── operations/     # operate, react, communicate, generate, parse
├── work/           # Declarative workflows: Report, Form, flow_report
├── rules/          # Validation rules and auto-correction
├── types/          # Spec, Operable, type system
├── lndl/           # LNDL parser and resolver
└── ln/             # Utility functions

See CLAUDE.md for detailed codebase navigation.

Documentation

Roadmap

  • Formal mathematical framework for agent composition
  • Rust core for performance-critical paths
  • Enhanced MCP (Model Context Protocol) support

License

Apache-2.0

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

lionpride-1.0.0a3.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

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

lionpride-1.0.0a3-py3-none-any.whl (305.3 kB view details)

Uploaded Python 3

File details

Details for the file lionpride-1.0.0a3.tar.gz.

File metadata

  • Download URL: lionpride-1.0.0a3.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for lionpride-1.0.0a3.tar.gz
Algorithm Hash digest
SHA256 594cdfb3ac2a824943e2248d2d89bcdd6547a33f5ee627a68bd7d2131a11569c
MD5 c9d84df0e3721ff945bf9d3538f44164
BLAKE2b-256 8f8d1161da296a302ce6a6e88b6cec8840b35a9188ac2ba917b1ceaf1f692ed2

See more details on using hashes here.

File details

Details for the file lionpride-1.0.0a3-py3-none-any.whl.

File metadata

  • Download URL: lionpride-1.0.0a3-py3-none-any.whl
  • Upload date:
  • Size: 305.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for lionpride-1.0.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 e2159295ce71265985e989513c7e9236b1500746defd78e3738ffba9e77bafcd
MD5 1c558a1fafdd7925da3debc2018f634c
BLAKE2b-256 3d7b9fb782d6f331bf6757c022760dfd66b507ac5a5181857aecab7ffe5d3514

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