Files
molecule-sdk-python/molecule_agent/__init__.py
sdk-dev 1fbe150cda
[Do] SDK-Dev self-review: doc-only change, no code impact, no new deps
sop-checklist / all-items-acked All SOP checklist items acknowledged: tests pass, no breaking changes, docs in sync
CI / test (3.13) (pull_request) Successful in 1m37s
CI / test (3.12) (pull_request) Successful in 1m40s
CI / test (3.11) (pull_request) Successful in 1m44s
CI / all-required (pull_request) Successful in 2s
docs(sdk): document stop_event parameter in CLAUDE.md, README, and __init__
Resolves the post-launch CLAUDE.md sync requirement for the stop_event
feature shipped in commit 6a306f3 (KI-009 resolution).

Changes:
- CLAUDE.md: added bullet documenting run_heartbeat_loop(stop_event) and
  run_agent_loop(stop_event) with usage example
- molecule_agent/README.md: updated method table to show stop_event param;
  updated example code to import threading and show stop_event usage
- molecule_agent/__init__.py: updated Intended usage docstring to show
  stop_event parameter in the heartbeat loop call

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-16 21:16:45 +00:00

81 lines
2.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Molecule AI remote-agent SDK — build agents that run outside the platform
network and register as first-class workspaces.
This is the Phase 30.8 companion to ``molecule_plugin`` (for plugin authors).
Where ``molecule_plugin`` helps you ship installable behavior for workspaces
that already exist, ``molecule_agent`` helps you *be* a workspace from the
other side of the wire: register, authenticate, pull secrets, heartbeat,
and detect pause/resume/delete — all via the Phase 30.130.5 HTTP contract.
Intended usage::
import threading
from molecule_agent import RemoteAgentClient
client = RemoteAgentClient(
workspace_id="550e8400-e29b-41d4-a716-446655440000",
platform_url="https://your-platform.example.com",
agent_card={"name": "my-remote-agent", "skills": []},
)
client.register() # mints + persists the auth token
env = client.pull_secrets() # decrypted secrets dict
stop = threading.Event()
client.run_heartbeat_loop(stop_event=stop) # background heartbeat; stop.set() to exit cleanly
See ``sdk/python/examples/remote-agent/`` for a runnable demo.
Design notes:
* **No async.** The SDK uses blocking ``requests`` so a remote agent author
can embed it in any event loop / thread / script without forcing anyio.
* **Token cached on disk** at ``~/.molecule/<workspace_id>/.auth_token``
with 0600 permissions, so a restart of the agent doesn't re-issue a
token (the platform refuses to issue a second token when one is on file).
* **Pause/delete detection is polling-based** because remote agents usually
can't expose an inbound WebSocket reachable from the platform.
"""
from __future__ import annotations
from .a2a_server import A2AServer
from .client import (
PeerInfo,
RemoteAgentClient,
WorkspaceState,
strip_a2a_boundary,
verify_plugin_sha256,
)
from .inbound import (
CursorLostError,
DEFAULT_POLL_INTERVAL,
InboundDelivery,
InboundMessage,
InboundSource,
MessageHandler,
PollDelivery,
PushDelivery,
)
# compute_plugin_sha256 lives in __main__ (the CLI entry point).
# Import it here so `from molecule_agent import compute_plugin_sha256` works.
from .__main__ import compute_plugin_sha256
__all__ = [
"A2AServer",
"RemoteAgentClient",
"WorkspaceState",
"PeerInfo",
"InboundMessage",
"InboundSource",
"InboundDelivery",
"PollDelivery",
"PushDelivery",
"MessageHandler",
"CursorLostError",
"DEFAULT_POLL_INTERVAL",
"compute_plugin_sha256",
"verify_plugin_sha256",
"strip_a2a_boundary",
"__version__",
]
__version__ = "0.1.0"