Metadata-Version: 2.4
Name: constitutional-swarm
Version: 1.1.0
Summary: Constitutional Swarm Mesh — orchestrator-free multi-agent governance via embedded Agent DNA
Author-email: ACGS Team <hello@acgs.ai>
License-Expression: AGPL-3.0-or-later
Project-URL: Homepage, https://acgs.ai
Project-URL: Documentation, https://github.com/dislovelhl/Acgs-Swarm#readme
Project-URL: Repository, https://github.com/dislovelhl/Acgs-Swarm
Project-URL: Issues, https://github.com/dislovelhl/Acgs-Swarm/issues
Project-URL: Changelog, https://github.com/dislovelhl/Acgs-Swarm/releases
Project-URL: PyPI, https://pypi.org/project/constitutional-swarm/
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: acgs-lite<5,>=2.8.1
Requires-Dist: cryptography>=44.0.2
Requires-Dist: pydantic<3,>=2
Requires-Dist: pyyaml>=6.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
Requires-Dist: ruff==0.17.1; extra == "dev"
Requires-Dist: mypy<3,>=2; extra == "dev"
Requires-Dist: numpy>=1.24; extra == "dev"
Requires-Dist: jsonschema>=4.18; extra == "dev"
Provides-Extra: braintrust
Requires-Dist: braintrust==0.46.0; extra == "braintrust"
Provides-Extra: bittensor
Requires-Dist: bittensor<11,>=7.0; extra == "bittensor"
Provides-Extra: transport
Requires-Dist: websockets>=12.0; extra == "transport"
Provides-Extra: postgres
Requires-Dist: psycopg[binary]<4,>=3.2; extra == "postgres"
Provides-Extra: research
Requires-Dist: torch>=2.0; extra == "research"
Requires-Dist: transformers>=4.40; extra == "research"
Requires-Dist: numpy>=1.24; extra == "research"
Provides-Extra: latent
Requires-Dist: constitutional-swarm[research]; extra == "latent"
Provides-Extra: finetune
Requires-Dist: constitutional-swarm[research]; extra == "finetune"
Requires-Dist: trl>=0.9; extra == "finetune"
Requires-Dist: peft>=0.11; extra == "finetune"
Provides-Extra: semantic
Requires-Dist: sentence-transformers>=2.5; extra == "semantic"
Provides-Extra: vertex
Requires-Dist: anthropic[vertex]>=0.84; extra == "vertex"
Requires-Dist: google-cloud-aiplatform>=1.50; extra == "vertex"
Provides-Extra: gemini
Requires-Dist: google-genai>=0.3; extra == "gemini"
Provides-Extra: langgraph
Requires-Dist: langgraph<1.3,>=1.1.10; extra == "langgraph"
Requires-Dist: langgraph-checkpoint>=3.0.1; extra == "langgraph"
Requires-Dist: langgraph-prebuilt>=1.0.5; extra == "langgraph"
Requires-Dist: langchain<2.0,>=1.0; extra == "langgraph"
Requires-Dist: langchain-core<2.0,>=1.0; extra == "langgraph"
Requires-Dist: langchain-anthropic>=1.0; extra == "langgraph"
Provides-Extra: langgraph-swarm
Requires-Dist: constitutional-swarm[langgraph]; extra == "langgraph-swarm"
Requires-Dist: langgraph-swarm>=0.1.0; extra == "langgraph-swarm"
Dynamic: license-file

# constitutional-swarm
[![PyPI](https://img.shields.io/pypi/v/constitutional-swarm)](https://pypi.org/project/constitutional-swarm/)
[![Python](https://img.shields.io/pypi/pyversions/constitutional-swarm)](https://pypi.org/project/constitutional-swarm/)
[![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)

**Orchestrator-free constitutional governance runtime for multi-agent systems.**

## 30-second explanation
`constitutional-swarm` extends `acgs-lite` from governing single actions to governing societies of agents.
It combines local constitutional enforcement (`AgentDNA`), DAG-based swarm execution (`SwarmExecutor`), peer validation (`ConstitutionalMesh`), durable settlement stores, replayable governance receipts, and bounded trust dynamics.

This package is **not** a generic agent framework and **not** an all-in-one orchestration platform.
It is a governance runtime you can embed into your existing agent stack.

Public import policy: `docs/API_COMPATIBILITY.md`. Hardcoded historical pins
such as `443 ns`, `2,656%`, or official SWE-bench scores are **not** current
product claims.

## Why it exists
Most multi-agent systems can execute tasks, but fewer can show:
- what policy was applied,
- which peers validated outputs,
- what decision was settled,
- and how to replay evidence later.

`constitutional-swarm` focuses on governed execution and verifiable governance evidence.

## What this package provides
- Local constitutional checks on agent actions (`AgentDNA`)
- Orchestrator-free task execution over DAGs (`DAGCompiler`, `SwarmExecutor`)
- Peer validation with signed votes and quorum settlement (`ConstitutionalMesh`)
- Durable settlement persistence (`JSONLSettlementStore`, `SQLiteSettlementStore`)
- Replayable governance receipts and verifier tooling (`governance_receipts`, `acgs-verify-receipts`)
- Trust-dynamics modules with bounded projection (`spectral_sphere`, `manifold` baseline)

## What this package does not provide
- A full hosted agent platform
- Turnkey workflow UI / dashboards
- Compliance certification or regulator approval
- A claim that all modules are production-ready
- A replacement for your existing model/runtime/orchestration tools

## What this is / what this is not
| This is | This is not |
|---|---|
| An orchestrator-free governance runtime | A generic no-governance multi-agent framework |
| Local constitutional enforcement + peer validation | A centralized coordinator product |
| Durable settlement + replayable receipts | A compliance certificate |
| Stable eager façade plus lazy legacy imports | A promise that `import *` still dumps research symbols |

## Install
Requires Python **3.11+** (`pyproject.toml`).

```bash
# Core runtime
pip install constitutional-swarm

# Optional extras
pip install "constitutional-swarm[dev]"              # pytest, ruff, mypy, numpy (tests)
pip install "constitutional-swarm[transport]"        # websockets remote-vote transport
pip install "constitutional-swarm[research]"         # torch + transformers + numpy
pip install "constitutional-swarm[latent]"           # deprecated alias of research
pip install "constitutional-swarm[finetune]"         # research + trl/peft recipe
pip install "constitutional-swarm[semantic]"         # sentence-transformers role-drift
pip install "constitutional-swarm[bittensor]"        # Bittensor subnet integration
pip install "constitutional-swarm[langgraph]"        # LangGraph runtime adapter
pip install "constitutional-swarm[langgraph-swarm]"  # LangGraph handoff topology
pip install "constitutional-swarm[vertex]"           # Anthropic-on-Vertex SWE-bench agent
pip install "constitutional-swarm[gemini]"           # Gemini SWE-bench agent
pip install "constitutional-swarm[braintrust]"       # optional testnet/eval telemetry
```

## 5-minute quickstart
Create `quickstart.py`:

```python
from acgs_lite import Constitution
from constitutional_swarm import AgentDNA, ConstitutionalMesh

# 1) Local constitutional enforcement
# Start with default constitutional rules, then load custom rules as needed.
agent = AgentDNA.default(agent_id="worker-1")
validation = agent.validate("summarize the meeting notes")
assert validation.valid

# 2) Peer-validated settlement
constitution = Constitution.default()
# quorum is the accept threshold (2 of 3 peers). quorum_met also needs every
# assigned peer to have voted, so the loop below votes with all of them.
required_votes = 2
# This demo holds every signing key in one process, so it must opt in to the
# single-operator dev evidence mode. Evidence produced in this mode is labelled
# "single_operator_dev" and is rejected by the default verifiers. Production
# meshes keep the default ("independent") and register remote voters with
# register_remote_agent.
mesh = ConstitutionalMesh(
    constitution,
    peers_per_validation=3,
    quorum=required_votes,
    evidence_mode="single_operator_dev",
)
mesh.register_local_signer("producer", domain="writing")
mesh.register_local_signer("peer-1", domain="writing")
mesh.register_local_signer("peer-2", domain="writing")
mesh.register_local_signer("peer-3", domain="writing")

assignment = mesh.request_validation("producer", "safe draft content", "artifact-1")
for voter_id in assignment.peers:
    mesh.submit_vote(
        assignment.assignment_id,
        voter_id,
        approved=True,
        reason="constitutional check passed",
        signature=mesh.sign_vote(
            assignment.assignment_id,
            voter_id,
            approved=True,
            reason="constitutional check passed",
        ),
    )

result = mesh.get_result(assignment.assignment_id)
print(result.accepted, result.quorum_met, result.settled)
```

Run it:

```bash
python quickstart.py
```

Expected: settled quorum result (`accepted=True`, `quorum_met=True`, `settled=True`).

## Architecture in one view
```text
Agent call/input
  -> AgentDNA (local constitutional enforcement)
  -> DAGCompiler + SwarmExecutor (orchestrator-free execution)
  -> ConstitutionalMesh (peer validation + signed votes)
  -> SettlementStore (durable finalization evidence)
  -> Governance receipts / verifier (replayable audit trail)
  -> Trust dynamics (spectral_sphere current direction, manifold baseline control)
```

## Maturity tiers
### Stable core
- `AgentDNA`
- `DAGCompiler`, `TaskDAG`, `SwarmExecutor`
- `ConstitutionalMesh` signed-vote workflow
- `JSONLSettlementStore`, `SQLiteSettlementStore`
- Governance receipts + verifier CLI (`acgs-verify-receipts`)

### Advanced runtime (stable APIs, optional in many deployments)
- Remote vote transport (`constitutional_swarm.remote_vote_transport`, `[transport]`)
- `EvolutionLog` invariant-enforced governance metrics
- `SpectralSphereManifold` bounded trust dynamics (current direction)
- LangGraph runtime adapter (`[langgraph]`, `[langgraph-swarm]`)
- Bittensor integration (`[bittensor]`)

### Research / experimental modules
- `latent_dna` (BODES-based steering hooks, `[research]`)
- `swarm_ode`
- `merkle_crdt` + `gossip_protocol`
- `swe_bench/` evaluation modules and scripts
- `manifold.py` Birkhoff/Sinkhorn baseline retained as research control

## Core concepts
- **Governed execution:** each step can be policy-checked before execution/acceptance.
- **Local constitutional enforcement:** policy checks run inside the agent runtime path.
- **Peer validation:** assigned peers vote on outputs with signatures.
- **Durable settlement:** final decisions are persisted as replayable evidence.
- **Replayable receipts:** governance receipts are canonicalized and verifiable.
- **Bounded trust dynamics:** trust updates are projected into bounded manifolds.

## Common use cases
- Governed agent execution in coding/review workflows
- Peer-validated output acceptance before downstream automation
- Decentralized or orchestrator-free agent task flows
- Governance receipt generation and settlement evidence retention
- Research experiments on trust dynamics and swarm behavior

## When to use this package
Use `constitutional-swarm` when you need:
- verifiable governance steps inside agent workflows,
- peer-validated acceptance/rejection,
- durable, replayable governance evidence,
- explicit separation between stable runtime and research modules.

## When not to use this package
Choose another tool first when you need:
- only basic orchestration with no governance/validation,
- a hosted platform with UI-first operations,
- fully fixed APIs across all experimental modules,
- compliance attestations by default.

## Examples
- `examples/constitution.yaml` — minimal constitution config
- `examples/langgraph_swarm_demo.py` — LangGraph adapter example
- `examples/governed-handoff/` — governed coding-agent handoff demo
- See [`docs/examples.md`](docs/examples.md) for task-oriented walkthroughs

## Security and trust boundaries
- See [`SECURITY.md`](SECURITY.md) for vulnerability reporting and support policy.
- See [`docs/security-model.md`](docs/security-model.md) for technical trust boundaries.
- Signed votes are required for `ConstitutionalMesh.submit_vote`.
- Remote vote transport security mode should be configured explicitly for non-loopback use.
- Treat optional research modules as experimental surfaces, not hardened defaults.

## Documentation map
> **Maintainers & AI agents:** start at the consolidated wiki —
> [`docs/wiki/`](docs/wiki/README.md). It ties these docs together with
> per-module code logic, end-to-end runtime flows, the roadmap, and a handoff
> checklist.

| Audience | Start here | Then read |
|---|---|---|
| New contributors | [`docs/quickstart.md`](docs/quickstart.md) | [`CONTRIBUTING.md`](CONTRIBUTING.md), [`docs/community.md`](docs/community.md) |
| Runtime integrators | [`docs/concepts.md`](docs/concepts.md) | [`docs/architecture.md`](docs/architecture.md), [`docs/security-model.md`](docs/security-model.md) |
| Agent-framework maintainers | [`docs/architecture.md`](docs/architecture.md) | [`docs/langgraph_runtime.md`](docs/langgraph_runtime.md), [`MIGRATION.md`](MIGRATION.md) |
| Governance/community contributors | [`docs/community.md`](docs/community.md) | [`docs/roadmap.md`](docs/roadmap.md), [`docs/faq.md`](docs/faq.md) |
| Researchers | [`docs/roadmap.md`](docs/roadmap.md) | [`docs/maci_dp_protocol.md`](docs/maci_dp_protocol.md), [`paper/README.md`](paper/README.md), `docs/internal/*` |

## Verification commands

This repo is `uv`-managed; prefer the one-command targets (see [`TOOLS.md`](TOOLS.md)):

```bash
make setup        # create the venv + install dev extras (standalone-safe)
make verify       # lint -> agent-check -> smoke -> tests
make agent-check  # validate agent/tool registries + doc completeness
```

The equivalent raw invocations run through the venv (no global `python`/`pip`/`ruff` is assumed):

```bash
uv run --no-sync ruff check src/constitutional_swarm/
uv run --no-sync ruff format --check src/
uv run --no-sync pytest tests/ --import-mode=importlib -q
uv run --no-sync pytest -m "not slow and not e2e and not research" tests/ --import-mode=importlib -q
uv build
```

If optional extras are installed, run targeted suites (for example transport or research-marked tests).

## Contributing
- Contribution guide: [`CONTRIBUTING.md`](CONTRIBUTING.md)
- Code of conduct: [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md)
- Security policy: [`SECURITY.md`](SECURITY.md)

## Roadmap
See [`docs/roadmap.md`](docs/roadmap.md).

## License
AGPL-3.0-or-later (see package metadata in `pyproject.toml`).
