Skip to main content

A minimal, provider-agnostic agent runtime for OpenAI and Gemini

Project description

LiteRun 🚀

PyPI - Version PyPI - Python Version PyPI - License Documentation

A lightweight, production-grade Python framework for building predictable, multi-turn AI agents. LiteRun standardizes the chaotic mechanics of modern LLM APIs (like tool-loop continuation, JSON stream assembly, and token accounting) while giving you absolute control over execution and state.

Currently supports OpenAI Responses API and Google Gemini Interactions API.

Key Features

  • Standardized Execution: A symmetric API for run(), arun(), stream(), and astream() with normalized result/event schemas for supported provider behavior.
  • Structured Tooling Runtime: Pydantic-powered schema generation, execution routing, and output validation.
  • Secure Context Injection: Safely pass ephemeral app state (like DB connections or Tenant IDs) into tools via ToolRuntime without exposing it to the LLM.
  • Multi-Provider Runtime: Provider-specific clients and adapters for OpenAI and Gemini behind a shared LiteRun orchestration contract.
  • Normalized Token Accounting: Exposes explicit cached_read, reasoning, tool_use, and standard token buckets when usage data is available.
  • Canonical Prompting: A strictly typed PromptTemplate builder that enforces message invariants before network execution.

Requirements

  • Python 3.10+

Note: Provider SDKs are installed via extras. Install the provider you want to use.

Installation

Install LiteRun with the provider extra you need.

pip install "literun[openai]"

For Gemini:

pip install "literun[gemini]"

For both supported providers:

pip install "literun[all]"

Set the matching API key in your environment:

export OPENAI_API_KEY="sk-proj-..."
export GOOGLE_API_KEY="your-google-api-key"

Quick Start

Here is a simple example demonstrating how to initialize an Agent, register a Tool using Pydantic schemas, and execute a synchronous run with OpenAI. The same agent surface works with Gemini by swapping the client.

from literun import Agent, ChatOpenAI, Tool
# from literun.providers import ChatGemini
from pydantic import BaseModel, Field

# 1. Define the tool's input schema for strict validation
class WeatherInput(BaseModel):
    location: str = Field(description="The city and state, e.g. San Francisco, CA")
    unit: str = Field(default="celsius", description="The unit of temperature")

# 2. Define the Python logic
def get_weather(location: str, unit: str = "celsius") -> str:
    return f"The weather in {location} is 22 degrees {unit}."

# 3. Wrap it in a LiteRun Tool
weather_tool = Tool(
    func=get_weather,
    name="get_weather",
    description="Get the current weather for a specific location.",
    input_schema=WeatherInput,
    strict=True # Enforces stricter OpenAI schema adherence (model/provider dependent)
)

# 4. Initialize the Agent Orchestrator
agent = Agent(
    llm=ChatOpenAI(model="gpt-5-nano"),
    # llm=ChatGemini(model="gemini-3-flash-preview"),
    system_instruction="You are a helpful and concise weather assistant.",
    tools=[weather_tool],
)

# 5. Execute the Run
result = agent.run("What is the weather in Tokyo?")

print(f"Response: {result.output}")
print(f"Usage: {result.token_usage}")
print(f"Execution Time: {result.timing.duration:.2f}s")

Advanced Usage & Examples

LiteRun supports sync/async execution in both non-streaming and streaming modes, plus runtime context injection and direct LLM client usage. The example scripts in examples/ use comment toggles so you can switch between OpenAI and Gemini quickly.

👉 Check out the Documentation and Examples for more details.

Testing

This project uses pytest as the primary test runner, but supports unittest as well.

# Run all tests
python -m pytest

or using unittest:

python -m unittest discover tests

Note: Some integration tests may require the provider api-key environment variable. They are automatically skipped if it is missing. Provider-specific tests require the matching provider SDK extra and API key.

License

Copyright (c) 2026 Kaustubh Trivedi.

Distributed under the terms of the MIT license, LiteRun is free and open source software.

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

literun-0.3.2.tar.gz (70.2 kB view details)

Uploaded Source

Built Distribution

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

literun-0.3.2-py3-none-any.whl (41.0 kB view details)

Uploaded Python 3

File details

Details for the file literun-0.3.2.tar.gz.

File metadata

  • Download URL: literun-0.3.2.tar.gz
  • Upload date:
  • Size: 70.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for literun-0.3.2.tar.gz
Algorithm Hash digest
SHA256 f17fd1e222cfe4359f32c96aac6649293f7b4a750ef4156a4946520330edcbd0
MD5 7f49629b41b90c22c969ca82aa5d6acb
BLAKE2b-256 bfc144da89805beab965f9593088c87af1e0c109a424c3e12ba632eea543a32f

See more details on using hashes here.

File details

Details for the file literun-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: literun-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 41.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for literun-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7d3323f48a2a8fcb6a62045e6969e57460164b4a9bd4a0ee01e2818d446332c5
MD5 b665ab5a1f5de79797c76838e03dd81e
BLAKE2b-256 ecaeadb0e205db03e78650a89b63697c148148fad3b144d2e92562f42f691d69

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