Marona Python SDK
Run Agents through one managed API, with structured output, local tools, Hub capabilities, streaming, realtime and A2A collaboration.
Install
Version 2.8.0. Package registry.
Python 3.10+.
python -m pip install --upgrade marona==2.8.0
Set MARONA_API_KEY in your backend environment. Never commit it, log it,
or embed a developer key in browser or mobile code. Use an exact accessible
marona/* model alias from Marona Platform.
Agent quickstart
Save as examples/agent_example.py. Run without arguments for text, or with a real
PNG/JPEG path for document extraction. Use stable application user IDs and a
distinct session ID for each conversation.
import asyncio
import base64
import os
import sys
from pathlib import Path
from marona import Agent, Marona, Runner
async def main():
async with Marona(
api_key=os.environ["MARONA_API_KEY"],
base_url=os.getenv("MARONA_RUNTIME_URL", "https://edge.marona.ai"),
) as marona:
agent = Agent(
name="Document Assistant",
model=os.getenv("MARONA_MODEL", "marona/qwen-qwen3.8-max-0902"),
instructions="Answer clearly and concisely.",
tool_choice="none",
)
user_input = "Reply with exactly OK."
if len(sys.argv) > 1:
path = Path(sys.argv[1])
mime = {".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg"}[path.suffix.lower()]
data_url = f"data:{mime};base64," + base64.b64encode(path.read_bytes()).decode("ascii")
user_input = [{"role": "user", "content": [
{"type": "input_text", "text": "Describe this image and transcribe any visible text."},
{"type": "input_image", "image_url": data_url},
]}]
result = await Runner.run(
agent, user_input, user_id="example-user", session_id="example-session"
)
print(result.output)
if __name__ == "__main__":
asyncio.run(main())
python examples/agent_example.py
python examples/agent_example.py image.png
Encode actual file bytes with standard Base64. Image and file blocks accept
raw Base64 in image_data / file_data, or complete matching data URLs.
Do not encode a path, encode twice, or send placeholder data. Remote URLs must
be reachable by the runtime. PDF, audio and realtime support depend on the
selected model; render PDF pages to images when native PDF is unavailable.
Structured output through Agent
The following fragment uses the authenticated client from the quickstart.
document_input is your text or document message input.
from pydantic import BaseModel, ConfigDict
from marona import Agent, Runner
class Extraction(BaseModel):
model_config = ConfigDict(extra="forbid")
text: str
agent = Agent(
name="Document Reader",
model="marona/qwen-qwen3.8-max-0902",
instructions="Extract the document text.",
output_type=Extraction,
output_schema_strict=True,
)
result = await Runner.run(agent, document_input, user_id="user-123")
print(result.output.text)
The explicit strict option asks the provider to enforce the supplied schema; the SDK also validates the final result before returning it. Strict mode requires a compatible model and schema. Declare every object property as required, use nullable values for optional fields, and set additionalProperties to false. Unsupported model capabilities or invalid output produce errors; they do not silently fall back to unstructured text. Input schemas, function tool schemas, guardrails, dynamic instructions and lifecycle hooks are also supported.
Apps and user connections
page = await marona.apps.list_async(user_id="user-123", limit=20)
action = await marona.apps.connect_async("calendar", user_id="user-123")
# Complete any returned authorization_url before calling protected tools.
await marona.apps.disconnect_async("calendar")
Listing an App does not authorize its protected operations. Follow the returned
connection action for the end user. Use hub.connect to expose a scoped set of
App or Skill capabilities to an Agent; Apps authorization and Hub tool discovery
are separate operations.
A2A collaboration and serving
import os
from marona import A2APeer, A2AServer, Agent
peer = A2APeer(name="reviewer", url="https://reviewer.example.com")
coordinator = Agent(name="Coordinator", peers=[peer])
server = A2AServer(
agent=coordinator,
url="https://coordinator.example.com",
skills=[{"id": "review", "name": "Review", "description": "Review a document"}],
)
# Apply production authentication and TLS at your service boundary.
server.run(host="127.0.0.1", port=8100)
Peers support Agent Card discovery, REST/JSON-RPC messages, task retrieval, cancellation, continuation and streamed task events. Servers persist task state. Use explicit credentials, restricted skills, HTTPS, and an appropriate durable task directory for production. Local JSON stores are for a single service instance; multi-instance deployments require coordinated task storage.
Push notifications are not implemented.
Brain2Agent (B2A)
Native B2A 1.0 uses one multimodal message contract in both directions. The
independent neural service owns signal decoding and feedback encoding, with
vendor-hosted MCP, HTTP or local plugin backends. Models and device drivers
are supplied by the interface provider. Configure Agent.protocols and connect with
Runner.connect, following the persistent realtime session lifecycle. These examples
read one captured signal file using your configured provider.
One configured protocol is selected automatically. Several compatible protocols
open a coordinated session automatically. Explicit selection remains available
(protocol="b2a" in Python and the corresponding option in other SDKs). Canonical
message protocol fields or unambiguous registered input predicates select the input;
ambiguous raw input is rejected. Implement AgentProtocol and the coordinated
session lifecycle to add protocols without adding Agent properties. Existing
A2A peers and servers retain their agent-to-agent role; they are not automatically
converted into input protocols. Agent.b2a and B2ARunner remain compatibility APIs.
Save as examples/b2a_message.py:
"""Run a captured signal through an independent provider and an Agent-bound B2A session."""
import asyncio
import json
import os
import sys
from pathlib import Path
from marona import Agent, B2A, B2ACodec, Runner, Marona
INSTRUCTIONS = """Interpret the decoded messages using its context.
Preserve uncertainty and ask for clarification when needed.
Use connected tools under Marona's permissions and confirmation requirements.
"""
async def main():
signal = json.loads(Path(sys.argv[1]).read_text())
neural_service = B2ACodec(
os.environ["B2A_CODEC_URL"],
token=os.environ["B2A_NEURAL_TOKEN"],
transport=os.environ.get("B2A_CODEC_TRANSPORT", "mcp"),
)
async with Marona() as client:
agent = Agent(
name="B2A Message Agent",
model=os.environ.get("MARONA_MODEL", "marona/auto"),
instructions=INSTRUCTIONS,
tools=client.hub.connect(),
protocols=[B2A(
provider=neural_service, output_profile=os.environ["B2A_OUTPUT_PROFILE"]
)],
)
async with await Runner.connect(
agent,
user_id=os.environ["B2A_USER_ID"],
session_id=os.environ["B2A_SESSION_ID"],
) as session:
await session.send_signal(signal)
async for event in session:
print(event)
if event.type in {"feedback", "signal.status", "error"}:
break # This file sends one captured window; keep open for continuous input.
if __name__ == "__main__":
asyncio.run(main())
Single run with structured output
Save as examples/b2a_structured.py. This opens a connection, decodes the signal, runs
the agent, validates the response, encodes feedback, and closes the connection.
"""Run a captured signal through an independent provider and an Agent-bound B2A session."""
import asyncio
import json
import os
import sys
from pathlib import Path
from pydantic import BaseModel, ConfigDict
from marona import Agent, B2A, B2ACodec, Runner, Marona
class NeuralResponse(BaseModel):
model_config = ConfigDict(extra="forbid")
text: str
INSTRUCTIONS = """Interpret the decoded messages using its context.
Preserve uncertainty and ask for clarification when needed.
Use connected tools under Marona's permissions and confirmation requirements.
"""
async def main():
signal = json.loads(Path(sys.argv[1]).read_text())
neural_service = B2ACodec(
os.environ["B2A_CODEC_URL"],
token=os.environ["B2A_NEURAL_TOKEN"],
transport=os.environ.get("B2A_CODEC_TRANSPORT", "mcp"),
)
async with Marona() as client:
agent = Agent(
name="B2A Message Agent",
model=os.environ.get("MARONA_MODEL", "marona/qwen-qwen3.8-max-0902"),
instructions=INSTRUCTIONS,
output_type=NeuralResponse,
output_schema_strict=True,
tools=client.hub.connect(),
protocols=[B2A(
provider=neural_service, output_profile=os.environ["B2A_OUTPUT_PROFILE"]
)],
)
result = await Runner.run(
agent, signal,
user_id=os.environ["B2A_USER_ID"],
session_id=os.environ["B2A_SESSION_ID"],
)
print(result.output.text)
if __name__ == "__main__":
asyncio.run(main())
Python returns the declared Pydantic model in result.output. Other SDKs validate
the declared JSON schema and expose their language's structured output representation.
Invalid output is rejected before encoding. Decoder abstention, required approval,
or failure does not become a successful typed result; use a persistent connection
for interactive clarification, approvals, and feedback delivery acknowledgments.
The SDK manages protocol messages, sequencing, event cursors, decoding and encoding.
Set B2A_CODEC_URL, B2A_NEURAL_TOKEN, B2A_OUTPUT_PROFILE, B2A_USER_ID and
B2A_SESSION_ID. Use B2A_CODEC_TRANSPORT=mcp or http. session_id identifies
an application conversation; each connection gets a separate native transport
session. The application authorizes processing before connecting; device and
protocol scope fields are supplied internally. Closing revokes those scopes.
Keep the session open to send more signals. Feedback events contain encoded
output; printing them does not deliver feedback. An interface driver acknowledges
presentation only after delivery. Failed or uncertain sends are never replayed
automatically. Native B2A supports server-hosted Hub tools and agent graphs;
SDK-local functions, callbacks and peer callbacks require server-hosted equivalents.
B2A connections automatically negotiate HTTP SSE with current runtimes. Sending a
signal returns when accepted. message events carry the standard envelope during
generation and at completion; agent.delta remains a text-preview compatibility event.
Validated, encoded output arrives as feedback. Keep consuming the session
stream for subsequent turns. The SDK handles transport and sequencing; no background
task or polling loop is required in application code. Heartbeats keep an active
stream alive without imposing a generation-wide timeout. Runner.run collects the
completed result and retains its configured run limit. New connections require a
B2A 1.0 runtime; the connection's streaming flag reports whether HTTP SSE is available.
One message format in both directions
{
"protocol": "b2a",
"version": "1.0",
"type": "message",
"source": "neural_decoder",
"message_id": "message-123",
"timestamp": "2026-11-12T08:00:00Z",
"payload": {"content": [
{"type": "text", "data": "Explain this observation"},
{"type": "audio", "mime_type": "audio/wav", "uri": "b2a://session-123/audio-001"}
]}
}
Brain → Agent and Agent → Brain use this same schema; source identifies the
sender (brain, neural_decoder, agent, or a provider-defined source). The SDK
binds the session ID, sequence and context revision. Source labels do not grant authority.
payload.content supports text, audio, image, video, control, features
and namespaced extensions. Binary inline data uses encoding: "base64" and a matching
mime_type; numerical values stay structured. Multiple representations of one
utterance can share representation_id and timing in milliseconds.
Providers return status, message, provenance and uncertainty from decode.
Encode receives that same message envelope with the agent source, under the existing
request.response argument. Models and neural hardware determine actual modality
support. The protocol does not promise that a text-only model can process audio/video.
Private b2a:// references are resolved automatically through the configured provider's
read_resource MCP tool or POST /v1/resources/read HTTP endpoint, with the provider's
credential. The request is {"uri":"b2a://session-123/audio-001","consent":true};
the result is one content block of the same type/MIME, containing inline data or a
scoped HTTPS URL. No arbitrary URL receives the provider bearer token. Large media
should use scoped HTTPS references; providers enforce resource ownership and expiry.
Streaming metadata is stream: {"id":"utterance-1","index":0,"final":false}.
Indices start at zero. Snapshots replace previous content; mode: "delta" appends
one text block. Only final decoder messages run the agent. Sequence/source conflicts,
finalized stream reuse and oversized accumulated input are rejected without execution.
See the repository's docs/b2a-protocol.md for the complete wire contract.
Neural provider connection options
B2ACodec supports optional overrides for provider tool names and HTTP paths.
Omit them when your provider uses the SDK defaults.
| Configuration | Applies to | SDK defaults |
|---|---|---|
decode_tool, encode_tool |
MCP tool names | decode, encode |
decode_path, encode_path |
HTTP endpoint paths | /v1/decode, /v1/encode |
For MCP, configure the provider's complete MCP endpoint URL and select the MCP transport. Tool names identify the provider's tools; HTTP path overrides do not affect MCP calls. These illustrative names must match your provider.
neural_service = B2ACodec(
codec_url,
token=codec_token,
transport="mcp",
decode_tool="neural_decode",
encode_tool="neural_encode",
)
For HTTP, configure the provider base URL. Paths start with / and are appended
to that URL after removing its trailing slash. For example,
https://neural.example/api plus /neural/decode calls
https://neural.example/api/neural/decode. MCP tool names do not affect HTTP calls.
neural_service = B2ACodec(
service_url,
token=codec_token,
transport="http",
decode_path="/neural/decode",
encode_path="/neural/encode",
)
The SDK defaults to HTTP when transport is omitted; the B2A quickstarts above
explicitly select MCP. Pass the resulting service as the B2A provider in the same
Agent.protocols configuration. These options change routing only: request and
response schemas still follow the B2A provider contract. Implement B2AProvider
when a vendor needs payload translation. These are neural-service routes, separate
from Marona's /runtime/b2a/... endpoints.
Device2Agent (D2A)
D2A 1.0 is an independent bidirectional device protocol. Configure it on an Agent
without B2A, or combine it with any compatible protocol. Device types and capability
names come from discovery. IoT sensors, robots, industrial systems and vendor SDKs
connect through a D2AProvider adapter implementing discovery, continuous events,
action execution, action lookup and cancellation. The protocol does not supply
hardware drivers automatically.
D2ADevice connects a compatible HTTP/SSE gateway. Its MCP mode maps discovery and
actions to tools and requires a real continuous event adapter or event endpoint.
Request polling is not presented as realtime. Provider credentials stay in the SDK
process and are never sent in the Agent configuration.
Save as examples/d2a_example.py. With a canonical message JSON file, run one exchange.
Without a file, the SDK subscribes to device events and keeps the session open.
Set MARONA_API_KEY, D2A_DEVICE_URL, D2A_DEVICE_TOKEN, D2A_USER_ID and D2A_SESSION_ID.
import asyncio
import json
import os
import sys
from pathlib import Path
from marona import Agent, D2A, D2ADevice, D2AMessage, Marona, Runner
async def main():
provider = D2ADevice(os.environ["D2A_DEVICE_URL"], token=os.environ["D2A_DEVICE_TOKEN"])
async with Marona() as client:
agent = Agent(
name="Device Agent", model=os.environ.get("MARONA_MODEL", "marona/auto"),
instructions="Interpret device observations, use authorized capabilities, and report confirmed outcomes.",
tools=client.hub.connect(),
protocols=[D2A(provider=provider, policy={"allow_actions": True})],
)
identity = {"user_id": os.environ["D2A_USER_ID"], "session_id": os.environ["D2A_SESSION_ID"]}
if len(sys.argv) > 1:
message = D2AMessage.from_dict(json.loads(Path(sys.argv[1]).read_text()))
result = await Runner.run(agent, message, **identity)
print(result.output)
else:
async with await Runner.connect(agent, **identity) as session:
async for event in session:
print(event) # The SDK continuously receives the provider's device events.
if __name__ == "__main__":
asyncio.run(main())
Message and action lifecycle
Both directions use protocol, version, type, source, message_id, timestamp and
payload. payload.kind is observation, state, action, feedback or coordination;
payload.content contains typed text, media, control, features or namespaced blocks.
Only action messages can execute device capabilities. Observations and state require
content; action, feedback and coordination metadata can use an empty content array.
The SDK assigns IDs and timestamps, then binds the native session and sequence.
Device resource references use HTTPS; adapters materialize private resources.
Actions are disabled by default. These examples deliberately enable execution of
advertised capabilities. Restrict allowed devices and capabilities for your application.
The runtime reserves an action before provider execution. Both boundaries validate
capability schemas, expiry, revision and policy. requires_approval still requires an
explicit session approval call; a model or provider cannot grant approval to itself.
Accepted and executing acknowledgments are not completion. A successful action needs succeeded feedback with a schema validated result. Single runs surface pending, approval required, rejected, failed, cancelled, expired or unknown outcomes instead of reporting successful execution. Persistent sessions expose these events and support approval, action lookup and cancellation. An uncertain action ID is retained and never automatically executed again. Cancellation cannot undo a completed action.
Provider event streams accept only advertised device observations, state or correlated feedback. Providers cannot inject agent actions, cross protocol routes or approval flags. Queues are bounded, sequence assignment is serialized, and closing a session cancels its readers and native connection. Streaming delivers messages as generation progresses; applications do not implement polling or a background routing loop.
Automatic protocol coordination
deviceProtocol / device_protocol and otherProtocol / other_protocol below are
configured AgentProtocol implementations. The second protocol may be B2A or any
other compatible protocol; D2A does not depend on it.
agent = Agent(
name="Connected Agent",
model="marona/auto",
tools=client.hub.connect(),
protocols=[device_protocol, other_protocol],
)
async with await Runner.connect(agent, user_id=user_id, session_id=session_id) as session:
await session.send(canonical_message)
async for event in session:
print(event)
All attached protocols share the authenticated user and application conversation,
with separate native session IDs. Discovery runs before any native connection opens.
The runtime receives advertised capabilities and emits final protocol.route decisions.
The SDK delivers each canonical message to its target, then calls the origin session's
deliverFeedback / deliver_feedback hook with correlated terminal feedback.
Partial model output never actuates devices. Pending acknowledgments stay pending.
Compatible sessions implement send, canonical deliver, deliver feedback, event iteration and close. Input recognition is optional; unclassified ambiguous input fails instead of being broadcast. Routes enforce target attachment, correlation, bounded deduplication and an eight hop limit with visited protocol lineage. Exceeding retention fails closed; old route IDs are never evicted to permit duplicate actions. Partial setup failures close already opened sessions. Explicit protocol selection preserves the single protocol API.
Standard realtime audio
Use RealtimeMedia to negotiate WebM/Opus, Ogg/Opus or MP3 with the runtime. The runtime
encodes before transmission; applications do not install an encoder or schedule
PCM chunks. This optional media layer leaves Agent tools, B2A messages, schemas,
and existing PCM sessions unchanged.
from marona import RealtimeMedia, RealtimeRunner
# agent is an existing Agent configured with an accessible audio model.
async with await RealtimeRunner.connect(
agent, user_id="user-123", session_id="voice-123", media=RealtimeMedia(),
) as session:
await session.send_message("Explain this observation briefly.")
async for event in session:
if event.type == "output_audio.stream" and event.audio:
# A standard media player can consume event.audio.uri immediately.
print(event.audio.uri, event.audio.mime_type)
if event.type == "response.completed":
break
# Headless consumers can use audio.chunks() or await audio.write_to(binary_sink).
output_audio.stream exposes a scoped, expiring audio URL and typed format metadata.
output_audio.done reports encoding completion, not playback completion. Wait for
your media output to finish before starting the next conversational turn. Closing
a session or cancelling a response stops active generation; stop your output adapter
to discard audio already delivered. The SDK never replays a response automatically.
RealtimeAudio.content() returns an existing B2A audio block for HTTPS media URLs.
The optional browser adapter is AudioPlayer from marona/media. Python ships the
same module through RealtimeMedia.browser_module() for serving from your application.
Use player.media for negotiation and await player.play(audio) for playback completion;
player.stop() cancels playback. A backend keeps its API key private and forwards only
typed media descriptors to the output. Native and headless consumers use the same
HTTP media resources without depending on a browser. These examples print a resource
reference; printing a URL alone does not play it.
Execution and errors
Use Runner.stream for streamed Agent events and
RealtimeRunner for a live session. Delegation and handoffs use explicit Agent
graphs. Set execution limits and validate permissions before tools with side
effects; cancellation cannot roll back an operation that has already executed.
Inspect the canonical error code, HTTP status, request ID and retry metadata. Correct invalid input and authorization errors before retrying. Use bounded retries for transient failures. Never include credentials or document content in error reports.
See Platform documentation for language
specific examples and migration guidance. These files are generated from
docs/client-sdk-guides.json; verify them with
python scripts/sync_client_sdk_docs.py --check.
2.8.0
D2A adds independent device communication, persistent provider events, schema checked actions, approval and outcome reconciliation. Multiple compatible Agent protocols now coordinate automatically through generic canonical delivery and feedback hooks. Existing B2A and core Agent APIs remain supported.
B2A 1.0 uses the same multimodal message envelope in both directions. The source identifies the sender. SDK-managed streaming, resource resolution and encoder return messages are built in. Existing v0.1 runtime sessions remain supported; new SDK connections require a runtime advertising B2A 1.0.
Metadata
Release files for marona 2.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| marona-2.8.0.tar.gz | 153.6 kB | With provenance | Details for marona-2.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| marona-2.8.0-py3-none-any.whl | Python 3 | none | any | Details for marona-2.8.0-py3-none-any.whl |
Total release size: 275.2 kB
Release files / marona-2.8.0.tar.gz
| Download URL | marona-2.8.0.tar.gz |
|---|---|
| Size | 153.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e33ab152b28b69b6d697c026e8bae916c20576becd9f8042b8e3cad26be522d
|
|
BLAKE2b-256 checksum How to use checksums |
bdb507800313602c50fd3d1a907e90520f93783ee170f8ab2e12065927a17609
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 19, 2026.
Transparency logRelease files / marona-2.8.0-py3-none-any.whl
| Download URL | marona-2.8.0-py3-none-any.whl |
|---|---|
| Size | 121.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
86950902a6aeb5fd645c8a8b49f9fdc6930549e8128a11e0fcf00a6e599e70d5
|
|
BLAKE2b-256 checksum How to use checksums |
706af2c23f688c115492787fcce41bb43a053924a9b24a1263ddd5cd9b1c19d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 19, 2026.
Transparency logSecurity for marona 2.8.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.
Attestation for marona-2.8.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 Nov 19, 2026.
Transparency logA 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.