Skip to main content

Metastable consensus protocol for multi-agent agreement

Project description

hanzo-consensus

Metastable consensus protocol for multi-agent agreement.

Install

pip install hanzo-consensus

Basic Usage

import asyncio
from hanzo_consensus import run, Result

async def execute(participant: str, prompt: str) -> Result:
    output = await call_agent(participant, prompt)
    return Result(id=participant, output=output, ok=True, ms=100)

async def main():
    state = await run(
        prompt="What is the best approach?",
        participants=["agent1", "agent2", "agent3"],
        execute=execute,
        rounds=3,
    )
    print(f"Winner: {state.winner}")
    print(f"Synthesis: {state.synthesis}")

asyncio.run(main())

MCP Mesh - Agent-to-Agent Consensus

Each agent in consensus is available as MCP to every other:

from hanzo_consensus import MCPMesh, run_mcp_consensus

# Create mesh of agents
mesh = MCPMesh()
mesh.register("claude", claude_server)
mesh.register("gpt4", gpt4_server)
mesh.register("gemini", gemini_server)

# Run 10 rounds of discussion
state = await run_mcp_consensus(
    mesh=mesh,
    prompt="Discuss the architecture",
    rounds=10,
)

# Access discussion history
for i, round_responses in enumerate(state.discussion_history):
    print(f"Round {i+1}:")
    for agent, response in round_responses.items():
        print(f"  [{agent}]: {response[:100]}...")

MCPMesh Features

  • Agent Registration: Local FastMCP servers or remote endpoints
  • Tool Calling: Any agent can call tools on any other agent
  • Broadcasting: Call a tool on all agents simultaneously
  • Discussion Rounds: Agents build on each other's responses
# Call tool on specific agent
result = await mesh.call("claude", "gpt4", "think", prompt="What do you think?")

# Broadcast to all agents
results = await mesh.broadcast("claude", "discuss", prompt="New proposal...")

Protocol

Two-phase finality:

Phase I (Sampling)

  • Each participant proposes initial response
  • k-peer sampling per round
  • Luminance-weighted selection (faster = higher weight)
  • Confidence accumulation toward β₁

Phase II (Finality)

  • Threshold aggregation
  • β₂ finality threshold
  • Winner synthesis

Parameters

Param Default Description
rounds 3 Sampling rounds
k 3 Sample size per round
alpha 0.6 Agreement threshold
beta_1 0.5 Preference threshold (Phase I)
beta_2 0.8 Decision threshold (Phase II)

Reference

https://github.com/luxfi/consensus

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hanzo_consensus-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hanzo_consensus-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file hanzo_consensus-0.1.0.tar.gz.

File metadata

  • Download URL: hanzo_consensus-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for hanzo_consensus-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8193816d297b2bfa85f6c752b325ac7b38dcc0ec6439a0421777a9b92ca8f740
MD5 d9dd9c9e4f3a6d836343c99db1b5d011
BLAKE2b-256 221a0dddd14f023b5d0609bc326675c5c2be1696e2ebde0c89915493d6761af0

See more details on using hashes here.

File details

Details for the file hanzo_consensus-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hanzo_consensus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 023dc9939a1d561bfdd89eb02267d23a4f0810227936b6c6721cb890b5a12c9c
MD5 a6d09f4610bf04566324fae17d294d84
BLAKE2b-256 96d7215e4e1df9668ba27c0c64524634a63c58b6c884059d7d7fad55c64d5c8a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page