agora.matrix.client

Thin Matrix client wrapper around matrix-nio.

Exposes a small, domain-shaped MatrixClientProtocol so tests can inject a fake without touching the network. AgoraMatrixClient is the production implementation that delegates to nio.AsyncClient.

Functions

unwrap_envelope(event)

If event is an Agora envelope, return an event dict with the original type/content.

wrap_for_homeserver(event_type, content)

Map a domain event type + content to what we actually send over the wire.

Classes

AgoraMatrixClient

Concrete MatrixClientProtocol backed by nio.AsyncClient.

MatrixClientProtocol

Minimal surface used by the rest of the codebase.

NullMatrixClient

A MatrixClientProtocol that needs no homeserver.

SyncBatch

One batch of events returned by sync_once.

class agora.matrix.client.MatrixClientProtocol[source]

Bases: Protocol

Minimal surface used by the rest of the codebase.

async login(password)[source]
async create_room(name, topic='', invite=None, initial_state=None)[source]
async send_state_event(room_id, event_type, content, state_key='')[source]
async send_event(room_id, event_type, content)[source]
async get_room_state(room_id)[source]
async get_room_timeline(room_id, limit=100, since=None)[source]
async upload_file(file_path)[source]
async download_file(mxc_uri, dest_dir)[source]
async sync_once(timeout_ms=30000, since=None, rooms=None)[source]
async close()[source]
__init__(*args, **kwargs)
class agora.matrix.client.NullMatrixClient[source]

Bases: object

A MatrixClientProtocol that needs no homeserver.

Used when the Matrix surface is switched off (enable_observer=False): the phased runner drives a whole lifecycle with nobody watching, and demanding a live Conduit for rooms no human will ever open is a hard dependency for nothing. With this client the documented path is Python + Ollama; Conduit becomes the optional live-observation view.

This is not a void. Provenance is unconditional (F3): every call is recorded to run.log at INFO, so the record of what an agent tried to communicate survives whether or not a homeserver existed. What disappears is only the delivery to a room.

Two things this deliberately does NOT do:

  • It does not fake a human. Tools that block on a person (request_review, await_user_decision) must fail LOUDLY rather than receive a synthetic answer — a fabricated approval is worse than no approval. Those tools check ToolContext.matrix_live and refuse; the client never invents a vote.

  • It does not silently swallow. Room ids and event ids are synthetic but marked (!null-…/$null-…), so anything that logs or asserts on them shows plainly that no room existed.

__init__(*, homeserver='<null>', user_id='@null:local')[source]
async login(password)[source]
async create_room(name, topic='', invite=None, initial_state=None)[source]
async send_state_event(room_id, event_type, content, state_key='')[source]
async send_event(room_id, event_type, content)[source]
async get_room_state(room_id)[source]
async get_room_timeline(room_id, limit=100, since=None)[source]
async upload_file(file_path)[source]
async download_file(mxc_uri, dest_dir)[source]
async sync_once(timeout_ms=30000, since=None, rooms=None)[source]
async close()[source]
class agora.matrix.client.SyncBatch[source]

Bases: object

One batch of events returned by sync_once.

events is a list of (room_id, event_dict) tuples, each shaped like a raw Matrix timeline event (type, event_id, sender, content, optional state_key). next_since is the token to pass to the next sync_once call.

events: list[tuple[str, dict[str, Any]]]
next_since: str | None
__init__(events, next_since)
class agora.matrix.client.AgoraMatrixClient[source]

Bases: object

Concrete MatrixClientProtocol backed by nio.AsyncClient.

__init__(homeserver, user_id, device_name='agora', client=None)[source]
async login(password)[source]
async create_room(name, topic='', invite=None, initial_state=None)[source]
async send_state_event(room_id, event_type, content, state_key='')[source]
async send_event(room_id, event_type, content)[source]

Post a timeline event.

Some homeservers (notably Conduit) reject custom event types in /send with HTTP 500. We wrap any non-m.room.* type into an m.room.message envelope with com.agora.type / com.agora.data for loss-free round-trip. unwrap_envelope() on the read side restores the original type.

async get_room_state(room_id)[source]
async get_room_timeline(room_id, limit=100, since=None)[source]
async upload_file(file_path)[source]
async download_file(mxc_uri, dest_dir)[source]

Download an mxc:// URI into dest_dir and return the local path.

Caches by a hash of the MXC URI; subsequent calls with the same URI return the cached path without re-downloading.

async sync_once(timeout_ms=30000, since=None, rooms=None)[source]

Long-poll /sync once. Returns one batch of events + the next token.

async close()[source]
agora.matrix.client.wrap_for_homeserver(event_type, content)[source]

Map a domain event type + content to what we actually send over the wire.

Only Agora’s own custom events (m.agora.*) are wrapped in an m.room.message envelope — those are the ones Conduit rejects with HTTP 500. Every other event type (m.room.*, m.poll.*, m.reaction, m.space.*, …) is Matrix-spec and passes through so native clients like Element render them correctly.

agora.matrix.client.unwrap_envelope(event)[source]

If event is an Agora envelope, return an event dict with the original type/content. Otherwise return event unchanged.