Skip to main content

lughus logo

PyPI version Supported Python versions License: MIT

lughus

Micro-framework for building A2A agents with LiteLLM. Register tools, run an agentic loop, get a result. No graphs, no runners, no magic.

Installation

pip install lughus              # Core: agent loop, tool registry, LiteLLM
pip install "lughus[server]"    # + FastAPI, uvicorn, A2A gateway & developer console
pip install "lughus[all]"       # Everything (including OpenTelemetry SDK)

🚀 Two Tracks to Get Started

Track 1: Micro-Agent in 30 Seconds (Standalone Script)

Run an autonomous agent loop directly in a Python script without starting a server:

import asyncio
import json

from lughus import ToolRegistry, agent_loop
from lughus.testing import MockLLM

# 1. Create a tool registry and register tools (automatic schema inference)
registry = ToolRegistry()


@registry.tool
def greet(name: str) -> str:
    """Greet a user by name.

    Args:
        name: Name to greet
    """
    return json.dumps({"greeting": f"Hello, {name}!"})


# 2. MockLLM for offline tests or swap with LLM for production
llm = MockLLM(
    [
        [{"name": "greet", "arguments": {"name": "World"}, "id": "call_1"}],
        "Hello, World!",
    ]
)


# 3. Execute the loop
async def main():
    result = await agent_loop(
        llm,
        system="You are a greeting assistant. Use the greet tool.",
        context="Say hello to World",
        registry=registry,
        tool_names=["greet"],
    )
    print(result)  # "Hello, World!"
    print(f"{result.iterations} iterations, {result.total_tokens} tokens")


asyncio.run(main())

For live execution against 100+ LLM providers, swap MockLLM for LLM:

from lughus import LLM

llm = LLM(model="openai/gpt-4o", max_output_tokens=16384)

Track 2: Production A2A Agent (Server & Developer Console)

When your agent needs network transport, streaming, task status, and an interactive UI:

1. Scaffold an agent project

lughus new my_agent
cd my_agent && pip install -e ".[dev]"

2. Start the A2A server

export AGENT_MODEL="openai/gpt-4o"
export OPENAI_API_KEY="sk-..."
export ENABLE_CONSOLE="true"

python -m my_agent  # Starts ASGI server on http://localhost:8080

3. Explore the Developer Console (/ui)

Open http://localhost:8080/ui in your browser to access the interactive console:

  • Live Streaming & Timeline: real-time token stream and step-by-step agent trajectory.
  • Rich GFM Markdown & KaTeX: rendered tables, GitHub alerts ([!NOTE], [!WARNING]), and LaTeX math ($E=mc^2$).
  • Interactive Human Approvals: live amber cards with Approve / Reject actions for sensitive tools.
  • Artifact Downloads: view and download files generated by the agent.

🛡️ Governance & Deterministic Policy

Tools declare risk levels, required permission scopes, and approval gates. The policy engine evaluates actions before execution — prompt instructions are never used as access controls:

import json

from lughus import ToolEffect, ToolRegistry, ToolRisk

registry = ToolRegistry()


@registry.tool(
    risk=ToolRisk.CRITICAL,
    effects=frozenset([ToolEffect.WRITE, ToolEffect.IRREVERSIBLE]),
    requires_approval=True,  # Suspends the run until human confirms
)
def deploy(service: str) -> str:
    """Deploy a service to production."""
    return json.dumps({"status": "deployed", "service": service})

Container-confined Python Code Interpreter

Lughus provides an isolated Python code execution tool with automatic output truncation and timeout handling:

from lughus import ToolRegistry, register_code_interpreter

registry = ToolRegistry()
register_code_interpreter(registry, timeout_s=30.0, requires_approval=True)

⚙️ Configuration

All configuration is managed through environment variables loaded automatically via .env:

Variable Default Description
AGENT_MODEL (required) LiteLLM model string (e.g. openai/gpt-4o, anthropic/claude-3-7-sonnet)
MAX_OUTPUT_TOKENS 16384 Maximum output tokens per LLM completion call
HOST / PORT 0.0.0.0 / 8080 Network binding address for A2A server
LUGHUS_ENV development Set to production for strict startup configuration validation
ENABLE_CONSOLE false Enable the developer console UI at /ui (development only)
API_BEARER_TOKEN (not set) Shared secret bearer token for non-health endpoints
MAX_CONCURRENT_REQUESTS 0 (disabled) Framework-level backpressure limit on active HTTP requests

🏛️ Comparison Matrix

Feature Core (agent_loop) A2A Server (BaseGateway / serve)
Execution In-process Python async coroutine HTTP JSON-RPC 2.0 / SSE server
Tool Calling Parallel with semaphore bulkhead Parallel with semaphore bulkhead
Streaming agent_loop_stream generator A2A server-sent event updates
Developer UI Terminal / Logging Rich web console at /ui
Telemetry OpenTelemetry spans & counters OpenTelemetry spans, counters & metrics
Scaffolding Single-script import CLI scaffold via lughus new

📚 Documentation & Resources

Governed execution

See the unified run/stream guide. Before 1.0, minor releases may break APIs; pin and test upgrades.

License

MIT — see LICENSE.

Native clients and Python confinement

See A2A, MCP and Python security. The interpreter now requires an explicit Docker/Podman backend and artifact store; there is no unsafe fallback.

Durable beta execution

Lughus provides SQLite-backed resume/resume_stream. Read its single-host, stateless-tool and reconciliation constraints before deployment. See the beta runtime conventions.

Metadata

Release files for lughus 0.22.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lughus 0.22.0
File Size Uploaded Provenance Actions
lughus-0.22.0.tar.gz 229.8 kB With provenance Details for lughus-0.22.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lughus 0.22.0
File Interpreter ABI Platform Actions
lughus-0.22.0-py3-none-any.whl Python 3 none any Details for lughus-0.22.0-py3-none-any.whl

Total release size: 396.3 kB

Release files / lughus-0.22.0.tar.gz

Download URL lughus-0.22.0.tar.gz
Size 229.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5537ba36fc408c3c2e08484dff8f845c261cdec3f32c2f3b5dfd71232f90c777
BLAKE2b-256 checksum
How to use checksums
794109e69d0f709d14613522ac779a40a8b5a3a239a0916988cf4295700516f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / lughus-0.22.0-py3-none-any.whl

Download URL lughus-0.22.0-py3-none-any.whl
Size 166.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1304ec30c3f5e926b8a4edecf30c5602324888f035a436f0a9af09142af43ac2
BLAKE2b-256 checksum
How to use checksums
8b448743922e25ffdb1c90c2303ef6752ce246be38c087a9959d14eedd34994b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Security for lughus 0.22.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for lughus-0.22.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page