InsightForge is a FastAPI backend for an agentic content workflow: it can analyze trends, generate personalized Vietnamese social content, manage generated assets, and support a human-approved posting flow.
The repository is intentionally backend. It connects with the InsightForce frontend (Chris-KH/InsightForce). The frontend should talk to the API only; API usage details live in app/api_docs.txt.
- A FastAPI API surface for users, trends, generated content, orchestration, and posting.
- A2A agents for trend analysis, content generation, orchestration, and posting.
- MCP tool servers for trend data, image generation, image retrieval, and social publishing helpers.
- PostgreSQL/Supabase persistence for users, trend analyses, generated content, image metadata, and publish-related data.
- A demo fast-path for UI testing so selected requests return fixed stored responses immediately without running the full agent workflow.
app/ FastAPI routes, schemas, services, database bootstrap
agents/ A2A agents for trend, content, routing, and posting
mcp_servers/ Tool servers used by the agents
database/ Supabase helper client
integrations_api/
External integration wrappers
scripts/ Demo payloads and utility scripts
sample_data/ Local image metadata, embeddings, and image store data
sql/ Database bootstrap SQL
- Python 3.11+
- PostgreSQL-compatible database, usually Supabase
- API keys for the providers you want to run for real workflows
- Optional but recommended: a virtual environment
Install dependencies:
pip install -r requirements.txtCreate a local .env file from .env_example, then replace values with your own credentials. Do not commit real secrets.
Minimum local settings usually include:
DATABASE_URL=postgresql+asyncpg://...
AGENT_HOST=127.0.0.1
ROUTING_AGENT_PORT=9996
TREND_AGENT_PORT=9997
CONTENT_AGENT_PORT=9998
POSTING_AGENT_PORT=9995
CORS_ALLOW_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
DEMO_FAST_PATH_ENABLED=trueAdd provider keys as needed for real agent runs:
GOOGLE_API_KEY=...
SERP_API_KEY=...
ENSEMBLEDATA_API_KEY=...
UPLOAD_POST_API_KEY=...
IMG_BB_API_KEY=...
SUPABASE_URL=...
SUPABASE_KEY=...The FastAPI app calls init_db() on startup to create or update the application tables it knows about.
If you need to bootstrap manually, use:
psql "postgresql://USER:PASSWORD@HOST:PORT/DB?sslmode=require" -f sql/init_postgresql.sqlUse a normal PostgreSQL URL with psql, not the SQLAlchemy postgresql+asyncpg:// form.
Start the FastAPI backend:
uvicorn app.main:app --reloadOpen:
http://127.0.0.1:8000/docs
Health check:
GET http://127.0.0.1:8000/health
The full orchestration path expects the agent servers to be running:
python -m agents.trend_agent.main
python -m agents.generating_agent.main
python -m agents.posting_agent.main
python main.pyThen call:
POST /api/v1/agents/orchestrate
The routing server in main.py coordinates the trend and content agents. Full runs can take a while because they may call LLMs, trend providers, image generation, image storage, and database persistence.
Use app/api_docs.txt for request and response fields. The practical UI entry points are:
GET /healthGET /api/v1/agents/statusPOST /api/v1/agents/orchestratePOST /api/v1/post/postGET /api/v1/contentsGET /api/v1/contents/{content_id}GET /api/v1/trends/historyPOST /api/v1/trends/history/searchGET /api/v1/usersGET /api/v1/users/{user_id}
- Keep edits scoped to the backend repository.
- Restart FastAPI after service or schema changes.
- Restart agent servers after agent prompt/tool changes.
- If the UI seems slow, confirm whether the request matches the demo fast-path sample exactly.
- If image retrieval fails on Windows, check that JSON metadata is read with UTF-8.
- Keep
.env, credentials, and provider keys out of git.
Agents unreachable:
GET /api/v1/agents/status
Slow orchestration:
- Confirm
DEMO_FAST_PATH_ENABLED=truefor demo mode. - Confirm the prompt matches
scripts/script_orchestrator.json. - If running the real workflow, check all agent processes and provider credentials.
Posting flow returns slowly:
- Confirm the request matches one item in
scripts/script_upload.json. - If using the real posting workflow, make sure the posting agent and its MCP server can access image metadata and provider credentials.
Database errors:
- Check
DATABASE_URL. - Confirm Supabase/PostgreSQL allows SSL if required.
- Restart the backend so
init_db()can run.