Free playbooks in your inbox

How to Get Your Next Winning Stock Trade From 5 AI Agents

Run a multi-agent trading system in Python where five AI agents research a stock, make the call, size it and hand you an order with a limit price. On the practice stock they return buy 1 DEMO at 70.96, with every line of the call pointing back to a fact you can check.

From the youcanbuildthings catalog ▸ Build-tested

Hello builders,

This weekend you can have five AI agents working one stock idea together and handing you a trade with a size and a limit price already on it. A trader I quote in the book asked one chatbot for swing trades on QQQ and posted the result: “So far it’s 0-3.” What we build here is a multi agent trading system in Python with five seats, research, thesis, challenge, risk and execution, and it runs on your laptop in about a minute.

A reader under a Reddit post about agent trading asked the question everybody asks first: “How do you have agents for Different models speaking to each other?” There’s no group chat. Each seat writes one small structured answer and hands it to the next seat as its input, so research can run on one company’s model and challenge on another and neither one ever knows.

Five seats, one trade call

Here is the first trade call our desk ever made, from the book’s scripted stand-in replies, with each line traced back to the seat that wrote it.

Multi agent trading system trade call: decision D-f01824fc DEMO, thesis buy at 70.96 on breakout-v1, challenge PASS 2 objections, risk REDUCE $80, order buy 1 DEMO limit 70.96 day, status RISK_APPROVED, with research, thesis, challenge, risk and execution cards showing which seat wrote each line

Read it top to bottom and you can watch the whole desk work. Research looked at the facts for a practice stock called DEMO and wrote “Closed above the 20-day high,” citing facts F1, F2 and S1. Thesis committed to “Breakout fired on the close,” a buy at 70.96 on the strategy called breakout-v1. Challenge has one job, which is to assume thesis is wrong, and it passed the idea with two objections on file, the first being “The supplier delay is not answered,” citing headline N3. Risk read that open objection and came in at $80 where the cap allows $100, because there was “One open objection, so under the full limit.”

Execution is plain code with no model in the chair, and it divides $80 by 70.96, gets one share and writes the order exactly as approved, which is how I want the seat nearest my money to behave.

Run it in a minute

You need Python 3.12 or newer. We use no keys and no account here, because DEMO is a made-up stock whose prices come from a formula, which is also why your screen will match mine digit for digit.

git clone https://github.com/regardo911/alpha-swarm.git
cd alpha-swarm
python3 -m venv .venv
source .venv/bin/activate
python make_fixture.py
python packet.py DEMO --fixture
python swarm.py packets/P-0390dac823.json

The packet step gathers 11 facts from two price sources and three headlines. On this first run each model chair holds a scripted stand-in reply read from a file; add a model key, name your models in swarm.json, and the same command seats real models. The last command walks the packet past all five seats and prints this:

decision D-f01824fc  DEMO
  thesis     buy at 70.96 on breakout-v1
  challenge  PASS, 2 objection(s)
  risk       REDUCE $80
  order      buy 1 DEMO limit 70.96 day
  status     RISK_APPROVED
saved runs/D-f01824fc.json

Run it again and you get the same decision number, because the number is a fingerprint of the packet. Open runs/D-f01824fc.json and every answer from every seat is in there with the fact numbers it pointed at, so when a trade goes wrong you can see which seat said what.

Now make a seat lie

Here’s the test I’d run before trusting any agent team with a dollar. In fixtures/seats/broken/thesis.json the thesis seat claims “Earnings beat by a mile last night” and cites headline N9. The packet holds three headlines, so N9 doesn’t exist. Change "scene": "first" to "scene": "broken" in swarm.json and we run the same command again.

AI trading agent refuses an invented headline: the first run ends RISK_APPROVED with buy 1 DEMO limit 70.96, the broken scene ends status NO_ORDER with error thesis: unsupported claim, cites N9

One invented headline and the desk stopped with NO_ORDER before challenge or risk were even asked. Every claim has to cite a fact that exists in today’s packet, and a seat that breaks its card means no trade. Set the scene back to first when you’re done.

Real models make this matter more. When I gave the same DEMO packet to real models, the thesis seat quoted the two upbeat headlines and skipped N3, the supplier warning, which is what I suspect any optimist with a job to do will tend to do. On that run the challenge seat sent the thesis back, and the second draft had the supplier warning in it. The research seat also wrote five observations when its card says up to four, and nothing objected, because no line of code counts them. My working rule since then: if a rule matters to us, we put it in code and let the card carry the rest.

Plenty of AI trading projects stop at an opinion, and the ai-hedge-fund project on GitHub says so in its own README:

This project is for educational purposes only and is not intended for real trading or investment.

Note: the system does not actually make any trades.

(virattt/ai-hedge-fund)

Our desk ends at an order line with a symbol, a size and a limit, ready for a broker’s practice account, and the next chapter of the book sends it there.

When you seat real models, put a different one in the challenge chair. My view is that a second opinion is worth more when it comes from a different head, and that is the one mix we bother with on day one. Then put your Alpaca and market-data keys in keys.env and run python packet.py scan on your own watchlist. Which of your stocks fired a setup today, and what will five seats say about it? Send that packet through the same command and read what your challenge seat wrote back.

Now go build something this weekend!

John Cook

Why trust this? Every youcanbuildthings guide is pulled from a build-tested book: code that ran in production before it was written down.