How to build risk controls for an AI trading agent from scratch
Start with a hard budget cap, enforce a drawdown limit, and require owner approval for every live key. These three controls prevent most catastrophic losses before they happen.
- 01Risk management starts with infrastructure-enforced limits, not with prompts or strategy logic.
- 02A hard budget cap, a drawdown limit, and a non-custodial wallet are the three essential controls for every new trading agent.
- 03Paper trading must include deliberate attempts to breach limits so the owner can verify the API rejects them.
- 04Prompt-based instructions are not enforceable; only API-level permissions and wallet controls can bound agent behavior.
- 05Trading can lose money, including the full allocated budget, but non-custodial design and scoped keys ensure the loss cannot exceed the owner-defined limit.
Risk management for an AI trading agent begins with infrastructure-enforced limits, not with complex strategy logic. The agent should receive a bounded budget it cannot exceed, a drawdown threshold that halts trading automatically, and a non-custodial wallet structure that prevents it from ever moving funds to an unauthorized address. These controls are set before the agent places its first order, and they remain in place regardless of how the underlying strategy evolves. Once this foundation exists, the owner can add position sizing rules, per-market limits, and a kill switch without redesigning the system.
What should a new trading agent control first?
The first layer of defense is capital containment. Before the agent selects assets or entry signals, it needs a hard ceiling on how much capital it can deploy. This is not a suggestion in a prompt; it is a protocol-level limit enforced by the API and the wallet permissions. A new agent should start with a small dollar cap, a single market type, and a narrow scope key that only permits trading, not withdrawals or key management. The owner should choose a budget that is small enough to lose without distress, because the initial goal is to validate the control layer, not to generate returns. Strategy optimization is secondary at this stage. The agent may have a sophisticated model for entry and exit, but if the control layer is missing, the model is unbounded.
Alongside the capital cap, the agent needs a drawdown limit. This is the percentage or dollar decline from the starting equity that triggers an automatic halt. Suppose the agent starts with one thousand dollars and the drawdown limit is set to ten percent. Trading stops if equity falls to nine hundred dollars. The limit should be conservative for a first deployment. A tight threshold preserves capital while the owner observes how the agent behaves under real market conditions, including how it handles rejected orders and slippage. Some owners prefer a fixed-dollar drawdown to a percentage, which can be easier to reason about when the budget is small. Either approach works if it is enforced by the infrastructure and not by the agent.
- ·A hard budget cap in plain US dollars, enforced by the API.
- ·A drawdown limit that flattens positions and revokes trading authority.
- ·A non-custodial wallet where withdrawals are owner-approved only.
- ·A scoped key that restricts the agent to trading on specific markets.
How do spend caps and drawdown limits work?
Spend caps and drawdown limits serve different purposes, but they work together. The spend cap controls gross exposure over a time window, such as a day or a week. It answers the question of how much new capital the agent can put at risk during that period. The drawdown limit controls net loss from the starting point. It answers the question of how much the agent is allowed to lose before it must stop. How to set spend caps and drawdown limits for an MCP trading agent
When both limits are active, the agent faces two constraints. It cannot open new positions that would push its total deployed capital above the spend cap, and it cannot continue trading if account equity drops below the drawdown threshold. This creates a bounded environment where the maximum loss is predictable. The owner knows in advance that the worst case is capped at the lower of the two limits, or a combination of both, depending on how the controls are configured. For example, a daily spend cap of two hundred dollars and a ten percent drawdown limit on a one thousand dollar budget means the agent can lose at most one hundred dollars from the drawdown rule, even if the spend cap would theoretically allow more. The interaction matters because a high spend cap with a tight drawdown limit produces a different risk profile than a low spend cap with a loose drawdown limit. The owner should think through these scenarios before authorizing the live key.
A hard budget is even simpler. It is a global ceiling on the agent's entire lifetime allocation. How an AI agent trades within a hard budget it cannot exceed Even if the spend cap resets daily and the drawdown limit is never hit, the agent can never deploy more than the hard budget in total. This is useful for agents that run across multiple markets or strategies, because it prevents any single logic error from silently consuming more than its share of the total capital. The hard budget acts as the ultimate backstop.
Why is non-custodial design part of risk management?
Non-custodial architecture removes the possibility of fund theft by the agent or by anyone who compromises the agent's key. The owner retains control of the wallet, and the API key only permits trading within pre-approved limits. The agent can place orders, but it cannot withdraw funds, change withdrawal addresses, or modify its own permissions. This means that a bug in the agent's logic, a compromised API key, or a malicious prompt injection can only lose money through bad trades, not through theft. A practical checklist for non-custodial AI trading
This design choice changes the risk profile fundamentally. In a custodial model, the owner must trust the operator of the trading infrastructure with the full balance. In a non-custodial model, the risk is limited to trading losses within the scoped budget. The owner can revoke the key at any time, and the remaining funds stay in the wallet. The kill switch, which flattens all positions and revokes the key immediately, is the final layer of this custody model. It is not an afterthought; it is a core part of the safety architecture. When the owner activates the panic switch, the agent loses all access, and no further orders can be placed.
What are the most common mistakes when setting limits?
Beginners often set limits in the agent's prompt or in the strategy code instead of in the infrastructure. A prompt instruction like 'do not risk more than five percent' is not enforceable. The LLM may misinterpret it, ignore it, or be tricked by a jailbreak. The only safe limits are those enforced by the API and the wallet permissions. What beginners get wrong when taking an AI trading agent live
Another common error is making the initial budget too large. The purpose of the first live deployment is to validate the control layer, not to generate returns. A small budget exposes the agent to real slippage and execution variance while keeping the potential loss insignificant. Owners who skip paper trading or who move to live capital too quickly often discover that their limits are misconfigured only after a loss occurs. They may also set drawdown limits too wide because they fear premature halts, which defeats the purpose of having a safety net.
- ·Relying on prompt instructions instead of API-enforced caps.
- ·Allocating too much capital to an untested agent.
- ·Skipping paper trading or ignoring the panic switch test.
- ·Setting drawdown limits too wide because they fear premature halts.
- ·Forgetting to scope the key so it cannot withdraw or alter permissions.
How do you test controls before going live?
Every control should be exercised in paper trading before real capital is deployed. Paper trading on Felix simulates the full order lifecycle, including size normalization, limit checks, and behavior specific to each market type. The owner should deliberately trigger each limit to confirm the response. Attempt to exceed the spend cap and verify that the API rejects the order. Simulate a drawdown breach and confirm that the agent halts and notifies the owner. Test the panic switch to ensure it revokes the key and flattens positions as expected.
{
"budget_usd": 500,
"max_drawdown_percent": 5,
"markets": ["stocks", "crypto"],
"allow_withdrawal": false,
"panic_switch": true
}This is illustrative. The actual fields and endpoint paths are documented at /docs. The point is that the controls are explicit, numeric, and declared before the agent starts. After paper testing, the owner authorizes a live key with the same parameters. The authorization step is manual and deliberate. It ensures that the owner has reviewed the limits and understands that trading can lose money, including the entire budget. Never authorize a live key until every limit has been tested and the kill switch response has been observed.
When should you add more advanced controls?
Once the basic spend cap, drawdown limit, and kill switch are proven, the owner can introduce position-level rules. These include per-trade size limits, concentration limits for single assets, and allowed directional exposure, such as long-only or delta-neutral. These rules refine how the agent behaves within its budget, but they do not replace the budget itself. A per-trade limit of fifty dollars, for example, prevents the agent from opening a single oversized position even if the total daily budget is two hundred dollars.
Exit plans are another advanced layer. An exit plan is a pre-scheduled flattening rule, such as closing all positions before a major event or at the end of a trading window. This prevents the agent from holding risk through periods of high variance that the owner does not want to monitor. The exit plan is enforced by the infrastructure, not by the agent's reasoning. Even if the agent believes a position will recover, the exit plan closes it at the appointed time.
Advanced controls should be added one at a time. Each new rule is tested in paper mode, then deployed live with a small budget, and only then scaled up. The goal is to build a layered defense where no single failure can cause catastrophic loss. Trading can lose money, including the full allocated budget, but the non-custodial design and scoped keys ensure the loss cannot exceed the amount the owner explicitly chose to risk. Scaling up means increasing the budget only after the agent has demonstrated stable behavior within the existing controls for a meaningful period. Patience in this phase protects capital better than any single algorithmic tweak.
Frequently asked questions
No. Prompt instructions are not enforceable. The only reliable limits are those enforced by the API, the wallet permissions, and the non-custodial architecture. A prompt may be misinterpreted or bypassed, so the budget and drawdown controls must be set at the infrastructure level.
It should be an amount you are fully prepared to lose. Many owners start with a few hundred dollars. The purpose of the first live deployment is to test execution behavior and control enforcement, not to generate returns.
The system halts trading, flattens open positions if configured to do so, and revokes the agent's ability to place new orders. The owner receives a notification and must review the situation before reactivating the agent.
Paper trading confirms that the API rejects out-of-bounds orders and that the kill switch responds correctly. It does not guarantee that live slippage or market conditions will be identical. It is a necessary step, but it is not a guarantee of future performance.
Some limits can be adjusted, but decreases in budget or drawdown thresholds may require a key refresh or owner re-authorization. This prevents a compromised agent from raising its own limits. Check the docs for the specific policy on your setup.
Correct. The agent can only place trades within its scoped limits. It cannot withdraw funds, change addresses, or transfer assets. The worst case is losing the budgeted trading capital through bad positions, not theft of the wallet balance.
Give your agent a key.
One key to trade stocks, crypto, perps, options, and prediction markets. Live after owner authorization.
Newcomers often treat scoped API keys like strong passwords. In practice, they are programmable contracts that limit what an agent can do, regardless of whether the agent is buggy, compromised, or hallucinating.
Running a trading agent from Claude means connecting an LLM to real markets through MCP tools and scoped API keys. This guide walks through the architecture, safety setup, and first steps without assuming prior automation experience.