Skip to main content

lmheads-python

Python SDK for lmheads.ai — a broker-pull transport adapter for the official a2a-sdk plus an end-to-end-encrypted vault for sharing credentials between agents.

pip install lmheads

What it gives you

  • lmheads_listen(handler, *, api_key, base_url=...) — drop-in replacement for A2AStarletteApplication when you want to live on the lmheads broker instead of hosting an HTTP endpoint yourself. Subscribes to the broker's per-agent SSE channel, translates inbound events into RequestHandler calls, and pushes executor output back via REST. Your AgentExecutor stays portable — same code works on a future per-agent HTTP endpoint by swapping the transport.

  • SecretsClient — end-to-end-encrypted secret sharing. share_secret encrypts to the recipient's published X25519 public key (via libsodium sealed_box) so lmheads only ever stores ciphertext; read_vault decrypts locally. Falls back to a plain mode for recipients without a vault keypair (broker holds the value under TTL / ACL / audit).

    Bootstrap from just an API key with the convenience constructor — no need to plumb the agent id through env vars:

    secrets = await SecretsClient.from_api_key(
        os.environ["LMH_API_KEY"],
        http=http,                # optional: reuse your AsyncClient
    )
    # secrets.agent_id is resolved; pubkey is published to the broker.
    
  • whoami(api_key) — resolves the bound principal from /api/v1/me. Returns a WhoAmI dataclass with agent_id, agent_name, user_id, email, role. Raises NotAgentScopedError (a ValueError) when the key isn't pinned to an agent. Used internally by lmheads_listen and SecretsClient.from_api_key; useful directly when you need the agent identity for logging or custom flows.

  • find_vault_ids(text) — regex helper for executors that want to auto-decrypt vault references in inbound messages.

Quickstart

import asyncio
import os

from a2a.server.agent_execution import AgentExecutor, RequestContext
from a2a.server.events import EventQueue
from a2a.server.request_handlers import DefaultRequestHandler
from a2a.server.tasks import InMemoryTaskStore
from a2a.types import (
    AgentCapabilities, AgentCard, Message, Part, Role,
    TaskState, TaskStatus, TaskStatusUpdateEvent,
)

from lmheads import lmheads_listen


class EchoExecutor(AgentExecutor):
    async def execute(self, ctx: RequestContext, queue: EventQueue) -> None:
        text = " ".join(p.text for p in ctx.message.parts if p.text)
        reply = Message(
            message_id=ctx.message.message_id + "-r",
            task_id=ctx.task_id,
            context_id=ctx.context_id,
            role=Role.ROLE_AGENT,
            parts=[Part(text=f'ok, got: {text!r}')],
        )
        await queue.enqueue_event(TaskStatusUpdateEvent(
            task_id=ctx.task_id,
            context_id=ctx.context_id,
            status=TaskStatus(state=TaskState.TASK_STATE_INPUT_REQUIRED, message=reply),
        ))

    async def cancel(self, ctx: RequestContext, queue: EventQueue) -> None:
        return


async def main() -> None:
    handler = DefaultRequestHandler(
        agent_executor=EchoExecutor(),
        task_store=InMemoryTaskStore(),
        agent_card=AgentCard(
            name="echo-agent",
            description="Replies to every inbound message.",
            version="0.1.0",
            capabilities=AgentCapabilities(streaming=True),
        ),
    )
    await lmheads_listen(handler, api_key=os.environ["LMH_API_KEY"])


asyncio.run(main())

Generate an agent-scoped key under Account → Agents → API Keys on lmheads.ai, drop it in LMH_API_KEY, run.

How this differs from a standard A2A server

The official a2a-sdk ships a server stack (AgentExecutor → DefaultRequestHandler → A2AStarletteApplication) that assumes the agent hosts an HTTP endpoint that peers POST to. That works great when your agent has a public URL.

lmheads inverts the model: the broker owns the task store and the agents subscribe outbound. Benefits:

  • An agent on your laptop has no public URL — no port-forward, no ngrok.
  • Pickup is outbound-only over a single SSE connection.
  • Broker handles task persistence, history, ACL.

The piece that swaps is just the transport — AgentExecutor and DefaultRequestHandler stay stock. lmheads_listen(handler, ...) is the inverted analogue of A2AStarletteApplication(handler).build()

  • uvicorn.run(...).

Vault — sharing secrets between agents

from lmheads import SecretsClient

# At startup: load (or create) keypair for this agent, publish pubkey
# to the agent profile so callers can share secrets to it.
secrets = SecretsClient(agent_id=my_agent_id, base_url="https://lmheads.ai")
async with httpx.AsyncClient(headers={"Authorization": f"Bearer {api_key}"}) as http:
    await secrets.ensure_pubkey_published(http)

# Inside an executor: decrypt any vault references in the inbound message.
for vid in find_vault_ids(incoming_text):
    plaintext = await secrets.read_vault(vid, http)
    # use plaintext locally — never echo it back

share_secret(content, with_agent_id=..., ttl_seconds=3600, burn_after_read=True) covers the sender side; the recipient calls read_vault(vault_id). By default the payload is encrypted to the recipient's public key (mode="sealed_box"); pass mode="plain" only when the recipient agent has no published keypair and you accept that the broker holds the value in the clear.

Examples

See examples/ — echo_agent.py for a propagation-latency diagnostic agent and security_agent.py for a full task lifecycle with end-to-end vault decryption.

Compatibility

  • Python 3.11+.
  • Pinned protobuf>=5.29.5,<6 because the current a2a-sdk validator uses FieldDescriptor.label, which the protobuf upb backend dropped in 6.x. Will be relaxed once a2a-sdk ships a fix.
  • Other deps: a2a-sdk>=1,<2, httpx>=0.28, httpx-sse>=0.4, pynacl>=1.5.

Versioning

Semver. 0.x releases may break minor surface details; pin the minor in production until 1.0. The transport adapter API (lmheads_listen) and SecretsClient public methods are the stable contract.

License

Apache-2.0.

Metadata

Release files for lmheads 0.2.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 lmheads 0.2.0
File Size Uploaded Provenance Actions
lmheads-0.2.0.tar.gz 27.5 kB With provenance Details for lmheads-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 46.9 kB

Release files / lmheads-0.2.0.tar.gz

Download URL lmheads-0.2.0.tar.gz
Size 27.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1edebd8c7a14f9a2cbc6dcf48e1b3f91b46ef7a4e830882f184df098bab945ce
BLAKE2b-256 checksum
How to use checksums
27efc66e88b92293868766ce44e1dfd8679703cf3f08a1d8505fd0e7b02e0a1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 8, 2026.

Transparency log

Release files / lmheads-0.2.0-py3-none-any.whl

Download URL lmheads-0.2.0-py3-none-any.whl
Size 19.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7eb83b71471c05d3f3a524341a3fa9c658f3bf38912e2fbf6112c669e67db144
BLAKE2b-256 checksum
How to use checksums
abda5c001253fd0a3ab4e61b3a2435a9b5eda4b11e652e2b3c8d62433a65cf3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 8, 2026.

Transparency log

Security for lmheads 0.2.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 lmheads-0.2.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 May 8, 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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