Stigmergic Blackboard Protocol - Python Client SDK
Project description
SBP Python Client
Python SDK for the Stigmergic Blackboard Protocol.
Installation
pip install sbp-client
Quick Start
from sbp import SbpClient, ThresholdCondition
# Connect to the blackboard
with SbpClient("http://localhost:3000") as client:
# Emit a pheromone
client.emit(
trail="market.signals",
type="volatility",
intensity=0.8,
payload={"symbol": "BTC-USD", "vix": 45.2},
)
# Sniff the environment
result = client.sniff(trails=["market.signals"])
for p in result.pheromones:
print(f"{p.trail}/{p.type}: {p.current_intensity:.2f}")
Local Mode (No Server Required)
You can run SBP entirely in-memory within a single process. This is useful for testing, simulations, or simple multi-agent scripts where you don't want to manage a separate server process.
from sbp import SbpClient, SbpAgent
# Client in local mode
with SbpClient(local=True) as client:
client.emit("local.test", "signal", 0.9)
# Agent in local mode
# Note: In a single process, all local=True instances share the same blackboard state.
agent = SbpAgent("my-agent", local=True)
@agent.when("local.test", "signal", value=0.5)
async def handle(trigger):
print("Received signal locally!")
Async Usage
import asyncio
from sbp import AsyncSbpClient, ThresholdCondition
async def main():
async with AsyncSbpClient() as client:
# Emit
await client.emit("signals", "event", 0.7)
# Register a scent (trigger condition)
await client.register_scent(
"my-scent",
condition=ThresholdCondition(
trail="signals",
signal_type="event",
aggregation="max",
operator=">=",
value=0.5,
),
)
# Subscribe to triggers via WebSocket
async def on_trigger(trigger):
print(f"Triggered! {trigger.scent_id}")
await client.subscribe("my-scent", on_trigger)
asyncio.run(main())
Declarative Agent Framework
from sbp import SbpAgent, TriggerPayload, run_agent
agent = SbpAgent("my-agent", "http://localhost:3000")
@agent.when("tasks", "new_task", operator=">=", value=0.5)
async def handle_task(trigger: TriggerPayload):
print(f"Got task: {trigger.context_pheromones}")
await agent.emit("tasks", "completed", 1.0)
run_agent(agent)
API Reference
SbpClient / AsyncSbpClient
| Method | Description |
|---|---|
emit(trail, type, intensity, ...) |
Deposit a pheromone |
sniff(trails, types, ...) |
Read environment state |
register_scent(scent_id, condition, ...) |
Register a trigger |
deregister_scent(scent_id) |
Remove a trigger |
subscribe(scent_id, handler) |
Listen for triggers (async only) |
inspect(include) |
Get blackboard metadata |
evaporate(...) |
Force cleanup |
Condition Types
# Simple threshold
ThresholdCondition(
trail="market.signals",
signal_type="volatility",
aggregation="max", # sum, max, avg, count, any
operator=">=", # >=, >, <=, <, ==, !=
value=0.7,
)
# Composite (AND/OR/NOT)
CompositeCondition(
operator="and",
conditions=[condition1, condition2],
)
# Rate-based
RateCondition(
trail="events",
signal_type="click",
metric="emissions_per_second",
window_ms=10000,
operator=">=",
value=5.0,
)
Decay Models
from sbp.types import exponential_decay, linear_decay, immortal
# Exponential (default) - half-life in milliseconds
decay = exponential_decay(half_life_ms=300000) # 5 minutes
# Linear - rate per millisecond
decay = linear_decay(rate_per_ms=0.0001)
# Immortal - never decays
decay = immortal()
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sbp_client-0.2.0.tar.gz.
File metadata
- Download URL: sbp_client-0.2.0.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d184abb2a48f4ef0f7dc05d3ca54ee324cf76e51ed2e27c6d9324193916a4df9
|
|
| MD5 |
432c05ea45ee4b6e6c27001030dc7fa7
|
|
| BLAKE2b-256 |
d20d191912a9891ac988872adccfcd9b35df1baa0a10c3de5d2ad8fe96fabbb9
|
File details
Details for the file sbp_client-0.2.0-py3-none-any.whl.
File metadata
- Download URL: sbp_client-0.2.0-py3-none-any.whl
- Upload date:
- Size: 21.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7e31fd4c248f6dbe6e4762f83dc994e2daf009f98fdd76bc03231896863290f
|
|
| MD5 |
1244575c20dcc296ac82bb930f01c21b
|
|
| BLAKE2b-256 |
a5ed5d3ab80856b34110abe23870318da99904390a17d65af55a3c1586ccb0a1
|