A Minimal agent runtime built on OpenAI Responses API
Project description
LiteRun 🚀
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(), andastream()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
ToolRuntimewithout 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
PromptTemplatebuilder that enforces message invariants before network execution.
Requirements
- Python 3.10+
Note: Core dependencies like
openaiandpydanticare automatically installed when you installliterun.
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_KEYenvironment 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56e3602c0eb8df4cb32ef08ece61a993c2048b96b393acb95ec63c45b4c52d84
|
|
| MD5 |
0175f62a2edb6d508c48090c9ecf87eb
|
|
| BLAKE2b-256 |
ce7b4a4a0cc228f4fd9faf31d08c2cb7624073b79c93bd37e5afc3c8ee64323a
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
345f53f15aa5c1dcf92ae5c6f24a59b32058cf6339e9659a516d30d22a8c61f4
|
|
| MD5 |
deb45d1affda3b9d5901f493b74ddf25
|
|
| BLAKE2b-256 |
cade9b924ec32b9b409306e24ebbba2115fe06cb08c2812333475397ca559306
|