A Bayesian Energy-Aware Framework for Multi-Agent Communication Optimization under Incomplete Information
Documentation · Quick start · Tests
BEAM jointly models agent participation and communication links. Energy combines contribution and communication cost, pairwise Gaussian-process moments represent uncertainty, and task feedback with nuclear-norm, variance and GP prior regularization trains the graph distribution. Deployment constructs a feasible DAG and executes its selected agents and links.
Download and extract the repository, then open a terminal in its root directory.
python -m venv .venv
source .venv/bin/activate
python -m pip install -e .
python -m beam.examples.bayesian_workflowThe example runs calibration, fixed-target reference sampling and deployment on CPU with deterministic callbacks. It requires no API key. Python 3.9+ and PyTorch 2.0+ are supported.
| Stage | Implementation | Purpose |
|---|---|---|
| Observation and energy | set_completeness, update_energy |
Retained-information coefficients and square-root energy updates |
| Score uncertainty | SparsePairGP, probabilities |
Inducing-variable moments and Gaussian exceedance probabilities |
| Calibration | train / atrain |
Node and centered edge scores with three regularizers |
| Reference chain | sample_reference |
Fixed-mask single-edge Metropolis–Hastings |
| Deployment | run / run_sync |
Gaussian edge draws, cycle repair and strict frequency consensus |
| Execution | AgentGraph.arun_state |
Exact active-node and edge execution with isolated request buffers |
import asyncio
from beam.examples.bayesian_workflow import build_example
async def main():
strategy = build_example()
stats = await strategy.atrain(
[{"task": "What is 2 + 2?", "answer": "4"}],
lambda prediction, answer: float(prediction == answer),
num_iterations=1,
)
answers, graph = await strategy.run({"task": "What is 2 + 2?"})
print(answers, graph["node_mask"], graph["adjacency"])
asyncio.run(main())Use AgentNode callbacks or an LLM client to define agents. Register nodes with graph.add_node(node) in the intended state-coordinate order, then call strategy.set_graph(graph). See the API reference for complete construction and persistence interfaces.
python -m pip install -e '.[dev]'
python -m pytest -q
python -m pip install -r requirements-docs.txt
python -m mkdocs build --strict
python scripts/check_site.pyTests cover all 25 DAGs on three active nodes and all node masks. They verify detailed balance, stationarity, the joint score gradient, GP covariance and KL, energy transitions, DAG execution, integration masks and checkpoint continuation. CI runs Python 3.9 and 3.12. The static documentation site deploys through GitHub Pages artifacts from main.
- AgentBayesian implements the joint model and algorithms above;
TokenOptimizer(config, graph)delegates to it whenconfig.optimization.strategy="bayesian". - AgentPrune and AgentDropout expose separate edge-pruning and agent-skipping interfaces.
- LangChain runnables can supply an agent's execution callback.
- LangGraph adapters map named nodes to explicit adjacency coordinates.
Optional integrations: python -m pip install -e '.[langchain,langgraph]'.
MIT.
