in reviewhumanPR #360Transport
Rebbi: token-lending MCP integration
Rebbi lends spare token budget between the AI agents of one fleet. An agent about to run out mid-job calls post_handoff over MCP; Rebbi books a loan from an agent with budget above its reserve (LEND), or refuses with each lender's reason…
Description
The pitch.
## Summary Rebbi lends spare token budget between the AI agents of one fleet. An agent about to run out mid-job calls `post_handoff` over MCP; Rebbi books a loan from an agent with budget above its reserve (`LEND`), or refuses with each lender's reason (`CANNOT_MOVE`). `settle` returns what the borrower did not spend. This PR adds `examples/rebbi/`: a Lab integration in which Town agents use Rebbi's real MCP server as shared infrastructure for a paid job, four scenarios (clean, lost reply, duplicate delivery, no lender with room), validators, recorded evidence, and a CI-safe test (`tests/test_example_rebbi.py`). Town found a real bug. Before the fix, a borrow request that reached Rebbi twice booked two loans and left one open, while Rebbi's own ledger check still passed. Rebbi now takes a `request_id` and returns the first decision when the same request arrives again. ## Integration - **Subject:** Rebbi (`eglismella/rebbi`, private for now; access for graders on request), hosted separately, at `07da056` (with the fix) and `3db016d` (before it). It runs as its own processes in its own virtual environment. - **Interface tested:** MCP over stdio, one server process per fleet agent (`python -m rebbi.mcp_server`, identity from `REBBI_AGENT_ID`). Tools: `report_headroom`, `get_budget`, `post_handoff`, `settle`. - **Adapter (`rebbi_adapter`):** the only role that talks to Rebbi. It makes one tool call per delivered Town message, in the session of the sender Town's auth layer verified, and never removes duplicates. `rebbi_meter.py` runs in Rebbi's interpreter, meters work steps through Rebbi's own `Ledger` (as Rebbi's gateway meters model calls), and reads the final ledger and Rebbi's invariant check. - **Town scripts:** `lender-a`, `lender-b`, `worker-01`, `client`. They were written for this test and are not independently developed agents. - **Town parts used:** transport, including the drop and duplicate faults; verified senders; escrow in the payments ledger; and the evidence pipeline. - **Why a Lab scenario:** the Path and Track profiles judge a price quote, and `nandatown mcp test` stops at the handshake, so neither can judge a lending workflow. ## Reproduce Town base commit `6f9a7c0`, evaluator `lab-0.2.6`, seed 42. Rebbi `07da0565da42d74a224dcd2148c03eac0105d37a`. Recorded on Windows with Python 3.13. No model key is needed. ```bash git clone https://github.com/eglismella/rebbi.git ../rebbi # private for now: ask for access git -C ../rebbi checkout 07da0565da42d74a224dcd2148c03eac0105d37a python -m venv ../rebbi/.venv && ../rebbi/.venv/bin/python -m pip install -e ../rebbi python -m venv .venv && .venv/bin/python -m pip install -e '.[dev]' .venv/bin/python examples/rebbi/run.py --project ../rebbi --case all --out runs/rebbi .venv/bin/python examples/rebbi/run.py --verify examples/rebbi/evidence .venv/bin/python -m pytest -q tests/test_example_rebbi.py ``` `run.py` exits non-zero unless every case passed. To reproduce the failure, check out `3db016d` and run `--case lost-reply` and `--case duplicate`. The evidence verifies offline without Rebbi; with `REBBI_PROJECT=../rebbi` set, the test also runs all four cases live. ## Results and limitations | Bundle | Rebbi | Expected | Observed | | --- | --- | --- | --- | | `before-fix-lost-reply` | `3db016d` | one loan; the retry gets loan 1 back | **FAILED**: loans 1 and 2 for one request; loan 1 left active | | `before-fix-duplicate` | `3db016d` | one loan; the second copy gets loan 1 back | **FAILED**: loans 1 and 2; loan 2 left active | | `after-fix-lend` | `07da056` | one 18,000-token loan, job paid, 2,000 returned | **PASSED**, 9/9 | | `after-fix-lost-reply` | `07da056` | one loan; the retry gets loan 1 back | **PASSED**, 12/12 | | `after-fix-duplicate` | `07da056` | one loan; the second copy gets loan 1 back | **PASSED**, 11/11 | | `after-fix-no-room` | `07da056` | `CANNOT_MOVE` with reasons, nothing spent, client refunded | **PASSED**, 9/9 | Bundle fingerprints are …
Try it
Open PR on GitHubView diffCheckout locally
git fetch origin pull/360/head:pr-360
git checkout pr-360