# Add a pre-trade check to TradingAgents

## How do I add a pre-trade check to TradingAgents?

Call TradingAgentsGraph.propagate. It returns the Portfolio Manager rating. Before any broker call you add, run an order check on that decision, stop if a kill-switch file exists, and keep the default on a paper broker.

That return is final_state and the rating ([trading_graph.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/trading_graph.py#L404), [rating.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/agents/rating.py#L112)).

## What this repository is

The README title is TradingAgents: Multi-Agents LLM Financial Trading Framework ([README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L30)). That README says the framework is designed for research purposes, and that it is not intended as financial, investment, or trading advice ([README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L77)). The license file is the Apache License, Version 2.0 ([LICENSE](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/LICENSE#L1), [LICENSE](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/LICENSE#L2)).

The README has an analyst team ([README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L81)), a researcher team ([README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L93)), a trader agent ([README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L100)), and a risk management team providing assessment reports to the Portfolio Manager for final decision ([README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L108)).

## Where the final decision is written

The Trader node writes trader_investment_plan ([trader.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/agents/trader/trader.py#L95)). The graph edge from Trader goes to Aggressive Analyst ([setup.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/setup.py#L176)). should_continue_risk_analysis returns Portfolio Manager when risk_debate_state count is at least three times max_risk_discuss_rounds ([conditional_logic.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/conditional_logic.py#L26), [conditional_logic.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/conditional_logic.py#L28)).

The Portfolio Manager prompt says to deliver the final trading decision ([portfolio_manager.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/agents/managers/portfolio_manager.py#L42)). The node returns final_trade_decision and final_rating ([portfolio_manager.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/agents/managers/portfolio_manager.py#L100)). TradingAgentsGraph.propagate returns that state and the rating ([trading_graph.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/trading_graph.py#L177), [trading_graph.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/trading_graph.py#L404)). The rating comes from run_rating, which reads final_rating or the decision text ([rating.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/agents/rating.py#L112)). The Portfolio Manager edge goes to END ([setup.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/setup.py#L185)).

The README says an approved proposal is sent to a simulated exchange ([README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L109)). propagate returns the state and the rating. A broker call belongs in your code, after the check below.

## Where to put the check

The package section says propagate returns a decision ([README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L255)). The example assigns that return and prints it ([README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L264), [README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L265)). That value is a rating. It is not an order. Build the order you would send, then run the check on that order, before any broker call. The CLI reads one JSON order on stdin. Exit 0 is PASS, exit 1 is SEND-BACK, and exit 2 means the check did not run ([cli.ts](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/src/cli.ts#L14)). A non-zero exit stops the snippet. Run it from the [agent-order-check](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/README.md#L24) package, with your own limits file.

```python
import json
import subprocess

# After TradingAgentsGraph.propagate. The return is a rating, not an order.
# https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/trading_graph.py#L404
# Replace the sample fields with the order you would send. Not a trade.
state, decision = ta.propagate(ticker, trade_date)
order = {
    "symbol": "SPY",
    "asset_class": "equity",
    "side": "buy",
    "qty": 10,
    "type": "limit",
    "limit_price": 500,
    "time_in_force": "day",
    "account_type": "paper",
    "stop_loss": {"stop_price": 496},
    "take_profit": {"limit_price": 506},
}
proc = subprocess.run(
    ["bun", "src/cli.ts", "--limits", "limits.json", "--halt-file", "HALT"],
    input=json.dumps(order),
    text=True,
    capture_output=True,
)
if proc.returncode:
    raise SystemExit(proc.stdout.strip() or proc.stderr.strip() or "order check refused")
```

The public [Agent Order Check](/check) runs in the browser. This server does not accept the order. Paste the order you would send on that page, and run the local command in the snippet before a send.

## Kill switch and paper default

The snippet passes --halt-file HALT. The CLI blocks every order while that file exists ([cli.ts](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/src/cli.ts#L17), [cli.ts](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/src/cli.ts#L73)). TRADING_HALT=1 blocks every order too ([README](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/README.md#L97)). Keep the file where the sender can read it and do not give the agent a tool that deletes it. The pattern is the [kill switch guide](/guides/ai-trading-bot-kill-switch).

The sample order sets account_type to paper. The CLI refuses account_type live unless ALLOW_LIVE=1 or --allow-live is set ([cli.ts](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/src/cli.ts#L18), [README](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/README.md#L113)). The snippet does not pass that switch. The [paper trading guide](/guides/ai-agent-paper-trading) is the ladder before a live send.

Checked on 2026-10-20 against commit e8f5503e9b86d5c2710b0c76b1f686703968c9df.

## Questions people ask

### How do I add a pre-trade check to TradingAgents?

Call TradingAgentsGraph.propagate. It returns the Portfolio Manager rating. Before any broker call you add, run an order check on that decision, stop if a kill-switch file exists, and keep the default on a paper broker.

### Where does TradingAgents write the final decision?

The Trader node writes trader_investment_plan ([trader.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/agents/trader/trader.py#L95)). The Portfolio Manager returns final_trade_decision and final_rating ([portfolio_manager.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/agents/managers/portfolio_manager.py#L100)). propagate returns that state and the rating ([trading_graph.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/trading_graph.py#L404)).

### Does that return send an order to a broker?

The README says an approved proposal is sent to a simulated exchange ([README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L109)). propagate returns the state and the rating ([trading_graph.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/trading_graph.py#L177)). Put a broker call you write after the check, on a paper lane first.

### What stops the send?

The check CLI exits 0 on PASS and 1 on SEND-BACK ([cli.ts](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/src/cli.ts#L14)). A halt file passed with --halt-file blocks every order while it exists ([cli.ts](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/src/cli.ts#L17)). account_type live is refused unless ALLOW_LIVE=1 or --allow-live is set outside the agent ([cli.ts](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/src/cli.ts#L18)). The [kill switch guide](/guides/ai-trading-bot-kill-switch) and the [paper trading guide](/guides/ai-agent-paper-trading) are the two controls. Paste the order you would send into [Agent Order Check](/check).

## Sources

- [README](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L30)
- [README, research purposes](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L77)
- [README, analyst team](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L81)
- [README, risk management and Portfolio Manager](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L107)
- [README, simulated exchange](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L109)
- [README, propagate](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L255)
- [README, propagate example](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/README.md#L264)
- [LICENSE](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/LICENSE#L1)
- [trader.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/agents/trader/trader.py#L95)
- [setup.py, Trader edge](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/setup.py#L176)
- [setup.py, Portfolio Manager to END](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/setup.py#L185)
- [conditional_logic.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/conditional_logic.py#L28)
- [portfolio_manager.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/agents/managers/portfolio_manager.py#L42)
- [portfolio_manager.py, return](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/agents/managers/portfolio_manager.py#L100)
- [trading_graph.py, propagate](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/trading_graph.py#L177)
- [trading_graph.py, return](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/graph/trading_graph.py#L404)
- [rating.py](https://github.com/TauricResearch/TradingAgents/blob/e8f5503e9b86d5c2710b0c76b1f686703968c9df/tradingagents/agents/rating.py#L112)
- [agent-order-check CLI](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/src/cli.ts#L14)
- [agent-order-check halt file](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/src/cli.ts#L17)
- [agent-order-check paper default](https://github.com/thetahustler/agent-order-check/blob/626e89ee0893fe3a98a55f248dedcc54974660cd/src/cli.ts#L18)
- [Agent Order Check](/check)
- [Kill switch](/guides/ai-trading-bot-kill-switch)
- [Paper trading](/guides/ai-agent-paper-trading)

Not financial advice. Paper first.

Free check: https://theagentictrader.com/check?utm_source=md&utm_medium=agent&utm_campaign=guides-add-pre-trade-check-to-tradingagents
Weekly note on broker and agent changes: https://theagentictrader.com/subscribe?utm_source=md&utm_medium=agent&utm_campaign=guides-add-pre-trade-check-to-tradingagents
Desk Kit, $79 one-time. Full refund within 7 days: https://theagentictrader.com/desk-kit?utm_source=md&utm_medium=agent&utm_campaign=guides-add-pre-trade-check-to-tradingagents
