Building an Open-Source AI Agent Workflow Platform: A Stock Research Use Case

    This article explains how to build a self-hosted AI agent workflow platform using open-source tools and apply it to stock research. It compares three deployment options (cloud-managed, local, and private server), outlines a five-stage workflow design for traceable research, and details verifiability controls, knowledge base retrieval strategies, cost and operations practices, and a phased rollout roadmap. The goal is reproducible, auditable research automation rather than automated decision-making.

    1. Why Go Open-Source and Self-Hosted: Cost, Control, and Compliance

    When building AI agent applications, teams usually face three practical constraints: unpredictable inference costs, business data that should not leave the organization, and workflows that require frequent iteration. A self-hosted, open-source workflow platform addresses all three.

    • Predictable cost structure: In a self-hosted setup, the main expenses are compute and storage. You can choose different model sizes on demand, avoiding budget overruns from per-call billing.
    • Clear data boundaries: Market data, position information, and research notes can all stay within your own environment and be accessed over an internal network, reducing the risk of sensitive data leaving your perimeter.
    • Versionable workflows: Workflow definitions are essentially configuration and code, so they can be placed under version control, making research logic reproducible.

    Self-hosting is not free of trade-offs, however. You take on operations, backups, upgrades, and security hardening. If a team lacks operational capacity, a managed cloud service is often more economical.

    2. Choosing Among Three Deployment Options

    1. Cloud-Managed

    Register and start immediately, with no operations overhead. This suits prototyping and individual research. Typical limitations include caps on the number of applications, missing team collaboration features, and quotas on requests and knowledge base capacity. Team collaboration, tiered permissions, and audit logs generally require a higher-tier plan.

    2. Local Deployment

    Run the full stack on a personal computer through a container runtime. This fits data-sensitive scenarios and offline debugging. The advantages are zero additional hardware cost and fast debugging feedback; the drawback is that availability depends on the local machine, making long-running tasks and scheduled jobs unreliable.

    3. Private Server Deployment

    Run the stack on a cloud host using container orchestration, balancing availability and control. Recommended practices:

    • Use containerized deployment, with services communicating over an internal network and only necessary entry ports exposed;
    • Put a reverse proxy in front and enable HTTPS to avoid transmitting credentials in plaintext;
    • Configure separate database and object storage volumes, with daily snapshots and off-site backups;
    • Enable access logs and operation auditing so you can trace which run produced which conclusion.

    The three options are highly consistent in configuration parameters and interaction patterns. This yields an important engineering benefit: a workflow that works locally can migrate smoothly to a server environment without a rewrite.

    3. Designing an Agent Workflow for Stock Research

    The core challenge in stock research is not “making the model talk” but “making conclusions traceable.” A five-stage structure is recommended:

    1. Data acquisition layer: Wrap market data, financial reports, announcements, and news interfaces in a unified way, outputting standardized fields (timestamp, symbol, frequency, adjustment method).
    2. Cleaning and alignment layer: Handle trading halts, missing values, adjustment differences, and timezone and trading-calendar alignment, then persist an immutable dataset.
    3. Feature and indicator layer: Compute momentum, volatility, turnover, relative industry strength, and more, with explicit window parameters written into metadata.
    4. Reasoning and generation layer: The agent calls tools to retrieve, calculate, and attribute, producing structured conclusions with evidence citations.
    5. Validation and presentation layer: Rule checks (value ranges, units, date validity) plus report generation and archiving.

    An illustrative workflow node configuration (pseudocode, structure only):

    1. workflow:
    2. - id: fetch
    3. tool: market_data
    4. params: { symbols: "${input.symbols}", freq: "1d", adjust: "qfq" }
    5. - id: align
    6. tool: calendar_align
    7. params: { tz: "Asia/Shanghai", fill: "ffill" }
    8. - id: features
    9. tool: indicator_calc
    10. params: { windows: [5, 20, 60] }
    11. - id: reason
    12. agent:
    13. tools: [vector_search, calculator, report_writer]
    14. constraints: { require_citation: true, max_steps: 8 }
    15. - id: validate
    16. tool: rule_check
    17. params: { forbid: ["future_data_leak", "unit_mismatch"] }

    4. Keeping Hallucinations in Check: Verifiability by Design

    The most common failure of research agents is fabricating data and citations. Four engineering gates can control this:

    • Tools first: All numbers must come from calculation tools. The model only organizes language and explains results; it is not allowed to “estimate” on its own.
    • Mandatory citations: Every key number in a conclusion carries a source identifier and timestamp. Output missing citations is deemed non-compliant.
    • Time isolation: Construct samples strictly by the point in time when data became available, preventing future functions from inflating backtest results.
    • Dual-channel review: A rule engine and the model produce conclusions in parallel. When they conflict, the rule result prevails and the case is flagged for manual review.

    5. Knowledge Base and Retrieval Strategy

    Split research reports, announcements, and internal notes into chunks with metadata (symbol, industry, date, document type). Use hybrid retrieval combining vector search and keyword search, then rerank and take the top few chunks into the context. Key practices:

    • Apply metadata filtering before similarity ranking to avoid retrieving outdated documents;
    • Route numeric question answering through a “query the database” path rather than semantic retrieval;
    • Rebuild indexes periodically and record the index version to keep experiments reproducible.

    6. Cost, Performance, and Operations

    • Model tiering: Use small models for simple tasks like extraction and classification, and large models for attribution and writing, significantly reducing cost.
    • Caching and batching: Serve repeated queries from cache; schedule batch jobs after market close to avoid peak hours.
    • Observability: Connect logging and monitoring with alerting, setting thresholds for task failure rate, latency, and token consumption.
    • Security baseline: Least-privilege accounts, centralized secret management with regular rotation, entry-point rate limiting, and pinned dependency image versions.

    7. Rollout Roadmap and Scope Statement

    A four-phase approach is recommended: Phase one completes the private environment and data pipelines; Phase two automates a single-symbol daily report; Phase three extends to industry and portfolio views, introducing backtesting and attribution; Phase four establishes a review mechanism, positioning the agent as a “research assistant” rather than a decision-maker.

    Note that the above covers technical implementation and research process automation only. No output constitutes investment advice; model conclusions are uncertain and must be reviewed by qualified personnel before use. To reduce the operational burden of self-hosting, you can also evaluate general capabilities from cloud providers such as Baidu AI Cloud, including container platforms, object storage, logging, and monitoring with alerting, to host similar workflows in a managed manner.