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
registry = ToolRegistry()


@registry.tool(
    "greet",
    "Greet a user by name.",
    {
        "type": "object",
        "properties": {
            "name": {"type": "string", "description": "Name to greet"},
        },
        "required": ["name"],
        "additionalProperties": False,
    },
)
def greet(*, name: str, state) -> str:
    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(
    "deploy",
    "Deploy a service to production.",
    {
        "type": "object",
        "properties": {"service": {"type": "string"}},
        "required": ["service"],
    },
    risk=ToolRisk.CRITICAL,
    effects=frozenset([ToolEffect.WRITE, ToolEffect.IRREVERSIBLE]),
    requires_approval=True,  # Suspends the run until human confirms
)
def deploy(*, service: str, state) -> str:
    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

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.17.0.tar.gz (197.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.17.0-py3-none-any.whl (141.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lughus-0.17.0.tar.gz
  • Upload date:
  • Size: 197.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.17.0.tar.gz
Algorithm Hash digest
SHA256 0634994566956e820bb1d8c2d6294673b641f9d47bfe4fcf5ccd901dd82a1f6c
MD5 19bdc7377f18abec1b1da94c8070203a
BLAKE2b-256 d324ebf4fdc64934fd986df79667e54fab8b30ffae3d7a1cc13fb9721664fd7a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: lughus-0.17.0-py3-none-any.whl
  • Upload date:
  • Size: 141.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.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aca905ce1f1e23950834781052dedd885bfb4a19cb71cfc3b123dc9ee3c6f505
MD5 26f0d70fcf94d6398a7e24b8fa9a8c4d
BLAKE2b-256 e3845aee60e39ad73d697c83cdb7c2de8befd78e784b32d15252a76dc16cff2d

See more details on using hashes here.

Provenance

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

0.19.0

2 files

0.18.0

2 files

This release

0.17.0 This release

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