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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lughus-0.20.0.tar.gz (216.3 kB view details)

Uploaded Source

Built Distribution

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

lughus-0.20.0-py3-none-any.whl (156.9 kB view details)

Uploaded Python 3

File details

Details for the file lughus-0.20.0.tar.gz.

File metadata

  • Download URL: lughus-0.20.0.tar.gz
  • Upload date:
  • Size: 216.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lughus-0.20.0.tar.gz
Algorithm Hash digest
SHA256 e122ad542f83b07d58a262d094b3a8feda016e2556b5e9ac458d3026fd37658a
MD5 d8bd2e1358e3bf154f1c502438c59c7f
BLAKE2b-256 5d5b65b2fa7871edd628263619bdec485a9b1f5682b8174b0da7ac25fb435ade

See more details on using hashes here.

Provenance

The following attestation bundles were made for lughus-0.20.0.tar.gz:

Publisher: publish.yml on hdg-zero/lughus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lughus-0.20.0-py3-none-any.whl.

File metadata

  • Download URL: lughus-0.20.0-py3-none-any.whl
  • Upload date:
  • Size: 156.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lughus-0.20.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c79425dee61b1321ac631cba6be0476f0afa7c5faaea0bd2d16e919987c57c6b
MD5 9e3942bb645c4a804c10a0e68e1a161e
BLAKE2b-256 bd8c82bec342cf61412ddea0d801790e531eff3662c9118b6d0d5bcb205f8dad

See more details on using hashes here.

Provenance

The following attestation bundles were made for lughus-0.20.0-py3-none-any.whl:

Publisher: publish.yml on hdg-zero/lughus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.20.0 This release

2 files

0.19.0

2 files

0.18.0

2 files

0.17.0

2 files

0.15.0

2 files

0.14.1

2 files

0.12.0

2 files

0.11.0

2 files

0.10.2

2 files

0.10.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

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