Skip to main content
AIDevOps
  • Learn
  • Learning Paths
  • Practice
  • Open Source
  • Books
  • Engineering

    AI DevOpsThe full map of building and operating AI servicesLLMOpsLLM deployment · evaluation · observabilityHands-on ProjectsBuild AI Agent projects

    Knowledge

    DocsTechnical documentationBlogEngineering articlesPloggerDevelopment log feed

    Validate

    Certification3-level skills certification · coming soon
AI Models
LlamaTutorial|MistralTutorial|GemmaTutorial|DeepSeekTutorial|QwenTutorial
🧠 AI Agent Development
Finance AI AgentLLM API ServerStock Investing AgentAIOps AI AgentEducation AI AgentCoding AI Agent
🤖 AI Applied Development
Applied AI Intro & RoadmapHugging FaceLangChainLlamaIndexLLMOps|LangGraphMCPMulti-AgentAgent Evaluation
🧠 AI Core
AI Intro & RoadmapML FundamentalsLLM Fundamentals|Python AIC++|PyTorchTensorFlowJAX
🌱 Spring Cloud
Spring Intro & RoadmapSpring Cloud GatewaySpring BootJava|Spring AISpring SecuritySpring BatchSpring JPA
🐳 DevOps
DevOps Intro & RoadmapLinuxDockerCI/CD|Kubernetes BasicsK8s AdvancedPrometheusGrafana
🧱 Infrastructure
Infrastructure Intro & RoadmapNginxRedis
☁️ Cloud
Cloud Intro & RoadmapAWSGCPAzureNCPCloudflare
🎨 Frontend
Frontend Intro & RoadmapJavaScriptTypeScript|ReactNext.js|VueNuxt|Electron
📱 Mobile
Mobile Intro & RoadmapKotlinAndroidFlutter
⚙️ Backend
Backend Intro & RoadmapPython BasicsFastAPIDjangoFlask|CGoGinNode.js
💾 Database
DB Intro & RoadmapCore SQLOracleMySQLPostgreSQL|MongoDBVector DB
🧪 Testing
k6JMeternGrinder
AIDevOps

Engineering AI. From Code to Production.
An engineering learning platform for building and operating AI and AI Agents

Learn

  • All Guides
  • Learning Paths
  • AI Tutorial
  • Practice
  • Books

Resources

  • AI DevOps
  • LLMOps
  • Hands-on Projects
  • Docs
  • Blog
  • Plogger
  • Open Source
  • Certification (coming soon)

Start Here

  • AI Core Roadmap
  • AI Applied Development Roadmap
  • Spring Cloud Roadmap
  • DevOps Roadmap
  • Infrastructure Roadmap

 

  • Cloud Roadmap
  • Frontend Roadmap
  • Mobile Roadmap
  • Backend Roadmap
  • Database Roadmap
© 2026 AIDevOps. All rights reserved.
Terms of ServicePrivacy PolicySitemaptestforge.kr
Finance AI Agent

FIN AutoTrading AI Investment Agent AI Agent Project

Visitors

A hands-on stock investing AI agent that combines a local SQLite screener DB with pgvector RAG. Reads the quantitative scores (SQLite) of the existing AutoTrading system, synthesizes stock reports with the Qwen 2.5 3B model, generates 768-dimension embeddings with nomic-embed-text, and loads them into pgvector (PostgreSQL). A LangChain ReAct agent then combines real-time Yahoo Finance tool calls with semantic RAG search to deliver detailed investment analysis.

← Back to projects
FIN

Contents

0 / 15
  1. Technical guide
  2. Development environment
  3. AI model selection
  4. Model install and run
  5. Training and tuning
  6. Vector DB setup
  7. RAG development
  8. System integration
  9. Validation and operations
  10. Model selection by domain
  11. Overall architecture
  12. Project ABC
  13. Data and tools
  14. Milestones/deliverables
  15. Tech stack
Contents 15 sections
  1. Technical guide
  2. Development environment
  3. AI model selection
  4. Model install and run
  5. Training and tuning
  6. Vector DB setup
  7. RAG development
  8. System integration
  9. Validation and operations
  10. Model selection by domain
  11. Overall architecture
  12. Project ABC
  13. Data and tools
  14. Milestones/deliverables
  15. Tech stack

Technical Blueprint

Hands-on AI Agent Development Checklist

Executable development documents come before explanations of the idea. An AI Agent only moves from demo to real service once local execution, the API contract, RAG data, tool calls, the validation routine, and the operational fallback are fixed first.

1. Development environment and run baseline

  • Put `npm install`, `docker compose up`, `npm run build`, and the health check command in order at the top of the README.
  • Fix the default development environment: Node.js 22 LTS, Python 3.11 or later, Git, Docker Desktop, and VS Code or Cursor.
  • Start with Next.js for the frontend, FastAPI or a Cloudflare Worker for the Agent API, and either Chroma or pgvector for the Vector DB.
  • In `.env.example`, keep the model name, API key, DB URL, vector collection, timeout, and observability endpoint under their real variable names.
  • From the first commit, treat the build, API unit tests, representative curl calls, and a k6 smoke test as the pass criteria.

2. Model and cost criteria

  • First classify the task as one of: conversation, document Q&A, code generation, data analysis, or tool calling.
  • Compare candidate production models not on quality alone but also on monthly cost, p95 latency, JSON schema compliance rate, and how well they can fall back on failure.
  • For local-first projects, write down the actual model names to install and their expected sizes, such as `llama3.1:8b`, `llama3.2:3b`, `gemma2:9b`, and `nomic-embed-text`.
  • When also using API models, add a provider adapter so you can switch through `MODEL_PROVIDER`, `MODEL_NAME`, and `MODEL_TIMEOUT_SECONDS`.
  • Evaluate models against a golden set of 30-50 representative questions and tabulate accuracy, groundedness, hallucination rate, latency, and failure types.

3. API contract and local execution

  • Four endpoints are enough to fix at first: `/health`, `/v1/chat`, `/v1/rag/query`, and `/v1/agent/run`.
  • Every response returns `answer`, `citations`, `model`, `latency_ms`, `trace_id`, and `warnings` in the same shape.
  • Design it so the browser never calls the model provider or the laptop API directly, only the server-side API facade.
  • Run local models with Ollama or Docker Compose, and include the model list call and a first chat completion curl in the docs.
  • Do not hard-code timeout, retry, max tokens, temperature, or streaming; move them into environment variables.

4. Prompts and response policy

  • Keep the system prompt short and fixed: the role, forbidden behavior, how to answer when evidence is thin, and the conditions for using tools.
  • Early on, improve the prompt template, RAG document quality, tool schema, and JSON response format before reaching for fine-tuning.
  • Include examples of forbidden answers, insufficient-evidence answers, and answers that need user confirmation in the golden set.
  • Manage per-task output not as free text but as a schema such as `summary`, `evidence`, `next_actions`, `confidence`, and `needs_review`.
  • When a prompt changes, compare the golden set pass rate and failure types against the previous version.

5. Building the RAG data

  • Store the source documents, chunks, embeddings, metadata, and ingestion version separately, and put the re-index command in the README.
  • Start with 10 documents and inspect the chunk size, overlap, metadata, and search results by eye.
  • The search API takes explicit `query`, `top_k`, `filters`, and `min_score` and returns the source id, title, page, score, and chunk text.
  • Make citations mandatory in RAG answers, and fall back to an “insufficient evidence” response when there is no citation.
  • Decide in advance how to detect document changes, index incrementally, tombstone deleted documents, and re-index when the embedding version changes.

6. Implementing the Agent workflow

  • Split the workflow into intent classification, deciding whether retrieval is needed, tool calls, answer generation, verification, and fallback, in that order.
  • If you use LangGraph, document the input/output schema of each node and the next node on failure.
  • Start the tools the Agent can call as read-only, and put write actions behind a human approval step.
  • Attach a timeout, retry, rate limit, audit log, and user permission check to every tool call by default.
  • Return the final answer with evidence, next actions, and whether review is needed as separate fields so the UI can render it as-is.

7. System integration and security

  • The Agent does not query the DB directly; it calls only restricted tool APIs such as `stock_search`, `portfolio_summary`, `log_search`, and `policy_check`.
  • Give external APIs and internal DB adapters permissions, rate limits, timeouts, retries, and audit logs by default.
  • Clearly divide where the API key, JWT, session id, user id, and request id are handled between the cloud and the local API.
  • Do not leave sensitive data as-is in prompts and logs; mask it or move it to a separate secure store.
  • Link the user request, tool calls, model response, and final answer by trace id and use it for incident analysis and quality improvement.

8. Validation and moving to production

  • Measure correctness, groundedness, policy violations, and output format compliance with the golden set, and compare results before and after each change.
  • The minimum bar before production is the health check, smoke test, k6 p95 latency, API error rate, RAG hit rate, and fallback rate.
  • In high-risk areas such as finance, education, and operations automation, always separate LLM judgment from deterministic rule checks.
  • Observe latency, token usage, tool failures, and retrieval hit rate with OpenTelemetry, Prometheus, Grafana, or at least structured logs.
  • Start the first release as a read-only Agent with a human-approval workflow, and widen the scope of automatic execution after enough validation.
Live working demo

AI Screen Ranking & Antigravity integration dashboard

A web demo that simulates the local SQLite data sync and pgvector semantic search described in the blueprint. See the top-ranked stocks in real time and watch the multi-agent reasoning process of the Antigravity AI Agent right away.

Launch the working demo →

Model Selection

AI model selection and install/usage by domain

So that you can start a POC right away on a Finance project, this section lays out the recommended API models, local models, embedding models, and install/usage guidelines.

Recommended API models

Local CPU on-device baseline: no paid external APIs (zero cost)

Local/on-premises alternatives

qwen2.5:3b (strong multilingual instruction-following) or gemma2:2b (very fast inference)

Embedding models

nomic-embed-text (768-dimension high-performance text embeddings)

Chosen models and Docker install baseline

Adopts qwen2.5:3b as the default so that CPU inference runs smoothly without running out of memory (OOM) on an ordinary 16GB RAM laptop/PC. For speed-first and very low-memory environments, gemma2:2b is downloaded as well so the two can be swapped at any time.

All services are managed under Docker Compose. The aia_postgres container uses PostgreSQL 16 with pgvector, aia_ollama serves as the local LLM inference engine, and aia_backend runs as the FastAPI web application.

Recommended server spec

  • Minimum: 16GB RAM, 20GB or more of free SSD, a CPU with 4 or more cores (works with Intel Arc GPU and WSL2 CPU acceleration)
  • Recommended: 32GB RAM or more (more stable CPU inference speed under concurrent requests)
  • Caution: on 16GB of RAM, the WSL2 virtual machine needs at least 8GB-12GB of memory allocated, and unused host browser windows should be closed to avoid a physical OOM.

Capacity and storage

  • Ollama core runtime: about 1.5 GB
  • qwen2.5:3b model file: about 1.9 GB
  • gemma2:2b model file: about 1.6 GB
  • nomic-embed-text embedding model: about 274 MB
  • PostgreSQL pgvector and SQLite data volumes: under about 5GB

Docker install commands

  • Write docker-compose.yml in the project root to define the postgres, ollama, and backend services.
  • The Postgres external port is forwarded to 5435 (internal 5432) to make local client access easier, and the backend binds port 8000.
  • Start the containers: build and run the whole stack at once with `docker-compose up -d --build`.
  • Pull the Ollama models: run `docker exec -it aia_ollama ollama pull qwen2.5:3b` and `docker exec -it aia_ollama ollama pull nomic-embed-text`.

Post-install verification

  • Verify the Ollama model list: run `docker exec aia_ollama ollama list` to confirm the models loaded correctly.
  • Verify the container processes: check with `docker ps` that all three containers are running (Up).
  • Verify the integration in the virtual environment: activate the local virtual environment (.venv), run `$env:PYTHONIOENCODING="utf-8"; python -m backend.test_integration`, and confirm the report is summarized and embedded correctly.

Why these were chosen

  • Combining the quantitative score data of the existing AutoTrading system with yfinance price indicators into qualitative investment points (reports) requires a natural-language summarization and embedding pipeline.
  • To run on a single local CPU machine, a large model such as llama-70B was replaced with the small, light qwen2.5:3b, which has strong multilingual performance, cutting latency dramatically.
  • With the PostgreSQL pgvector extension, text fragments of stock reports can be vectorized and stored, and the data most relevant to a user question can be retrieved (RAG) in milliseconds, which makes it a good way to give the agent its knowledge.
  • Attaching the yfinance API as an explicit Tool of the Agent provides a safeguard: the LLM refers to real data instead of making up recent price levels or financial statements.

Install and configuration

  • 1. Create a .env file in the project root and set DATABASE_URL (postgres:5435), OLLAMA_BASE_URL (http://localhost:11434), LLM_MODEL_NAME (qwen2.5:3b), and EMBEDDING_MODEL_NAME (nomic-embed-text).
  • 2. Write docker-compose.yml to connect the pgvector postgres container (port 5435), the ollama container (port 11434), and the FastAPI backend container (port 8000).
  • 3. Map SQLAlchemy and the pgvector DDL (the ScreenerReport model) in backend/db.py, and implement the SQLite connection utility in backend/autotrading_connector.py.
  • 4. Write the qwen2.5:3b report summary function and the nomic-embed-text embedding utility in backend/agent/screener_synthesizer.py.
  • 5. In backend/agent/tools.py, bind the yfinance financial API and the pgvector semantic search function with the LangChain @tool decorator.

How to use them

  • 1. Call the data sync API (SQLite ➡️ AI summary ➡️ pgvector load):
  • `Invoke-RestMethod -Uri "http://localhost:8000/api/autotrading/sync?limit=3" -Method Post`
  • 2. Call the natural-language semantic vector search API:
  • `$body = @{ query = "Recommend stocks with strong buying flows that are in an uptrend"; limit = 2 } | ConvertTo-Json`
  • `Invoke-RestMethod -Uri "http://localhost:8000/api/autotrading/search" -Method Post -ContentType "application/json" -Body $body`
  • 3. Call the AI investing agent chat API (yfinance / RAG Tool mapped automatically):
  • `$body = @{ prompt = "Use the screener report search tool to tell me the investment points for Hanwha Aerospace" } | ConvertTo-Json`
  • `Invoke-RestMethod -Uri "http://localhost:8000/api/chat" -Method Post -ContentType "application/json" -Body $body`

Cautions

  • Because it runs on a local CPU, syncing a lot of data at once (/api/autotrading/sync) causes response delays. Use the limit query parameter to run it in small sequential batches.
  • Korean stock tickers must be converted exactly to the Yahoo Finance format (e.g. Samsung Electronics -> 005930.KS) before being passed to the tool, so the agent prompt template needs explicit Ticker rules.
  • For communication between Docker containers, use the container network hostname (e.g. `http://ollama:11434`) instead of `localhost` to avoid host-container port mapping problems.

Reference Architecture

Overall architecture design

An AI Agent is easier to change and validate when the UI, orchestration, tool integration, data retrieval, and evaluation/operations layers are separated.

Presentation Layer

  • Next.js UI
  • Agent run status
  • Evidence/source display
  • User feedback collection

Agent Orchestration

  • Prompt policy
  • Tool routing
  • Memory/session
  • Structured output

Tool & Integration

  • Business API adapter
  • DB query tool
  • Document search tool
  • Policy check tool

Data & Retrieval

  • PostgreSQL
  • pgvector
  • Document chunking
  • embedding/reranking

Evaluation & Ops

  • Golden set
  • Playwright
  • k6
  • OpenTelemetry/Prometheus

Project ABC

The ABCs of running the project for real

A is architecture design, B is the AI Agent implementation, and C is the validation criteria. Following this order makes it easy to grow from a demo into an Agent you can operate.

A. Architecture

  • SQLite DB connector layer: a module that quickly extracts the AutoTrading screener ranking and detailed scores (out of 145 points).
  • AI Synthesizer layer: runs the quantitative figures through a Qwen 2.5 3B prompt template to synthesize professional investment analysis reports.
  • RAG & Vector DB layer: extracts report embedding vectors with nomic-embed-text, loads them into the Docker pgvector DB, and implements cosine similarity search.
  • LangChain ReAct Agent layer: combines the yfinance API tool with the pgvector search tool and controls question classification and the find-tool, run, answer loop.

B. Build

  • Implement the FastAPI main.py server with initialization of the pgvector database and table schema in the Startup event handler.
  • Initialize the AI agent with create_react_agent and AgentExecutor from langchain_classic, avoiding import errors between Classic versions.
  • Bring up the PostgreSQL, Ollama, and FastAPI server infrastructure on the local container network with docker-compose up -d --build.

C. Check

  • Run the test_integration.py script in PowerShell with the UTF-8 encoding environment variable and verify that the report is generated correctly.
  • Trigger the `/api/autotrading/sync` API and check that the top-3 stocks are loaded into pgvector with nothing missing.
  • Final check: when "Hanwha Aerospace investment points" is sent to the `/api/chat` API, the agent correctly goes through the `search_screener_reports` tool and arrives at the right answer.

Project Spec

Data and Agent tools

Data

  • AutoTrading SQLite screener results (autotrading.db)
  • AI-synthesized stock summary reports
  • 768-dimension embedding vectors
  • yfinance real-time price/financial data

Agent Tools

  • get_stock_financials
  • get_stock_price_history
  • search_screener_reports
  • get_latest_top_screener_stocks
  • analyze_user_portfolio

AI Agent scope

  • Build the SQLite screener DB connector
  • Build the local Ollama summary and embedding pipeline
  • Implement FastAPI data sync (/api/autotrading/sync)
  • Implement pgvector natural-language search (/api/autotrading/search)
  • Integrate the LangChain ReAct investing AI agent and Chat API (/api/chat)

Validation criteria

  • SQLite data is extracted correctly
  • Qwen 2.5 3B summarization and nomic-embed-text vectorization succeed
  • pgvector similarity search (Cosine Distance) accuracy
  • The agent picks the right Tool for each situation and the final answer quality is good

Execution

Milestones and deliverables

Milestones

  • Implement the SQLite screener DB connector
  • Set up and start the Docker Compose local infrastructure (pgvector/Ollama)
  • Pull the Qwen 2.5 3B and nomic-embed-text models
  • Design the FastAPI sync and natural-language search APIs
  • Integrate the LangChain-based yfinance / pgvector RAG agent
  • Validate that the local integration script works
  • Finish curl tests of the FastAPI endpoints

Deliverables

  • docker-compose.yml and Dockerfile configuration
  • FastAPI main.py and db.py scripts
  • agent/tools.py and agent/investment_agent.py agent code
  • test_integration.py integration test code
  • SQLite autotrading.db data file
  • AI Agent hands-on run guide (AIAgentRun.md)

Stack

Tech stack

FastAPIOllamaqwen2.5:3bnomic-embed-textPostgreSQLpgvectorSQLiteLangChain-ClassicyfinanceDocker Compose