in reviewhumanPR #345Identity
GridPact: add A2A adapter and Path-mode duplicate and conflict test
GridPact is a peer-to-peer energy-trading protocol for grid agents: agents trade over an MCP server with a locked stake, a hash-chained ledger, deterministic settlement and an auditor that can challenge over-declared capacity.
Description
The pitch.
## Summary GridPact is a peer-to-peer energy-trading protocol for grid agents: agents trade over an MCP server with a locked stake, a hash-chained ledger, deterministic settlement and an auditor that can challenge over-declared capacity. It lives in its own repository, <https://github.com/nh13120/gridpact>, and runs there. This PR adds only the Town side of a compatibility check: a small A2A adapter (`examples/gridpact/gridpact_a2a.py`), a script that runs the check, saved evidence, tests, and a README. The seller's accept and the auditor's challenge can be decided by a Claude Haiku agent (`--llm`) or by a fixed rule (default). Town's Path mode can then test GridPact end to end, including the audit and settlement steps, not only a trade. ## Integration `nandatown test-agent --url ...` calls the adapter as an A2A agent. For each Town quote request the adapter plays one GridPact order through a real GridPact server over MCP (streamable HTTP): `propose` with the order's `request_id` as GridPact's idempotency key, `respond accept` as the seller (stake locked, commitment on the ledger), then an auditor agent checks the seller's declared capacity against its nameplate and `challenge`s a lie, then GridPact settles delivery for that commitment (a guarded `operator_settle` tool). The quote it returns (`total_cents`, `commitment_id`, audit verdict, delivered kWh) is read back from GridPact, not computed by the adapter. GridPact stays a separately hosted service; the adapter uses only `httpx`, `fastapi` and `uvicorn`, which Town already depends on, and touches no Town source files. ## Reproduce - Town commit: `6f9a7c0` (main on 2026-11-11). GridPact: tag `hw8-v2`. Python 3.14. - No data files. The default run needs no API key; `LLM=1` (Haiku seller and auditor) needs `ANTHROPIC_API_KEY`, about a cent per run. ```bash git clone --branch hw8-v2 https://github.com/nh13120/gridpact.git python3 -m venv gridpact/.venv && gridpact/.venv/bin/pip install -r gridpact/requirements.txt python3 -m venv .venv && source .venv/bin/activate && pip install -e '.[dev]' export GRIDPACT_DIR=$PWD/../gridpact GRIDPACT_PYTHON=$PWD/../gridpact/.venv/bin/python examples/gridpact/run_check.sh runs/gridpact-honest # honest seller LLM=1 VARIANT=liar examples/gridpact/run_check.sh runs/gridpact-liar-haiku # Haiku seller + auditor VARIANT=liar examples/gridpact/run_check.sh runs/gridpact-liar # seller declaring 2x its battery python -m pytest -q tests/test_gridpact_adapter.py ``` `run_check.sh` starts a fresh GridPact server and the adapter per profile, runs `a2a-capability-fulfillment@0.3` and `a2a-order-conflict@0.1`, and prints each stage and what GridPact recorded. Without `GRIDPACT_DIR` the 12 unit tests (fake GridPact, no network) still run and the integration test skips. The full Town suite passes with `GRIDPACT_DIR` and `ANTHROPIC_API_KEY` set: 1879 passed, 0 skipped (including the integration test with the scripted and the Haiku agents). Without them the integration tests skip. I also ran the integration test from a fresh clone of the `hw8-v2` tag. ## Results and limitations | | expected | GridPact `v2` (before) | `hw8-v2` honest | `hw8-v2` over-declaring seller | |---|---|---|---|---| | quote | total 3990 cents | 3990 | 3990 | 3990 | | `duplicate_request` | no second fulfillment | Failed: second, different quote | Passed | Passed | | `conflicting_retry` | `rejected`, first quote stands | Failed: re-quoted 9975 | Passed | Passed | | GridPact commitments per profile | 1 | 2 | 1 | 1 | | audit | none / valid challenge | not run | none | valid challenge, $12 bounty | | delivery of the 2 MWh ordered | all / what the battery can give | not run | 2000 kWh | 1250 kWh (trimmed 1000 to 625 kWh/step), no penalty | Failure found from outside: GridPact's `propose` had no request id, so a retried proposal opened a second offer and accepting both double-booked the seller. Town's duplicate and conflict stages caught it; the fix (optional `re …
Try it
Open PR on GitHubView diffCheckout locally
git fetch origin pull/345/head:pr-345
git checkout pr-345