Project · AI Automation
AI Stock Analyst: a multi-agent n8n workflow with a Telegram bot
A project built by Webziper. You message a Telegram bot, and an n8n workflow sends each stock through specialist AI agents for fundamentals, news and SEC filings, plus plain code for the technical numbers. A final decision agent applies hard rules with veto power and posts a BUY / WAIT / REJECT report back to Telegram.
- Stack
- n8n, Flowise LLM agents, Telegram Bot API, Finnhub, Yahoo Finance, SEC EDGAR
- Type
- Multi-agent workflow
- Interface
- Telegram
What does it do?
Most AI agent demos are one big prompt doing everything: reading the data, doing the math, making the call. When the answer is wrong, you can't tell which step failed. We built this project to test the opposite approach. Several narrow agents each look at one source, code handles anything calculable, and the final call sits under rules a human wrote.
Every ticker goes through six stages, one ticker at a time:
- Fundamentals agent. Reads financial metrics from Finnhub and returns ACCEPTED or REJECTED, with its reasoning.
- News sentiment agent. Reads recent news and rates the risk. It can issue a VETO.
- Technical layer. Weekly and daily RSI, calculated in code.
- Extra context. Earnings dates, insider trading, short interest, volume ratio and market cap. Also code.
- SEC agent. Reads the company's XBRL filings from SEC EDGAR and summarises balance-sheet and debt risk.
- CIO decision agent. Gets everything above and answers BUY, WAIT or REJECT in one sentence, under strict rules.
How does the Telegram bot work?
A Telegram bot is an account that hands every message it receives to your server. n8n's Telegram Trigger node receives those messages, so anything you send the bot starts the workflow. There's no dashboard to build or log into.
/startruns screener mode. n8n pulls tickers from Yahoo Finance screeners, including Undervalued Growth Stocks and Undervalued Large Caps, merges the lists and drops anything below a market-cap threshold. Only tickers the fundamentals agent ACCEPTS get the full analysis.- A single ticker like
AAPLruns single-ticker mode. That company goes through the whole pipeline whatever the fundamentals verdict is. If you asked about it, you get an answer.
A Switch node routes each message, both paths merge into the same pipeline, and a Split In Batches node feeds the tickers through one at a time. Each agent only ever sees one company, and every ticker gets its own report.
/start produces one report per accepted ticker; a single ticker always produces exactly one report.Each report starts with the ticker and market cap, the verdict and a one-line reason, then lists the evidence behind it:
📊 EXMP (fictional) · Market cap: $12.4B
Verdict: WAIT
Reasoning: Fundamentals pass and debt risk is moderate, but the weekly RSI is overbought. Wait for a pullback.
Evaluation details
RSI: weekly 72.4 · daily 64.1 (overbought, medium strength)
Fundamentals: ACCEPTED. Revenue growing, margins stable.
News: MEDIUM risk. Mixed coverage, no veto.
SEC: debt risk LOW. Leverage within a normal range.
Context: earnings in 23 days · insiders neutral · short interest 3.1% · volume 1.2× average
09:41How do the agents split the work?
The rule is simple: each agent gets one source and one question. Only the last agent sees everything.
- Fundamentals agent (a Flowise flow that n8n calls). Finnhub's metrics are numbers, but interpreting them isn't arithmetic: a ratio that's alarming for one company is normal for another. The agent answers one question: does this business pass a fundamentals check?
- News agent. Recent news is formatted into a compact digest and the agent rates the risk. If the news points to serious risk, it issues a VETO that the final decision has to respect.
- SEC agent. The workflow looks up the company's CIK (its SEC identifier), downloads the XBRL filings from EDGAR and parses them. The agent only answers how risky the balance sheet is, especially the debt.
- Technicals and context are code. RSI is calculated, not guessed, and a parser turns it into a signal and a strength. An LLM would add nothing here except the chance of getting the arithmetic wrong.
How is the final decision made?
Ask an LLM "should I buy this?" and you'll always get a confident answer. Without constraints, that answer is a guess in good grammar. So the CIO agent works under rules it can't argue its way around:
- News shows high risk, or the news agent issued a VETO → REJECT, even if RSI is oversold.
- The SEC report shows high debt risk → REJECT.
- RSI above 70 → WAIT (overbought).
- RSI below 35, fundamentals ACCEPTED, and news and SEC risk low or medium → BUY.
The first rule matters most. A stock whose price has collapsed often looks cheap on RSI, and sometimes it's cheap for a reason. A news veto closes off that value trap with one line of logic. When no hard rule applies, the CIO agent defaults to WAIT: a BUY only happens when every BUY condition is met.
Why LLMs + code + hard rules?
| Layer | What it does here | Good at | Weak at |
|---|---|---|---|
| LLM agent | Reads fundamentals, news and SEC filings | Unstructured text, judgment, explaining itself | Math, giving the same answer twice |
| Deterministic code | RSI, market-cap filter, earnings dates, volume ratio | Exact, repeatable, cheap | Anything that needs interpretation |
| Hard rule | Vetoes, RSI thresholds, the conditions for BUY | Predictable and auditable | Nuance and edge cases |
The payoff is auditability. Every REJECT traces back to a specific rule and a specific agent's finding, so you can check the reasoning instead of trusting it.
What we had to solve
One filter, two entry modes
"Pass only tickers the fundamentals agent ACCEPTED" is right for screener mode, but it breaks single-ticker mode: ask about a company with weak fundamentals and you get nothing back. The fix is one filter with OR logic. It passes the item if fundamentals are ACCEPTED, or if it came from a single-ticker message. That only works if each item still remembers where it came from after the two paths merge.
Tickers with no news
Some tickers have no recent news; Realty Income (O) is a good example. In n8n, a node that returns zero items stops that branch by default, so a ticker can quietly drop out of the batch. The right handling is to treat "no news" as data: the news step always outputs an item, and the agent reads it as not enough information (neutral, no veto) rather than "low risk".
Where does this pattern fit your business?
Take the stocks out and the architecture is general: specialist agents judge one source each, code handles the numbers, and a decision agent applies rules your team agreed on, with vetoes for what must never slip through.
| Use case | Agents read | Code checks | Hard rule / veto |
|---|---|---|---|
| Lead qualification | Inquiry text, company website, news | Company size, country, budget | No budget or outside your market → nurture, not sales |
| Vendor due diligence | News, reviews, financial filings | Registration status, payment history | Sanctions hit or insolvency → reject |
| Support ticket triage | Ticket text, customer history | SLA tier, account value | Legal threat or data breach → human now |
| Candidate screening | CV, portfolio, cover letter | Required certifications, location | AI never rejects alone → a human reviews every "no" |
| Document & invoice review | Invoice and contract terms | PO match, totals, VAT | Amount mismatch → block payment |
We build these for businesses as n8n automations and AI agents, with a human in the loop wherever a decision is sensitive. If your team makes the same kind of decision every day from several sources, tell us about it. We'll tell you honestly whether it needs agents, plain automation, or neither.
Frequently asked questions
Can n8n run multi-agent AI workflows?
Yes. n8n can call several LLM agents in one workflow, either through its built-in AI Agent nodes or through external agent tools such as Flowise, and pass each agent's output to the next step. A practical pattern is to give each agent one data source and one question, use regular nodes for calculations, and let a final agent bound by hard rules make the decision.
How do you connect an n8n workflow to a Telegram bot?
Create a bot with Telegram's BotFather to get a token, add it as a Telegram credential in n8n, and start the workflow with a Telegram Trigger node. Every message sent to the bot then starts the workflow, and a Telegram node at the end sends the results back to a chat or group. A Switch node can route different messages, such as /start or a single keyword, down different paths.
Why use hard rules on top of AI agents?
LLMs are good at reading unstructured information, but they always produce a confident answer, even when they shouldn't. Hard rules, such as vetoes for high-risk findings or fixed numeric thresholds, make the final decision predictable and auditable: every outcome can be traced to a specific rule and a specific agent's finding.
What business processes fit a multi-agent pattern?
Processes where one decision depends on several different sources and has to be explained afterwards. Good examples are lead qualification, vendor due diligence, support ticket triage, candidate screening and document or invoice review. Each source gets its own agent, calculations stay in code, and rules decide the outcome, with a human reviewing sensitive cases.