A safety layer for autonomous AI agents in finance, with tamper-evident audit, policy-as-code authorization, and herding detection.
Project description
corral
A safety layer for autonomous AI agents in finance. You corral a herd to keep it from stampeding, and that's the job here. Watch a fleet of black-box trading agents and keep it inside safe bounds.
Three pieces, and every one treats the agent as a black box. It reads what an agent did (orders, cancels, fills), never its weights or its prompts, because the action stream is the one thing that generalizes across architectures and the one thing a supervisor actually gets to see.
- Audit, an append-only, hash-chained record of every action with its decision context and the authorization behind it. Each entry binds the hash of the one before it, so editing history breaks every hash after it and the tampering shows. Any agent's behavior can be reconstructed and verified after the fact.
- Authorization, a deny-by-default gate that checks each order against declarative policy before it runs, against allowed instruments, order-size and notional limits, position caps, and restricted lists. Block on violation, or just log it and watch.
- Herding detection, a scikit-learn-style detector that scores how far a fleet is converging on the same move, measured against an explicit null so it reports real crowding and not noise, and flags it before it turns into a liquidity event.
Status
Early, 0.0.1. Real and tested today, the action contract, the hash-chained audit log with Merkle inclusion and consistency proofs, the deny-by-default policy gate and kill switch, two herding detectors (net-direction and RMT market-mode) and the budget-calibrated watchdog that combines them, the absorption-ratio early-warning signal, the synthetic cascade simulator, and the validation statistics. Stubbed and on the roadmap, RFC 3161 time-anchoring, OPA/Cedar policy adapters, the wider herding menu (CSAD, transfer entropy, Kuramoto, copula tail dependence, policy similarity), and the realistic order-book validation harness (ABIDES).
Install
pip install -e ".[dev]"
Python 3.9+. The core needs numpy and scipy; scikit-learn is optional and used when it's present.
A quick look
import numpy as np
from corral import AgentAction, ActionLog, TamperEvidentAuditLog, PreTradePolicyGate
from corral.action import ActionType
from corral.authz.policy import TradingPolicy
from corral.herding.detector import HerdingDetector
# the deny-by-default gate goes in front of every order
gate = PreTradePolicyGate(TradingPolicy(allowed_instruments=frozenset({"AAPL"}),
max_order_quantity=1000))
# the hash-chained log records what actually went through
audit = TamperEvidentAuditLog()
log = ActionLog()
rng = np.random.default_rng(0)
for t in range(40):
for i in range(15):
order = AgentAction(f"agent{i}", float(t), ActionType.ORDER, instrument="AAPL",
side="buy" if rng.random() < 0.5 else "sell",
quantity=float(rng.integers(1, 100)))
if gate.authorize(order).allowed:
audit.append(order)
log.append(order)
print("logged:", len(audit), "chain valid:", audit.verify())
# score the fleet against a chance baseline
X, agents, times = log.to_array(features=("signed_quantity",))
det = HerdingDetector(random_state=0).fit(X)
print("herding score:", round(float(det.decision_function(X)[0]), 2))
License
BSD-3-Clause. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file corral_fleet-0.1.0.tar.gz.
File metadata
- Download URL: corral_fleet-0.1.0.tar.gz
- Upload date:
- Size: 27.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f55e2f0b99a7c9293c001808d98e69b7f0383bf1429235e4a9ba8817213f23d
|
|
| MD5 |
200676d37ca2ceb08ffe472f30952bab
|
|
| BLAKE2b-256 |
2702e59dd5d48c68ef66cfc86de550cb1098e841e2a0af3313bbb69a1019302a
|
File details
Details for the file corral_fleet-0.1.0-py3-none-any.whl.
File metadata
- Download URL: corral_fleet-0.1.0-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e728dd28032d9c629d1a4a8497031c2f57b33ee19dbde4352aaed13a9e828f3
|
|
| MD5 |
addd224e45c59a9dfa8bae7c8122e398
|
|
| BLAKE2b-256 |
7b40d8bc11039267c8658aa2f0c5788415ae1375a6c89cc2c64c06570c88a5a8
|