EventBus
Messaging is part of ISH's context and coordination layer: it lets agents exchange events and targeted messages. It differs from shared working state. EventBus delivers notifications inside a running application; ContextStore holds named values agents can read or update; SqliteMailbox queues messages that must survive a process restart. A notification can point an agent to shared context, but the context record remains in ContextStore and is not copied or synchronized by the event system.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish import EventBus
bus = EventBus()
subscription = bus.subscribe("build.*")
bus.publish_sync("build.api", {"status": "complete"}, source="builder")
page = bus.poll(subscription)
print(page)
import { EventBus, IshClient } from "ish-harness";
const client = new IshClient();
const bus = new EventBus(client);
const subscription = bus.subscribe("build.*");
bus.publish("build.api", { status: "complete" }, "builder");
const page = bus.poll(subscription);
console.log(page);
bus.close();
client.close();
use ish_harness::EventBus;
let bus = EventBus::new();
let mut rx = bus.subscribe("build.*");
bus.publish_event("build.api", "builder", r#"{"status":"complete"}"#);
while let Ok(payload) = rx.try_recv() {
println!("Event: {payload}");
}
bus, err := ish.NewEventBus(client, nil, 0)
if err != nil {
panic(err)
}
defer bus.Close()
subscription, err := bus.Subscribe(ish.StringPtr("build.*"))
if err != nil {
panic(err)
}
_, err = bus.Publish("build.api", map[string]any{"status": "complete"}, ish.StringPtr("builder"))
page, err := bus.Poll(subscription, nil)
fmt.Println(page)
using System.Text.Json;
using Ish.Harness;
using var client = new IshClient();
using var bus = new EventBus(client);
var subscription = bus.Subscribe("build.*");
using var payload = JsonDocument.Parse("{\"status\":\"complete\"}");
bus.Publish("build.api", payload.RootElement, source: "builder");
var page = bus.Poll(subscription);
Console.WriteLine(page);
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.ishharness.EventBus;
import io.github.ishharness.IshClient;
import java.nio.file.Path;
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")));
var bus = new EventBus(client)) {
String subscription = bus.subscribe("build.*");
var payload = new ObjectMapper().createObjectNode().put("status", "complete");
bus.publish("build.api", payload, "builder");
var page = bus.poll(subscription);
System.out.println(page);
}
Event delivery
Routing
Topic matching
- A subscription matches events using the configured topic grammar. A subscriber receives an event once even if multiple patterns match.
- Subscriptions are local to the process. Reconnecting clients can read retained history or their unread inbox when those features are enabled.
- Selectable
TopicGrammar:Fnmatch(default): Usespermissions::fnmatch_simplesupporting glob*and?across the full topic string.Mqtt: Splits topic and pattern on.segments (mqtt_match), treating+or*as a single-segment wildcard and#or**as a trailing multi-segment wildcard (#/**only match at the final segment of the pattern). Each subscriber has a bounded in-memory queue. If it falls behind, the poll result reports missed events so the consumer can catch up or reload state.
Event IDs, unread cursors
- Events include an identifier, topic, source, JSON payload, and timestamp. If no source is supplied, the runtime labels it
system. - Messages sent to an agent inbox can be read as unread messages or filtered by timestamp. Reading unread messages advances that recipient's inbox cursor.
Targeted inbox messages
Publishing to inbox.<recipient> (send_to in Python) makes the message
retrievable from that process's inbox through poll_inbox / inbox. This is
not restart-safe; use SqliteMailbox when queued delivery must survive a
process exit:
- Python
- TypeScript
- Rust
- Go
- C#
- Java
import asyncio
from ish import EventBus
async def main() -> None:
bus = EventBus()
await bus.send_to("worker", {"task": "lint"}, sender="coordinator")
unread = bus.poll_inbox("worker", unread_only=True)
print(unread)
asyncio.run(main())
import { EventBus, IshClient } from "ish-harness";
const client = new IshClient();
const bus = new EventBus(client);
bus.publish("inbox.worker", { task: "lint" }, "coordinator");
const unread = bus.inbox("worker", true);
console.log(unread);
bus.close();
client.close();
use ish_harness::EventBus;
let bus = EventBus::new();
bus.publish_event("inbox.worker", "coordinator", r#"{"task":"lint"}"#);
let unread = bus.poll_inbox("worker", true);
println!("Unread inbox messages: {}", unread.len());
_, err := bus.Publish("inbox.worker", map[string]any{"task": "lint"}, ish.StringPtr("coordinator"))
if err != nil {
panic(err)
}
unreadOnly := true
messages, err := bus.Inbox("worker", &unreadOnly, nil)
fmt.Println(messages)
using System.Text.Json;
using var msg = JsonDocument.Parse("{\"task\":\"lint\"}");
bus.Publish("inbox.worker", msg.RootElement, source: "coordinator");
var unread = bus.Inbox("worker", unreadOnly: true);
Console.WriteLine(unread);
var msg = new ObjectMapper().createObjectNode().put("task", "lint");
bus.publish("inbox.worker", msg, "coordinator");
var unread = bus.inbox("worker", true);
System.out.println(unread);
Host callbacks
Register process-local subscribers when handling events inline. Rust owns callback registration order, topic matching, and deduplication; each SDK keeps only the user callback reference and invokes the callbacks returned by Rust. Unsubscribe hooks detach the Rust registration and release the host reference. Callback failures are recorded in the bounded Rust diagnostics buffer, with the stable handler label handler across SDKs:
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish import EventBus
bus = EventBus()
unsubscribe = bus.subscribe("build.*", lambda ev: print("Event:", ev.topic, ev.payload))
bus.publish_sync("build.ui", {"ok": True}, source="ci")
unsubscribe()
import { EventBus, IshClient } from "ish-harness";
const client = new IshClient();
const bus = new EventBus(client);
const unsubscribe = bus.subscribe("build.*", (event) => {
console.log("Event:", event.topic, event.payload);
});
bus.publish("build.ui", { ok: true }, "ci");
unsubscribe();
bus.close();
client.close();
use ish_harness::EventBus;
let bus = EventBus::new();
let (mut rx, subscriber_id) = bus.subscribe_with_id("build.*");
bus.publish("build.ui", r#"{"ok":true}"#);
if let Ok(payload) = rx.try_recv() {
println!("Delivered: {payload}");
}
bus.unsubscribe(subscriber_id);
unsubscribe, err := bus.SubscribeCallback(ish.StringPtr("build.*"), func(ev ish.EventBusEvent) error {
fmt.Println("Event:", ev.Topic, ev.Payload)
return nil
})
if err != nil {
panic(err)
}
defer unsubscribe()
_, err = bus.Publish("build.ui", map[string]any{"ok": true}, nil)
using System.Text.Json;
using var registration = bus.Subscribe("build.*", ev =>
{
Console.WriteLine($"Event: {ev.Topic} {ev.Payload}");
});
using var payload = JsonDocument.Parse("{\"ok\":true}");
bus.Publish("build.ui", payload.RootElement, source: "ci");
try (var registration = bus.subscribe("build.*", ev -> {
System.out.println("Event: " + ev.topic() + " " + ev.payload());
})) {
var payload = new ObjectMapper().createObjectNode().put("ok", true);
bus.publish("build.ui", payload, "ci");
}
Bounded mailbox behavior
Use a bounded mailbox when producers need explicit queue and payload limits or must coordinate backpressure across tenants:
FlowControlQuota Field | Default Value | Enforcement Scope |
|---|---|---|
max_queue_messages | 1000 | Maximum queued entries inside one mailbox instance |
max_queue_bytes | 10 * 1024 * 1024 (10 MiB) | Maximum sum of payload sizes inside one mailbox instance |
max_message_bytes | 1024 * 1024 (1 MiB) | Per-message payload byte cap (returns BackpressureError::MessageTooLarge) |
max_tenant_backlog_bytes | 50 * 1024 * 1024 (50 MiB) | Aggregate backlog across all mailboxes sharing a tenant_id via TenantQuotaLease |
Unlike generic drop-oldest queues, BoundedMailbox differentiates overflow behavior by MessageClass:
MessageClass | Telemetry Tag (static_telemetry_tags) | Overflow Behavior (EventOverflowPolicy) |
|---|---|---|
BestEffortTelemetry | "telemetry" | On DropOldest: pops oldest message and calls record_delivery_gap. On DropNewest: assigns monotonic sequence, calls record_delivery_gap, and returns Ok(seq). On Reject / Block: returns BackpressureError::QueueFull. Adjacent drops on the same topic coalesce into one DeliveryGapEvent (first_missing_sequence, last_missing_sequence, gap_count). |
OrdinaryNotifications | "notification" | Never silently dropped. Any queue or byte overflow returns BackpressureError::QueueFull. |
WorkflowStateTransitions | "workflow" | Never silently dropped. Any queue or byte overflow returns BackpressureError::WorkflowTransitionRejected. |
DurableMailboxMessages | "mailbox" | Rejected upfront on in-memory BoundedMailbox (before assigning a sequence) with BackpressureError::DurablePersistenceRequired. Route these through SqliteMailbox (DurableMailbox). |
Durable mailbox leases
SqliteMailbox stores messages and delivery claims in SQLite. A worker claims a message for a limited period and acknowledges it after processing:
- Message enqueue validates configured size and backlog limits before accepting a message.
- If a worker stops responding, its lease expires and another worker can claim the message.
- An expired worker cannot acknowledge a message after another worker has claimed it.
Agent tools
In Python, bus.get_tools(agent_name=...) returns tools for publishing events and sending inbox messages (plus an inbox-checking tool when agent_name is provided). Event payloads across all SDKs must be finite JSON values, and EventBus host callbacks are process-local rather than a durable delivery guarantee.