Skip to content

About

AgentSpaces Babashka Bindings

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

AgentSpaces Babashka

AgentSpaces bindings for Babashka. Query an AgentSpaces fleet from a shell, or start a peer that provides a named replicated space. Queries run entirely in Babashka. Hosting launches the AgentSpaces 0.6.0 JVM libraries in a separate JVM: bb as serve resolves the classpath from deps.edn with the Clojure CLI, then runs host/agentspaces/bb/SpaceHost.java through the JDK's single-file source launcher.

Start a space

Install Babashka (tested with 1.12.217). Hosting also requires JDK 21+, Clojure CLI, and access to the Maven artifacts in deps.edn.

bb as serve orders --entry '{"orderId":"o-1","item":"kite"}'

From another terminal:

bb as spaces
bb as entries entries '{"item":"kite"}'

The first entries is the query command and the second names the host's built-in panel. It exposes the fields of up to 100 readable agentspaces.bb.SpaceHost$Document records. Other AgentSpaces peers may use their own record types in the same space. The optional startup document has a one-hour lease; --lease PT10M sets another (ISO-8601).

Start another peer on the same machine to replicate the space:

bb as serve orders --seed 127.0.0.1:7701 --port 7702 --console-port 8081
AGENTSPACES_URL=http://127.0.0.1:8081 bb as entries entries

Each host uses a fresh peer identity. Match the space name and group founding text across peers. The default founding text is agentspaces-bb-v1. Override it with --group TEXT on both hosts. Both listeners bind to loopback. Stop with Ctrl-C. Records are held in memory and disappear when all replicas stop or the lease expires.

Timing, TTLs and health

The host is a plain Java node, so it keeps the core's timing (SPEC §9.5) in a mixed group:

  • It joins with the core's membership defaults. It judges a member that keeps itself alive at 45 s, and a member heard only through probes at 1.5 quiet probe cycles (54 s at ten members). Its own keepalive stays inside 30 s.
  • Its loop runs due work, not a fixed tick, and the process watchdog checks it every 2 s.
  • --seed takes one HOST:PORT or several separated by commas, such as --seed 127.0.0.1:7701,127.0.0.1:7703. The host joins through every seed it can reach and probes each one like any member, every few seconds and never 45 s apart. A seed that stops answering is left a few seconds after an unanswered probe, and the host carries on through the others. A link the host dialed to a seed that goes quiet for 45 s gets a PING on the link itself, and is closed if nothing arrives within 2 s, even when the seed still answers the rest of the group. Bytes of a frame still arriving count as an answer. With nobody left, it re-dials every seed in one pass on the core's back-off, never more than 30 s apart, and at once when a laptop wakes.
  • It answers and starts anti-entropy (DIGEST) with every member, so its own changes that were lost on a link are repaired.
  • A frozen process (SIGSTOP, a long GC or VM pause) is treated like a laptop wake once its loop wakes more than 30 s late. The host PINGs its seed and probes every member before judging any of them, so a member is not dropped just because the host itself was frozen.
  • Its space advertisement is re-issued every 10 minutes, so the 15-minute advertisement stays in every peer's discovery list. It is also re-issued at once when the wall clock jumps forward, such as when a laptop wakes. The core does this for every replicated space; the host adds nothing of its own.
  • It checks its TTLs at start. A --lease under 60 s logs a warning. With --ttl strict the host refuses to start instead, unless --lease-reason TEXT says why.
  • --watchdog exit stops the host with status 70 when the watchdog escalates. The default, report, keeps it running with its loop marked DOWN. Use exit when a supervisor restarts the host and nothing runs bb as health.

bb as health reads the host's loop-health panel. It prints the loop state (OK, DEGRADED or DOWN) and the reasons. It also prints the member TTL and keepalive the node uses now, and the core's seed-link counters under the names every AgentSpaces client uses: resumes (wakes: a laptop wake, a forward clock step of more than 30 s, or a loop wake more than 30 s late), wakePings, seedPings, linksSilent (links closed after an unanswered PING), seedDials, lateSeedChannels and introductionsUnanswered. It exits 1 when the state is DOWN, so a shell loop or supervisor can use it as a liveness check.

Use bin/agentspaces-bb from an extracted distribution, or put its bin directory on PATH. See CONTRIBUTING.md for testing and packaging.

Query a running fleet

Set the console base URL, including any reverse-proxy prefix. The default is http://127.0.0.1:8080.

export AGENTSPACES_URL=http://127.0.0.1:8080
bb as overview
bb as peers
bb as ads
bb as spaces
bb as space orders
bb as panels
bb as health
bb as panel order-entries
bb as entries order-entries '{"item":"kite"}'

Each command emits one JSON value on stdout. Errors go to stderr with a nonzero exit status. An empty match returns [] successfully.

space orders returns the console's statistics for the watched space. For tuple values, register a panel on the host that returns an array of records. The example uses a non-consuming readAll for the Order type, capped at 100. The client filters that snapshot by exact top-level field values. Omit the filter to see the whole snapshot. Each request reads the current panel data.

Run the example

The example host needs JDK 21+ and Clojure CLI with access to the AgentSpaces 0.6.0 Maven artifacts. From the repository root, run this in one terminal:

cd examples
java -cp "$(clojure -Spath)" OrdersConsole.java

From another terminal in the repository root, run bb as entries order-entries '{"item":"kite"}'. The seeded local space returns [{"orderId":"o-1","item":"kite"}]. To query a replicated fleet space, register the same panel on its existing console and bind it to the host's space and record class.

Use from a Babashka script

With this project's src on the Babashka classpath:

(require '[agentspaces.bb.client :as as])
(as/query "http://127.0.0.1:8080" :spaces)
(as/entries "http://127.0.0.1:8080" "order-entries" {"item" "kite"})

Run the client contract tests with bb test/client_test.clj, and the host's timing checks with bb test-host.

License

Apache License 2.0. Copyright 2026 Bad Monkey, Inc.

About

AgentSpaces Babashka Bindings

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages