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})

Sandboxed 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.

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.19.0.tar.gz (209.4 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.19.0-py3-none-any.whl (149.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lughus-0.19.0.tar.gz
Algorithm Hash digest
SHA256 f329c71f33e56781fb23959995dc0938ac652af2a91b56cfa6c3d1c078ef2a60
MD5 33fb1468925c3f5f73805737399c0178
BLAKE2b-256 3ada180a7dfdf7e7bbd0be1c2f88c9bef24c6d232f508539a9dac9f64e0264cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for lughus-0.19.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.19.0-py3-none-any.whl.

File metadata

  • Download URL: lughus-0.19.0-py3-none-any.whl
  • Upload date:
  • Size: 149.2 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.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d67be1f6368d0adb318724a217628f4e03294cb3dd568cc08fe3e32486cc5c0
MD5 bd4bfb419ce71d5e7003be6c9cf71d4a
BLAKE2b-256 a17606b925a77e65c3b7cef10cae9f19ab283e73192ed5773e1e23f7931adf94

See more details on using hashes here.

Provenance

The following attestation bundles were made for lughus-0.19.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

0.20.0

2 files

This release

0.19.0 This release

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