
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


