AI-Powered Finance Agent on Ghostfolio
Built for Gauntlet Week 2 · Forked from Ghostfolio
AgentForge is a production-ready AI finance agent layered on top of Ghostfolio. It adds a conversational AI assistant (powered by LangChain + Claude/GPT-4o) that can answer questions about your portfolio, surface insights, flag risks, and execute read operations — all from a floating chat widget embedded in the Ghostfolio UI.
| Layer | Tech | Port |
|---|---|---|
| Frontend | Angular (Ghostfolio client) | 4200 |
| Agent API | NestJS + LangChain.js | 8000 |
| Backend API | NestJS (Ghostfolio API) | 3333 |
| Database | PostgreSQL + Redis | 5432 / 6379 |
- Floating chat widget on every page — no separate route
POST /api/v1/chat— conversational interface to your portfolioGET /api/v1/tools— lists available agent toolsGET /api/v1/insights— proactive portfolio insightsPOST /api/v1/evals/run— LangSmith eval runner- LLM routing: GPT-4o-mini (simple) · Claude Sonnet (complex)
- Conversation state via Redis · Insights persisted in SQLite
The entire stack runs in Docker. Requires Docker and Node.js 22+.
git clone https://github.com/jsquire4/gf-AgentForge.git && cd gf-AgentForge
npm install
npm run setupnpm run setup walks you through everything interactively: creates .env with generated secrets, prompts for your OpenAI API key (and optional LangSmith key), starts Docker (Postgres, Redis, Ghostfolio), waits for health checks, runs database migrations and seeding, creates an eval user with a demo portfolio (AAPL, GOOGL, MSFT, AMZN, VTI, BND, VXUS), and builds the agent.
After setup completes, start the agent:
npm run start:agent# 1. Clone and install
git clone https://github.com/jsquire4/gf-AgentForge.git && cd gf-AgentForge
npm install
cp .env.example .envEdit .env and fill in the required values:
| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY |
Yes | OpenAI API key for agent LLM calls |
POSTGRES_PASSWORD |
Yes | Any strong password |
REDIS_PASSWORD |
Yes | Any strong password |
ACCESS_TOKEN_SALT |
Yes | Random string (openssl rand -base64 32) |
JWT_SECRET_KEY |
Yes | Random string (openssl rand -base64 32) |
LANGSMITH_API_KEY |
No | Enables LangSmith trace observability |
Important: The default DATABASE_URL in .env.example uses @postgres:5432 (the Docker service hostname). This works for containers but not for host commands like npm run database:setup. Update it to @localhost:5432 for running setup commands from your machine:
DATABASE_URL=postgresql://user:YOUR_PASSWORD@localhost:5432/ghostfolio-db?connect_timeout=300&sslmode=prefer
# 2. Start infrastructure (Postgres, Redis, Ghostfolio)
docker compose -f docker/docker-compose.yml up -d
# 3. Wait for Ghostfolio to be healthy (~30s)
until curl -sf http://localhost:3333/api/v1/health > /dev/null; do sleep 5; done
# 4. Seed the database and create an eval user with demo portfolio
npm run database:setup
npm run eval:seed # creates eval user, writes GHOSTFOLIO_API_TOKEN to .env
# 5. Build and start the agent
npm run build:agent
npm run start:agentOnce both Ghostfolio and the agent are running:
| Service | URL | Description |
|---|---|---|
| Ghostfolio UI | http://localhost:3333 | Portfolio management frontend |
| Agent API | http://localhost:8000 | AI agent endpoints |
| Agent Health | http://localhost:8000/api/v1/health | Health check |
# Verify the agent is up and tools are registered
curl http://localhost:8000/api/v1/health
curl http://localhost:8000/api/v1/tools
# Chat with the agent
curl -X POST http://localhost:8000/api/v1/chat \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-jwt>" \
-d '{"message": "How is my portfolio doing?"}'
# Validate setup (checks all services, env vars, build artifacts)
npm run eval:setup
# Run golden evals to validate the full pipeline
npm run eval:goldenThe agent ships with 6 tools that cover portfolio analysis, market data, compliance, and regulatory guidance:
| Tool | Category | Description |
|---|---|---|
portfolio_summary |
read | Pre-formatted portfolio overview from Ghostfolio |
market_data |
read | Current prices and historical performance for any ticker |
get_holdings |
read | Detailed breakdown of portfolio positions with allocation |
get_dividends |
read | Dividend payment history with date, amount, and totals |
check_wash_sale |
analysis | Detects IRS wash sale rule violations in transaction history |
lookup_regulation |
read | IRS/SEC/FINRA regulation lookup with citations and references |
Tools are registered via a single barrel export (tools/tools.exports.ts) and auto-discovered by the system prompt builder at runtime.
# Build agent
npm run build:agent
# Test agent
npm run test:agent
# Smoke-test chat round-trip
./scripts/test-chat.sh "What is my portfolio performance?"Every agent request is traced end-to-end via LangSmith. Traces include the full reasoning chain (input, tool calls, LLM reasoning, output) plus structured metadata for filtering.
Setup: Provide your LangSmith API key during npm run setup, or set these in .env manually:
LANGSMITH_API_KEY=lsv2_pt_...
LANGSMITH_PROJECT=ghostfolio-agent
LANGCHAIN_TRACING_V2=true
LANGCHAIN_CALLBACKS_BACKGROUND=trueWhat's traced:
| Field | Example | Description |
|---|---|---|
runName |
chat:a1b2c3d4 |
Identifies request type + conversation |
tags |
agent, slack, eval |
Filter by channel, eval vs production |
metadata.userId |
user-abc |
Links trace to Ghostfolio user |
metadata.conversationId |
conv-xyz |
Groups multi-turn conversations |
metadata.evalCaseId |
golden-01 |
Present only during eval runs |
Eval runs automatically tag traces with eval + the case ID, so you can filter eval traces from production in the LangSmith dashboard. Each request's langsmithRunId is also stored in the local metrics SQLite database for cross-referencing.
Two-tier eval system for validating agent behavior. Both tiers send prompts through the full agent loop (LLM + real Ghostfolio API). See evals/dataset/ for all eval cases.
| Tier | What it tests | When to run |
|---|---|---|
| Golden | Known-answer prompts — correct tool called, tool succeeds, natural language response | Every commit |
| Labeled | Routing under ambiguity, edge cases (prompt injection, off-topic), response quality | Branch merge |
Both eval tiers require the full stack running (Ghostfolio + Agent) and a seeded user with portfolio data:
# 1. Copy environment and add your keys
cp .env.example .env
# Edit .env → set OPENAI_API_KEY (required) + LANGSMITH_API_KEY (optional, for traces)
# 2. Start infrastructure
docker compose -f docker/docker-compose.yml up -d
npm run database:setup # creates tables + system tags
# 3. Seed eval user + demo portfolio (auto-writes GHOSTFOLIO_API_TOKEN to .env)
npm run eval:seed
# 4. Start the agent
npm run start:agent
# 5. Run evals
npm run eval:goldennpm run eval:seed creates a Ghostfolio user, imports demo holdings (AAPL, GOOGL, MSFT, AMZN, VTI), and writes the GHOSTFOLIO_API_TOKEN to .env automatically. The eval runner exchanges this token for a real JWT at runtime so tool calls authenticate as a real user. If the token is already valid, the seed is skipped.
# Run golden evals (known-answer, deterministic assertions)
npm run eval:golden
# Run labeled evals (routing + quality)
npm run eval:labeled
# Filter labeled evals by difficulty
npm run eval:labeled -- --difficulty straightforward
npm run eval:labeled -- --difficulty edge
# Run all evals
npm run eval
# Check every tool has eval coverage
npm run eval:coverage
# Validate setup before running evals
npm run eval:setupRegular users don't need any .env configuration. The Angular client handles authentication automatically — when you log into Ghostfolio, your JWT is stored in the browser and the AuthInterceptor attaches it to all requests, including those to the agent. The agent forwards the JWT to Ghostfolio's API for tool calls. No manual token management needed.
Eval dataset format: Each tool gets two JSON files — one in evals/dataset/golden/ (known-answer tool tests) and one in evals/dataset/labeled/ (routing tests with straightforward/ambiguous/edge cases). See evals/types.ts for the full schema.
Adding evals for a new tool: Drop two files (<tool-name>.eval.json) into golden/ and labeled/ — both runners auto-discover via glob.
Ghostfolio is an open source wealth management software built with web technology. The application empowers busy people to keep track of stocks, ETFs or cryptocurrencies and make solid, data-driven investment decisions. The software is designed for personal use in continuous operation.
Our official Ghostfolio Premium cloud offering is the easiest way to get started. Due to the time it saves, this will be the best option for most people. Revenue is used to cover operational costs for the hosting infrastructure and professional data providers, and to fund ongoing development.
If you prefer to run Ghostfolio on your own infrastructure, please find further instructions in the Self-hosting section.
Ghostfolio is for you if you are...
- 💼 trading stocks, ETFs or cryptocurrencies on multiple platforms
- 🏦 pursuing a buy & hold strategy
- 🎯 interested in getting insights of your portfolio composition
- 👻 valuing privacy and data ownership
- 🧘 into minimalism
- 🧺 caring about diversifying your financial resources
- 🆓 interested in financial independence
- 🙅 saying no to spreadsheets
- 😎 still reading this list
- ✅ Create, update and delete transactions
- ✅ Multi account management
- ✅ Portfolio performance: Return on Average Investment (ROAI) for
Today,WTD,MTD,YTD,1Y,5Y,Max - ✅ Various charts
- ✅ Static analysis to identify potential risks in your portfolio
- ✅ Import and export transactions
- ✅ Dark Mode
- ✅ Zen Mode
- ✅ Progressive Web App (PWA) with a mobile-first design
Ghostfolio is a modern web application written in TypeScript and organized as an Nx workspace.
The backend is based on NestJS using PostgreSQL as a database together with Prisma and Redis for caching.
The frontend is built with Angular and uses Angular Material with utility classes from Bootstrap.
We provide official container images hosted on Docker Hub for linux/amd64, linux/arm/v7 and linux/arm64.
| Name | Type | Default Value | Description |
|---|---|---|---|
ACCESS_TOKEN_SALT |
string |
A random string used as salt for access tokens | |
API_KEY_COINGECKO_DEMO |
string (optional) |
The CoinGecko Demo API key | |
API_KEY_COINGECKO_PRO |
string (optional) |
The CoinGecko Pro API key | |
DATABASE_URL |
string |
The database connection URL, e.g. postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}?sslmode=prefer |
|
ENABLE_FEATURE_AUTH_TOKEN |
boolean (optional) |
true |
Enables authentication via security token |
HOST |
string (optional) |
0.0.0.0 |
The host where the Ghostfolio application will run on |
JWT_SECRET_KEY |
string |
A random string used for JSON Web Tokens (JWT) | |
LOG_LEVELS |
string[] (optional) |
The logging levels for the Ghostfolio application, e.g. ["debug","error","log","warn"] |
|
PORT |
number (optional) |
3333 |
The port where the Ghostfolio application will run on |
POSTGRES_DB |
string |
The name of the PostgreSQL database | |
POSTGRES_PASSWORD |
string |
The password of the PostgreSQL database | |
POSTGRES_USER |
string |
The user of the PostgreSQL database | |
REDIS_DB |
number (optional) |
0 |
The database index of Redis |
REDIS_HOST |
string |
The host where Redis is running | |
REDIS_PASSWORD |
string |
The password of Redis | |
REDIS_PORT |
number |
The port where Redis is running | |
REQUEST_TIMEOUT |
number (optional) |
2000 |
The timeout of network requests to data providers in milliseconds |
ROOT_URL |
string (optional) |
http://0.0.0.0:3333 |
The root URL of the Ghostfolio application, used for generating callback URLs and external links. |
| Name | Type | Default Value | Description |
|---|---|---|---|
OPENAI_API_KEY |
string |
OpenAI API key for agent LLM calls (GPT-4o-mini) | |
GHOSTFOLIO_API_TOKEN |
string (optional) |
Ghostfolio security token for eval user (auto-set by eval:seed) | |
AGENT_DB_PATH |
string (optional) |
./data/insights.db |
SQLite path for agent metrics and insights |
LANGSMITH_API_KEY |
string (optional) |
LangSmith API key for trace observability | |
LANGSMITH_PROJECT |
string (optional) |
ghostfolio-agent |
LangSmith project name for grouping traces |
LANGCHAIN_TRACING_V2 |
boolean (optional) |
true |
Enables LangChain tracing to LangSmith |
LANGCHAIN_CALLBACKS_BACKGROUND |
boolean (optional) |
true |
Sends trace callbacks in background (non-blocking) |
| Name | Type | Default Value | Description |
|---|---|---|---|
ENABLE_FEATURE_AUTH_OIDC |
boolean (optional) |
false |
Enables authentication via OpenID Connect |
OIDC_AUTHORIZATION_URL |
string (optional) |
Manual override for the OIDC authorization endpoint (falls back to the discovery from the issuer) | |
OIDC_CALLBACK_URL |
string (optional) |
${ROOT_URL}/api/auth/oidc/callback |
The OIDC callback URL |
OIDC_CLIENT_ID |
string |
The OIDC client ID | |
OIDC_CLIENT_SECRET |
string |
The OIDC client secret | |
OIDC_ISSUER |
string |
The OIDC issuer URL, used to discover the OIDC configuration via /.well-known/openid-configuration |
|
OIDC_SCOPE |
string[] (optional) |
["openid"] |
The OIDC scope to request, e.g. ["email","openid","profile"] |
OIDC_TOKEN_URL |
string (optional) |
Manual override for the OIDC token endpoint (falls back to the discovery from the issuer) | |
OIDC_USER_INFO_URL |
string (optional) |
Manual override for the OIDC user info endpoint (falls back to the discovery from the issuer) |
- Basic knowledge of Docker
- Installation of Docker
- Create a local copy of this Git repository (clone)
- Copy the file
.env.exampleto.envand populate it with your data (cp .env.example .env)
Run the following command to start the Docker images from Docker Hub:
docker compose -f docker/docker-compose.yml up -dRun the following commands to build and start the Docker images:
docker compose -f docker/docker-compose.build.yml build
docker compose -f docker/docker-compose.build.yml up -d- Open http://localhost:3333 in your browser
- Create a new user via Get Started (this first user will get the role
ADMIN)
-
Update the Ghostfolio Docker image
- Increase the version of the
ghostfolio/ghostfolioDocker image indocker/docker-compose.yml - Run the following command if
ghostfolio:latestis set:docker compose -f docker/docker-compose.yml pull
- Increase the version of the
-
Run the following command to start the new Docker image:
docker compose -f docker/docker-compose.yml up -d
The container will automatically apply any required database schema migrations during startup.
Ghostfolio is available for various home server systems, including CasaOS, Home Assistant, Runtipi, TrueCharts, Umbrel, and Unraid.
For detailed information on the environment setup and development process, please refer to DEVELOPMENT.md.
Set the header for each request as follows:
"Authorization": "Bearer eyJh..."
You can get the Bearer Token via POST http://localhost:3333/api/v1/auth/anonymous (Body: { "accessToken": "<INSERT_SECURITY_TOKEN_OF_ACCOUNT>" })
Deprecated: GET http://localhost:3333/api/v1/auth/anonymous/<INSERT_SECURITY_TOKEN_OF_ACCOUNT> or curl -s http://localhost:3333/api/v1/auth/anonymous/<INSERT_SECURITY_TOKEN_OF_ACCOUNT>.
GET http://localhost:3333/api/v1/health
Info: No Bearer Token is required for health check
200 OK
{
"status": "OK"
}
Bearer Token for authorization
POST http://localhost:3333/api/v1/import
{
"activities": [
{
"currency": "USD",
"dataSource": "YAHOO",
"date": "2021-09-15T00:00:00.000Z",
"fee": 19,
"quantity": 5,
"symbol": "MSFT",
"type": "BUY",
"unitPrice": 298.58
}
]
}
| Field | Type | Description |
|---|---|---|
accountId |
string (optional) |
Id of the account |
comment |
string (optional) |
Comment of the activity |
currency |
string |
CHF | EUR | USD etc. |
dataSource |
string |
COINGECKO | GHOSTFOLIO 1 | MANUAL | YAHOO |
date |
string |
Date in the format ISO-8601 |
fee |
number |
Fee of the activity |
quantity |
number |
Quantity of the activity |
symbol |
string |
Symbol of the activity (suitable for dataSource) |
type |
string |
BUY | DIVIDEND | FEE | INTEREST | LIABILITY | SELL |
unitPrice |
number |
Price per unit of the activity |
201 Created
400 Bad Request
{
"error": "Bad Request",
"message": [
"activities.1 is a duplicate activity"
]
}
Grant access of type Public in the Access tab of My Ghostfolio.
GET http://localhost:3333/api/v1/public/<INSERT_ACCESS_ID>/portfolio
Info: No Bearer Token is required for authorization
{
"performance": {
"1d": {
"relativeChange": 0 // normalized from -1 to 1
};
"ytd": {
"relativeChange": 0 // normalized from -1 to 1
},
"max": {
"relativeChange": 0 // normalized from -1 to 1
}
}
}
Discover a variety of community projects for Ghostfolio: https://github.com/topics/ghostfolio
Are you building your own project? Add the ghostfolio topic to your GitHub repository to get listed as well. Learn more →
Ghostfolio is 100% free and open source. We encourage and support an active and healthy community that accepts contributions from the public - including you.
Not sure what to work on? We have some ideas, even for newcomers. Please join the Ghostfolio Slack channel or post to @ghostfolio_ on X. We would love to hear from you.
If you like to support this project, become a Sponsor, get Ghostfolio Premium or Buy me a coffee.
© 2021 - 2026 Ghostfolio
Licensed under the AGPLv3 License.
Footnotes
-
Available with Ghostfolio Premium. ↩


