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
← All projects
Technical demonstration, not investment advice. This page is about workflow architecture. We make no claims about how the signals perform.

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:

  1. Fundamentals agent. Reads financial metrics from Finnhub and returns ACCEPTED or REJECTED, with its reasoning.
  2. News sentiment agent. Reads recent news and rates the risk. It can issue a VETO.
  3. Technical layer. Weekly and daily RSI, calculated in code.
  4. Extra context. Earnings dates, insider trading, short interest, volume ratio and market cap. Also code.
  5. SEC agent. Reads the company's XBRL filings from SEC EDGAR and summarises balance-sheet and debt risk.
  6. CIO decision agent. Gets everything above and answers BUY, WAIT or REJECT in one sentence, under strict rules.
A Telegram message triggers n8n. A router sends /start to screener mode and a single ticker to single-ticker mode. Both paths merge into a per-ticker loop: fundamentals agent, an OR filter, news agent, RSI technicals, extra context, SEC agent and a final CIO decision agent, which sends one Telegram report per ticker.Telegram/start or a tickern8n TriggerTelegram Trigger nodeRouterSwitch node/start → screener modeYahoo screeners → tickers → cap filterAAPL → single-ticker modeboth paths mergePer-ticker loop · Split In Batches · one ticker at a time1 · FundamentalsFinnhub metrics → LLMACCEPTED / REJECTED+ reasoningFilter (OR)ACCEPTED, orsingle-tickerrequest2 · News agentrecent news → LLMrisk ratingcan issue a VETO3 · Technicalsweekly + daily RSIsignal + strengthno LLMREJECTED in screener mode → skip ticker4 · Extra contextearnings date · insidersshort interest · volumemarket cap5 · SEC agentCIK → EDGAR XBRL filingsparsed → LLMdebt-risk summary6 · CIO decision agentall findings above + hard rules→ BUY / WAIT / REJECT+ one-sentence reasonTelegram reportone message per ticker → your group↺ next ticker, until the list is doneLLM agentDeterministic codeRules & decisionTelegram
Figure 1. The whole workflow. Violet boxes are LLM agents, cyan boxes are deterministic code, gold is the rules-based decision, blue is Telegram.

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.

  • /start runs 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 AAPL runs 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.

Left: you send /start, the bot triggers n8n, n8n pulls tickers from screeners, sends them one by one to the AI agents and posts one report per accepted ticker to the Telegram group. Right: you send AAPL, n8n runs the full pipeline for that ticker and posts a single report./startscreener modeYouTelegram botn8nAI agentsTelegram group/starttrigger firesscreeners → tickersticker 1…N, one by oneverdict + reasonsreport #1report #2… report #NOne report per ACCEPTED tickerAAPLsingle-ticker modeYouTelegram botn8nAI agentsTelegram groupAAPLtrigger firesrouter: one tickerAAPL, full pipelineverdict + reasons1 reportAlways analysed, whatever the fundamentals say
Figure 2. The same bot, two conversations. /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:

Figure 3. One report, with a fictional ticker and illustrative values. The bot reports in Romanian; shown translated.

How 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.
Vetoes are checked first: high-risk news or a news VETO means REJECT even if RSI is oversold; high SEC debt risk means REJECT. RSI above 70 means WAIT. RSI below 35 with fundamentals ACCEPTED and low or medium news and SEC risk means BUY. If no rule fires, the verdict defaults to WAIT.All findings for one tickerNews: high risk or VETO?yesREJECTeven if RSI is oversold:avoids value trapsnoSEC: high debt risk?yesREJECTbalance sheet too riskynoRSI above 70?yesWAIToverboughtnoRSI below 35 andfundamentals ACCEPTED?yesBUYnews & SEC risk are low ormedium by this pointnoNo hard rule fires → WAITa BUY only happens when every BUY condition is met
Figure 4. The CIO agent's rules. Vetoes are checked first, so a cheap-looking stock with bad news or a weak balance sheet never gets through.

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?

Key insight: LLMs judge, code calculates, rules decide. Give the model only the work a model is needed for, which is reading messy information. Keep the math in code and the final call under rules a human wrote.
LayerWhat it does hereGood atWeak at
LLM agentReads fundamentals, news and SEC filingsUnstructured text, judgment, explaining itselfMath, giving the same answer twice
Deterministic codeRSI, market-cap filter, earnings dates, volume ratioExact, repeatable, cheapAnything that needs interpretation
Hard ruleVetoes, RSI thresholds, the conditions for BUYPredictable and auditableNuance 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 caseAgents readCode checksHard rule / veto
Lead qualificationInquiry text, company website, newsCompany size, country, budgetNo budget or outside your market → nurture, not sales
Vendor due diligenceNews, reviews, financial filingsRegistration status, payment historySanctions hit or insolvency → reject
Support ticket triageTicket text, customer historySLA tier, account valueLegal threat or data breach → human now
Candidate screeningCV, portfolio, cover letterRequired certifications, locationAI never rejects alone → a human reviews every "no"
Document & invoice reviewInvoice and contract termsPO match, totals, VATAmount 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.

Have a decision your team makes every day?

We build this kind of multi-agent automation for businesses: agents do the reading, rules make the call.

Book a Free Call →