
IRL Gateway
io.github.macropulse-labv0.2.0更新於 Oct 6, 2026
An AI agent's trading mandate it can't break: checked before every order, reasoning sealed in IRL.
概覽
讓 AI 代理透過受政策檢查的閘道下現貨市價單,並封存每筆交易的理由、核對成交結果。
- 功能
- IRL Gateway 位於 AI 代理與交易所帳戶之間。其 execute_trade 工具依授權、下單、綁定三步執行訂單:訂單在送達交易場所前先依代理的授權範圍(是否有效、名目金額上限、允許的資產與場所)檢查;代理必須說明交易理由,該理由會被雜湊並封存進防竄改的存證;之後再把授權意圖與實際成交比對,記錄為 MATCHED 或 DIVERGENT。其他工具可查詢授權範圍與本機終止開關狀態、最新價格、可用餘額、依編號查詢封存存證,以及本機近期交易日誌。IRL 無法連線或拒絕時會失敗關閉,本機終止開關檔案存在時一律拒絕交易。
- 適用情境
- 當允許助理進行交易,且你希望在訂單送出前強制執行硬性限額,並保留可驗證的授權、理由與成交紀錄時使用。預設是模擬盤,因此也適合在沒有交易所金鑰的情況下測試代理的交易行為。
- 執行需求
- 以 stdio 方式在本機執行,可從 PyPI 安裝 irl-gateway 或以 uvx 直接執行。需要一個 IRL 伺服器及在其上註冊的代理,透過 IRL_BASE_URL、IRL_API_TOKEN、IRL_AGENT_ID 與 IRL_MODEL_HASH 提供。GATEWAY_BROKER 選擇 paper(預設)或 exchange;exchange 模式還需要 EXCHANGE_API_KEY 與 EXCHANGE_API_SECRET。需要連線至 IRL 伺服器與交易場所的網路。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 IRL Gateway,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
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:
- 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.
- 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.
- Intent is reconciled with the fill. After the exchange fills the order, IRL compares what was authorized with what executed and records
MATCHEDorDIVERGENT.
When something goes wrong, you can prove what the agent was allowed to do, what it said it was doing, and what actually happened.
Tools
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/KILLand 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.
Quick start (paper trading)
You need an IRL server and an agent registered on it. Paper trading is the default: fills are simulated at live public Binance prices, and no exchange keys are needed.
Register the agent once, with its mandate:
Then add the gateway to your MCP client, for example Claude Code or Claude Desktop:
Ask the agent to check get_policy, then trade.
Configuration
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
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,提交 2cd9e0d
工具
0版本歷史
1- v0.2.0最新Oct 6, 2026


