IRL Gateway

io.github.norve-labsv0.3.0更新於 Oct 7, 2026

An AI agent's trading mandate it can't break: checked before every order, reasoning sealed in IRL.

已驗證STDIO僅桌面Security & MonitoringFinance

概覽

AI 產生的概覽

讓 AI 代理透過受政策檢查的閘道下現貨市價單,並把每筆交易的理由封存成防竄改紀錄。

功能
IRL Gateway 位於 AI 代理與交易所帳戶之間,在訂單送到交易所之前,先依代理已註冊的授權(啟用狀態、名目金額上限、允許的資產與交易場所)進行檢查。主要工具 execute_trade 依序執行授權、下單與綁定,並回傳 filled、denied、blocked 或 failed 以及 trace id。其他工具可讀取授權與本機終止開關狀態、報價、餘額、某筆交易的封存紀錄,以及本機近期交易日誌。交易理由經雜湊後封存進 IRL 紀錄,明文只留在本機日誌中。
適用情境
當助手被允許交易,但需要受預先註冊的授權約束,並留下可驗證的紀錄——證明它被允許做什麼、聲稱在做什麼、實際成交了什麼——時適用。模擬盤模式不需要交易所金鑰,適合低風險試用。
執行需求
以 stdio 方式在本機執行,從 PyPI 安裝並用 uvx 啟動。需要 IRL_BASE_URL、IRL_AGENT_ID、IRL_MODEL_HASH 以及密鑰 IRL_API_TOKEN,並能連線到 IRL 伺服器。GATEWAY_BROKER 選擇 paper(預設)或 exchange;exchange 模式還需要 EXCHANGE_API_KEY 與 EXCHANGE_API_SECRET。僅支援桌面端。
安裝前請注意
execute_trade 是唯一會動用資金的工具,在 exchange 模式下可在真實帳戶下單。它需要密鑰 IRL_API_TOKEN,實盤交易還需要交易所 API 金鑰與密鑰。理由明文留在本機,但交易內容的雜湊會傳送到 IRL 伺服器並在外部錨定。終止開關是本機檔案;專案處於早期(0.1),僅支援現貨市價單。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 IRL Gateway,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

IRL Gateway

Give your AI agent a trading account it can't misuse, and a record of every decision it can't rewrite.

IRL Gateway is an MCP server that sits between an AI agent (Claude, ChatGPT, or your own) and an exchange account. Every order the agent places goes through the IRL Engine:

  1. Policy before execution. IRL checks the order against the agent's mandate (active status, notional cap, allowed assets and venues) before anything reaches the exchange. Out of mandate means no order.
  2. The rationale is sealed. The agent must say why it is trading. The gateway hashes that rationale together with the trade inputs and seals the hash into IRL's tamper-evident trace, anchored daily to Bitcoin. The plaintext stays in your local journal.
  3. Intent is reconciled with the fill. After the exchange fills the order, IRL compares what was authorized with what executed and records MATCHED or DIVERGENT.

When something goes wrong, you can prove what the agent was allowed to do, what it said it was doing, and what actually happened.

AI agent ── MCP ──> irl-gateway ──> IRL: authorize (policy + sealed rationale)                         │                         ├──────> exchange: market order (client id = sealed intent)                         │                         └──────> IRL: bind fill -> MATCHED / DIVERGENT

Tools

ToolWhat it does
execute_trade(symbol, side, rationale, quantity | notional)The only tool that moves money. Spot market order through authorize → place → bind. Returns filled, denied, blocked or failed, with the IRL trace_id and verdict.
get_policy()The agent's mandate as IRL enforces it, plus the local kill-switch state.
get_quote(symbol)Last price on the gateway's venue.
get_balances()Free balances (paper or exchange).
get_trace(trace_id)IRL's sealed record of one trade.
list_recent_trades(limit)Local journal: rationale, context hash, trace id and outcome per trade.

Behaviour the agent can rely on:

  • Fail closed. If IRL is unreachable or denies the intent, no order is sent.
  • Kill switch. Create the file ~/.irl-gateway/KILL and every trade is refused before IRL is even called. Delete it to resume.
  • No silent fills. If the exchange fills but the IRL bind fails, the result still reports the fill and flags it for reconciliation.
  • Sealed = sent. Order sizes are rounded to the venue's step and checked against its minimums before IRL seals them, so the sealed quantity is exactly what reaches the exchange. An order the venue would reject is blocked with a plain reason instead.

Quick start (paper trading, about a minute)

bash
uvx irl-gateway init

That one command gets a free paper-tier token from norve.dev, registers your agent with a starter mandate (BTC/USDT and ETH/USDT, at most 1,000 USDT per order, on paper-binance), saves the credentials to ~/.irl-gateway/agent.json, and prints:

  • a claude mcp add irl-gateway ... line for Claude Code, and
  • an mcpServers block for Claude Desktop, Cursor or any MCP client.

Paste one of them, then ask the agent to call get_policy and make its first paper trade. Paper fills are simulated at live public Binance prices with Binance's real order-size rules, so no exchange keys are needed.

Options: --name, --assets BTC/USDT,SOL/USDT, --max-notional 250, --contact [email protected] (so we can reach you), --server (your own IRL engine).

Free tier limits: paper venues only, up to 3 agents and 500 authorizations a day per token. Want to trade live, or run without limits? Self-host the engine or ask for a full token.

Doing it by hand instead
bash
curl -X POST https://norve.dev/irl/signup -H "Content-Type: application/json" -d '{"client_name": "my-claude-trader"}'# -> {"token": "...", "tier": "paper", ...}  (shown once)
curl -X POST https://norve.dev/irl/agents -H "Authorization: Bearer $IRL_API_TOKEN"   -H "Content-Type: application/json" -d '{    "name": "my-claude-trader",    "model_hash_hex": "<sha256 of your agent config>",    "max_notional": 100,    "allowed_assets": ["BTC/USDT", "ETH/USDT"],    "allowed_venues": ["paper-binance"]  }'

Then add the gateway to your MCP client:

json
{  "mcpServers": {    "irl-gateway": {      "command": "uvx",      "args": ["irl-gateway"],      "env": {        "IRL_BASE_URL": "https://norve.dev",        "IRL_API_TOKEN": "…",        "IRL_AGENT_ID": "<agent_id from registration>",        "IRL_MODEL_HASH": "<the same model_hash_hex>",        "AGENT_MODEL_ID": "claude-opus-5-5",        "PAPER_BALANCES": "USDT=1000"      }    }  }}

Configuration

VariableDefaultMeaning
IRL_BASE_URL, IRL_API_TOKENrequiredIRL server and bearer token
IRL_AGENT_ID, IRL_MODEL_HASHrequiredThe registered agent and its model hash
AGENT_MODEL_IDunspecified-modelModel name sealed into each trace (the agent can override it per trade)
AGENT_CONFIG_CHECKSUMnoneOptional checksum of the agent's configuration, sealed into each trace
IRL_L2_MODEoffregime if your IRL server requires Layer 2 regime binding
GATEWAY_BROKERpaperpaper or exchange
EXCHANGE_IDbinanceAny ccxt exchange id; also the price source for paper trading
EXCHANGE_API_KEY, EXCHANGE_API_SECRETRequired for exchange
EXCHANGE_TESTNETtrueUse the exchange's testnet
PAPER_BALANCESUSDT=1000Starting paper balances (used only until paper_state.json exists; the paper account then persists across restarts)
IRL_GATEWAY_HOME~/.irl-gatewayJournal (journal.jsonl), kill switch (KILL) and paper account (paper_state.json) location

The venue IRL sees is the exchange id (binance), or paper-<exchange> for paper trading, so a mandate can allow paper trading while denying the real account.

How the rationale is sealed

For each trade the gateway builds a context of the rationale, symbol, side, quantity, reference price, venue, model id and client order id. It hashes that context as canonical JSON (sorted keys, no whitespace) with SHA-256 and sends the hash to IRL as prompt_version = "ctx-sha256:<hex>", which IRL seals into the trace's reasoning_hash.

The journal stores the full context next to its hash, so anyone holding a journal line can recompute the hash and match it to the sealed trace. IRL itself never sees the rationale's text.

Development

bash
python -m venv .venv && .venv/bin/pip install -e ".[dev]"pytest --cov=irl_gatewayruff check src tests && black --check src tests && isort --check-only src tests && mypy src

Status

Early (0.1). Spot market orders only. Paper trading and ccxt exchanges are supported; Alpaca is next. Not investment advice, and no strategy is included: the gateway controls and records what your agent does, it does not decide.

MIT licensed.

來源:README.md,提交 2e6fd99

工具

0
工具後設資料尚未被收錄。

版本歷史

1
  1. v0.3.0最新Oct 7, 2026