TestForge Blog
← All Posts

RAG-Based AI Stock Investment Agent Part 3 — Agent Workflow, Tool Calling, and Analysis Chains

A practical design for the workflow of an AI stock investment Agent. Covers routing, query parsing, screening, retrieval analysis, quantitative analysis, risk evaluation, and final report composition.

TestForge Team ·

A Stock Agent Is an Analysis Pipeline, Not a Single Answer

Even simple user questions require multiple steps underneath.

Example:

Analyze whether Amazon is still attractive after the latest earnings release

That implies:

  • trend and volatility inspection
  • event lookup
  • news and filing retrieval
  • portfolio exposure check
  • risk rule validation
  • report generation

The Agent is best thought of as an orchestrator.

Router
 -> Query Parser
 -> Screener
 -> Retrieval Analyst
 -> Quant Analyzer
 -> Risk Evaluator
 -> Response Composer

Router

  • classifies the question
  • distinguishes stock analysis, screening, or portfolio review

Query Parser

  • extracts symbol, time window, constraints, and strategy intent

Screener

  • filters the universe
  • narrows candidate symbols

Retrieval Analyst

  • searches filings, news, and transcripts
  • summarizes event context

Quant Analyzer

  • computes returns, volatility, drawdown, factor-like signals, and indicators

Risk Evaluator

  • checks exposure, event risk, and policy limits

Response Composer

  • creates an evidence-backed report

Tool Calling Should Be Explicit

A practical initial tool set might be:

[
  {"name": "get_price_summary"},
  {"name": "screen_symbols"},
  {"name": "search_news_context"},
  {"name": "search_filing_context"},
  {"name": "get_financial_metrics"},
  {"name": "get_portfolio_exposure"},
  {"name": "evaluate_risk_rules"}
]

Avoid vague tools like:

  • analyze_stock
  • search_market

Prefer narrow and well-scoped interfaces.

Why Query Parsing Matters

Natural language investment questions are usually under-structured.

Example:

Find three large-cap semiconductor names that still look healthy two weeks after earnings

A structured form might be:

{
  "intent": "screening",
  "sector": "semiconductor",
  "market_cap": "large",
  "event": "earnings",
  "window_days": 14,
  "constraint": "not_overheated",
  "top_n": 3
}

That structure is what makes the rest of the workflow reliable.

Screening Should Mostly Be Deterministic

Screening is often better handled by rules and SQL than by an LLM.

Example:

select symbol
from symbol_snapshot
where market_cap_rank <= 500
  and avg_dollar_volume_20d >= 50000000
  and last_earnings_date >= current_date - interval '14 days';

Let the model interpret and explain results, not perform the primary filtering logic.

Retrieval Analyst Adds Narrative Context

Once screening produces candidates, the Retrieval Analyst adds context such as:

  • recent news direction
  • filing events
  • earnings-call statements
  • guidance changes
  • regulation or supply chain issues

The Quant Analyzer explains what the numbers say. The Retrieval Analyst explains why the market might care.

Quant Output Should Be Structured

A useful quant output record might look like:

{
  "symbol": "NVDA",
  "return_20d": 0.124,
  "volatility_20d": 0.31,
  "max_drawdown_60d": -0.08,
  "rsi_14": 67.2,
  "earnings_gap": 0.052,
  "trend_label": "strong_uptrend"
}

That gives the response layer concrete numbers to cite.

Risk Evaluation Must Be Separate

One of the biggest design mistakes is blending stock analysis with portfolio risk control.

A stock can look attractive while still being a poor portfolio decision.

Examples:

  • The sector is already too concentrated
  • Earnings are within 24 hours
  • The symbol would exceed single-name exposure limits

The final recommendation might be:

Keep on watchlist, but avoid adding new size right now

The Response Should Read Like an Evidence Report

A useful answer format:

  1. conclusion
  2. quantitative evidence
  3. qualitative evidence
  4. risk factors
  5. sources

That is usually more trustworthy than a bare “buy” or “avoid” answer.

Do You Need Multi-Agent Architecture Immediately?

Usually not.

For early versions, one orchestrated service with separated roles is often enough. True multi-Agent design becomes more useful when:

  • strategy research runs independently
  • portfolio optimization is long-running
  • different agents own clearly different workflows

Before that point, multi-Agent can add complexity without enough benefit.

Closing Thoughts

The strongest stock investment Agents do not rely on one clever prompt.

They combine:

  • deterministic screening
  • RAG-based context retrieval
  • structured quantitative outputs
  • independent risk checks
  • clear, report-like response generation

That workflow design is what makes the system credible.