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.

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.
  • OpenAI-Focused Token Accounting: Exposes explicit cached_read, reasoning, 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: Core dependencies like openai and pydantic are automatically installed when you install literun.

Installation

Install literun directly from PyPI.

pip install literun

Set your API key in your environment:

export OPENAI_API_KEY="sk-proj-..."

Quick Start

Here is a simple example demonstrating how to initialize an Agent, register a Tool using Pydantic schemas, and execute a synchronous run.

from literun import Agent, ChatOpenAI, Tool
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"),
    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.

👉 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 OPENAI_API_KEY environment variable. They are automatically skipped if it is missing.

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.0.tar.gz (60.5 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.0-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: literun-0.3.0.tar.gz
  • Upload date:
  • Size: 60.5 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.0.tar.gz
Algorithm Hash digest
SHA256 56e3602c0eb8df4cb32ef08ece61a993c2048b96b393acb95ec63c45b4c52d84
MD5 0175f62a2edb6d508c48090c9ecf87eb
BLAKE2b-256 ce7b4a4a0cc228f4fd9faf31d08c2cb7624073b79c93bd37e5afc3c8ee64323a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: literun-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 32.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 345f53f15aa5c1dcf92ae5c6f24a59b32058cf6339e9659a516d30d22a8c61f4
MD5 deb45d1affda3b9d5901f493b74ddf25
BLAKE2b-256 cade9b924ec32b9b409306e24ebbba2115fe06cb08c2812333475397ca559306

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