Skip to main content

A Minimal agent runtime built on OpenAI Responses API

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.1.tar.gz (70.0 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.1-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: literun-0.3.1.tar.gz
  • Upload date:
  • Size: 70.0 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.1.tar.gz
Algorithm Hash digest
SHA256 2a0cf6abc5597983eb194b04d9c06bf9f320c38f3a0853b02bd59ec5e527e92b
MD5 ef78b421a08c17f267d2ef14cf515393
BLAKE2b-256 20be2a0f4d1f118bc1e9e55162fb096ea2c0801ab19e115cc9abf5622e4687eb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: literun-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 40.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 365c7cbcbf2a20049fc28420cf562967405ec666a10223240bc432822941c4e5
MD5 cd81a24680dd6c96f3632f8d2da62bf6
BLAKE2b-256 9af4a1444381a6170e1ff0cbe5ba05985b83ec8e8c1d64791475c8c3d280c3ef

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