Checked 2026-10-20.

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, rating.py).

What this repository is

The README title is TradingAgents: Multi-Agents LLM Financial Trading Framework (README). That README says the framework is designed for research purposes, and that it is not intended as financial, investment, or trading advice (README). The license file is the Apache License, Version 2.0 (LICENSE, LICENSE).

The README has an analyst team (README), a researcher team (README), a trader agent (README), and a risk management team providing assessment reports to the Portfolio Manager for final decision (README).

Where the final decision is written

The Trader node writes trader_investment_plan (trader.py). The graph edge from Trader goes to Aggressive Analyst (setup.py). should_continue_risk_analysis returns Portfolio Manager when risk_debate_state count is at least three times max_risk_discuss_rounds (conditional_logic.py, conditional_logic.py).

The Portfolio Manager prompt says to deliver the final trading decision (portfolio_manager.py). The node returns final_trade_decision and final_rating (portfolio_manager.py). TradingAgentsGraph.propagate returns that state and the rating (trading_graph.py, trading_graph.py). The rating comes from run_rating, which reads final_rating or the decision text (rating.py). The Portfolio Manager edge goes to END (setup.py).

The README says an approved proposal is sent to a simulated exchange (README). 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). The example assigns that return and prints it (README, README). 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). A non-zero exit stops the snippet. Run it from the agent-order-check package, with your own limits file.

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 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, cli.ts). TRADING_HALT=1 blocks every order too (README). 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.

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, README). The snippet does not pass that switch. The paper trading guide 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). The Portfolio Manager returns final_trade_decision and final_rating (portfolio_manager.py). propagate returns that state and the rating (trading_graph.py).

Does that return send an order to a broker?

The README says an approved proposal is sent to a simulated exchange (README). propagate returns the state and the rating (trading_graph.py). 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). A halt file passed with --halt-file blocks every order while it exists (cli.ts). account_type live is refused unless ALLOW_LIVE=1 or --allow-live is set outside the agent (cli.ts). The kill switch guide and the paper trading guide are the two controls. Paste the order you would send into Agent Order Check.

Sources

Not financial advice. Paper first.

All guides · Agent Order Check · Kill switch · Paper trading · This page as markdown

The paid set is the Grok Bot Desk Kit.

Not financial advice. Paper first.