β οΈ DEVELOPMENT STATUS
This system is currently under active development and bug fixes.
This is a DRAFT VERSION - features, APIs, and configurations may change without notice.
Not recommended for production use at this time.
AgentKS is an agentic RAG (Retrieval-Augmented Generation) knowledge stack under active development, orchestrated with Docker Compose and featuring LangGraph-based multi-skill agent execution, MCP (Model Context Protocol) services, and enterprise authentication. Not production-ready.
- π€ LangGraph Agent - Multi-skill execution with intelligent routing (RAG + Tools + Synthesis)
- π RAG System - Vector search with pgvector, document management via MCP
- π§ Dynamic Tools - Semantic tool discovery, auto-registration via mcp_watcher
- π Enterprise Auth - Authentik SSO with forward_auth pattern
- π Reverse Proxy - Caddy with automatic HTTPS
- π¬ Chat Interface - OpenWebUI for user interactions
- π Multi-Source Search - arXiv, CDS, INSPIRE-HEP, SearXNG integration
- π Admin Dashboard - Web UI for system management
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CADDY :80 / :443 β
β TLS termination + forward_auth (Authentik) β
ββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββββββ
β /webui β /api β /admin β /rag β /hyperparam
β β β β β
openwebui backend backend rag_mcp_ hyperparam_
:8080 :4000 :8000 service advisor_mcp
:5001 service:5020
β
βββββββββββ΄βββββββββββββββββββ
β β
RAG REST Tools MCP
:5000 :5010
(SSE retrieval) - arXiv / CDS
β - INSPIRE-HEP
βββ PostgreSQL + pgvector - SearXNG
Ollama :11434
ββββββββββββββββββββ ββββββββββββββββ ββββββββββββ
β authentik_ β β PostgreSQL β β Ollama β
β server + proxy β β + pgvector β β :11434 β
ββββββββββββββββββββ ββββββββββββββββ ββββββββββββ
AgentKS/
βββ docs/ # Documentation (see docs/INDEX.md)
β βββ INDEX.md # Documentation index
β βββ architecture/ # Architecture documentation
β βββ services/ # Service-specific docs
β βββ guides/ # How-to guides
β βββ api/ # API references
β
βββ backend/ # Backend services
β βββ backend_app/ # Main application
β β βββ agents/ # Agent backend (:4000)
β β βββ admin/ # Admin UI (:8000)
β β βββ rag/ # RAG services (now in rag_mcp_service)
β β βββ tools/ # MCP tool integration
β β βββ migrations/ # Alembic DB migrations
β β βββ supervisord.conf # Multi-service orchestration
β β
β βββ basic_tools_mcp_service/ # Search tools MCP (:5010)
β βββ hyperparam_advisor_mcp_service/ # Hyperparameter optimization MCP (:5020)
β βββ rag_mcp_service/ # RAG MCP + Injector (:5000, :5001)
β βββ searxng/ # SearXNG configuration
β
βββ docker-compose.yml # Full stack orchestration
βββ Caddyfile # HTTP routing & auth
βββ .env.example # Environment template
βββ README.md # This file
See docs/INDEX.md for complete documentation index and docs/architecture/STRUCTURE.md for directory tree
- Docker & Docker Compose
.envfile (copy from.env.exampleand configure)
# Clone repository
git clone https://github.com/BNLNPPS/AgentKS.git
cd AgentKS
# Configure environment
cp .env.example .env
# Edit .env with your settings
# Start all services
docker compose up --build -d
# View logs
docker compose logs -f
# Check status
docker compose ps- OpenWebUI: http://localhost/webui (Chat interface, authenticated via Authentik)
- Agent API: http://localhost/api (OpenAI-compatible API, used by OpenWebUI)
- Admin Dashboard: http://localhost/admin (System management, requires admin group)
- Hyperparameter Advisor: http://localhost/hyperparam (AI-powered optimization suggestions)
- Authentik: http://localhost:9000 (Authentication admin)
Authentication Flow:
- All requests go through Caddy reverse proxy
- Caddy uses forward_auth to Authentik for authentication
- Authentik validates session and injects identity headers
- OpenWebUI trusts
X-Authentik-Email,X-Authentik-Name,X-Authentik-Groupsheaders - Users are automatically logged into OpenWebUI with their Authentik identity
- OpenWebUI calls the Agent API at
/api/v1/*for chat completions
For faster backend iteration without full stack:
cd backend
docker compose -f docker-compose.local.yml up --buildThis starts: Backend + Postgres + Ollama + SearXNG (no Caddy/Authentik)
Direct Access:
- Admin UI: http://localhost:8000/admin
- Agent API: http://localhost:4000/v1/models
- RAG Injector: http://localhost:5001/health
The LangGraph-based agent supports 5 execution patterns:
-
Calculator - Direct math evaluation (fast path)
Query: "12 * (3 + 4)" Flow: analyze β calculator β answer -
RAG Only - Knowledge base search
Query: "What do you know about quantum computing?" Flow: analyze β rag_skill β answer -
Tools Only - External API/search
Query: "Search arXiv for transformer papers" Flow: analyze β tools_skill β answer -
RAG + Tools - Multi-skill with synthesis β
Query: "Compare our research with recent arXiv papers" Flow: analyze β rag_skill β tools_skill β synthesize β answer -
Direct - Conversational response
Query: "Hello, how are you?" Flow: analyze β direct β answer
See docs/architecture/AGENT_FLOW.md for detailed architecture
- arXiv Search - Scientific paper search
- CDS Search - CERN Document Server
- INSPIRE-HEP - High energy physics literature
- SearXNG - Meta search engine (web)
- Calculator - Math expression evaluation
- RAG Search - Internal knowledge base
- Hyperparameter Advisor - ML hyperparameter optimization suggestions based on historical results
Tools are auto-discovered and dynamically bound to the LLM based on semantic relevance.
OpenAI-Compatible API (used by OpenWebUI):
# List models
GET /api/v1/models
# Chat completions (streaming/non-streaming)
POST /api/v1/chat/completions
{
"model": "rag-agent",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": false
}Skills API (internal use):
# RAG Skill - Run RAG with LLM generation
POST /api/rag-skill/ask
# RAG Skill - List available RAG groups
GET /api/rag-skill/groups
# RAG Skill - Smoke test
GET /api/rag-skill/test
# Tools Skill - Run tools with dynamic discovery
POST /api/tools-skill/query
# Tools Skill - Smoke test
GET /api/tools-skill/testNote: Caddy strips /rag prefix before forwarding to rag_mcp_service:5001
# Health check
# Client: GET /rag/health -> Backend: GET /health
GET /rag/health
# Upload document
# Client: POST /rag/upload -> Backend: POST /upload
POST /rag/upload
# List documents
# Client: GET /rag/documents -> Backend: GET /documents
GET /rag/documents# Inject optimization results
POST /hyperparam/inject
{
"experiment_id": "cnn_opt_v1",
"results": [
{
"hyperparameters": {"lr": 0.001, "batch_size": 32},
"result": 0.92,
"result_type": "maximize"
}
]
}
# Get suggestions
POST /hyperparam/suggest
{
"target_params": ["lr", "batch_size", "dropout"],
"result_type": "maximize",
"n_suggestions": 3
}# Health check
GET /admin/api/health
# Response: {"ok": true}
# Dashboard (browser)
GET /adminWhen behind Caddy + Authentik:
curl -H "X-Authentik-Groups: admin" \
-H "X-Authentik-Email: user@example.com" \
-H "X-Authentik-Name: John Doe" \
http://localhost/admin/api/health# Domain configuration
DOMAIN=your-domain.com
# Note: AUTH_DOMAIN is the same as DOMAIN β Authentik is served under the same domain
# Authentik
AUTHENTIK_TAG=2024.2.0
AUTHENTIK_SECRET_KEY=<generate-random-50-char-key>
AUTHENTIK_OUTPOST_TOKEN=<from-authentik-admin-panel>
# Database
AK_POSTGRES_DB=authentik
AK_POSTGRES_USER=authentik
AK_POSTGRES_PASSWORD=<secure-password>
AK_REDIS_PASSWORD=<secure-password>
# OpenWebUI
WEBUI_AUTH=true # Authentik-based authentication via trusted headers
OPENWEBUI_POSTGRES_DB=openwebui # Optional, defaults to 'openwebui'
# Backend
DATABASE_URL=postgresql+psycopg://${AK_POSTGRES_USER}:${AK_POSTGRES_PASSWORD}@postgres:5432/${AK_POSTGRES_DB}
OLLAMA_BASE_URL=http://ollama:11434
OLLAMA_CHAT_MODEL=llama2:7b
OLLAMA_EMBED_MODEL=nomic-embed-text
# Collections
COLLECTION_DOCS=kb_docs
COLLECTION_TOOLS=tool_catalogSee .env.example for complete configuration
| Port | Service | Access | Purpose |
|---|---|---|---|
| 80/443 | Caddy | Public | HTTP/HTTPS ingress |
| 8000 | Admin UI | Via Caddy | Dashboard |
| 4000 | Agent API | Via Caddy | OpenAI-compatible API |
| 5000 | RAG MCP | Internal | Document retrieval (SSE) |
| 5001 | RAG Injector | Internal | Document ingestion (REST) |
| 5010 | Tools MCP | Internal | Search tools (SSE) |
| 5020 | Hyperparam MCP | Internal | Hyperparameter optimization (SSE) |
| 8080 | OpenWebUI | Via Caddy | Chat interface |
| 11434 | Ollama | Internal | LLM inference |
# All services
docker compose logs -f
# Specific service
docker compose logs -f backend
# Within backend container (supervisord)
docker compose exec backend supervisorctl tail -f app
docker compose exec backend supervisorctl tail -f mcp_watcherdocker compose exec backend alembic upgrade headcd backend/backend_app
# Install dependencies
pip install -r requirements.txt
# Run migrations
alembic upgrade head
# Run services individually
uvicorn agents.main:app --reload --port 4000
uvicorn admin.main:app --reload --port 8000
python -m urls.daemons.url_watcher
python -m tools.daemons.watcher# Test RAG skill
curl -X POST http://localhost:8000/api/rag-skill/ask \
-H "Content-Type: application/json" \
-d '{"query": "What is quantum computing?", "k": 5}'
# Test Tools skill
curl -X POST http://localhost:8000/api/tools-skill/query \
-H "Content-Type: application/json" \
-d '{
"query": "search arXiv for transformer papers",
"user_id": "test@example.com",
"role": "user"
}'
# Test chat completions
curl -X POST http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "rag-agent",
"messages": [{"role": "user", "content": "Hello!"}]
}'docker compose up -d
docker compose ps
docker compose logs -fREADME.md- This file: Project overview and quick startdocs/INDEX.md- Complete documentation indexdocs/architecture/STRUCTURE.md- Repository structure and architecturedocs/architecture/AGENT_FLOW.md- Multi-skill agent execution patternsdocs/architecture/CADDY_ROUTING.md- Caddy routing and path rewritingdocs/services/backend_app.md- Backend services guidedocs/guides/llm_management.md- LLM configurationdocs/services/agents/rag_skill.md- RAG skill usagedocs/services/mcp_services/hyperparam_advisor.md- Hyperparameter optimization tool
User Request
β
Caddy
β
Forward Auth β Authentik Proxy
β
Is Authenticated?
β
ββββ΄βββ
YES NO
β β
Add Headers Redirect to Login
β β
Backend Login Success
Services β
Redirect Back
Identity Headers:
X-Authentik-Email- User email (canonical user ID)X-Authentik-Name- Display nameX-Authentik-Groups- User groups (comma-separated)
Services treat these headers as the authoritative identity source.
| Category | Technology |
|---|---|
| Orchestration | Docker Compose, Supervisord |
| Web Framework | FastAPI |
| Agent Framework | LangGraph |
| LLM | Ollama (llama2, nomic-embed-text) |
| Vector DB | PostgreSQL with pgvector |
| Authentication | Authentik |
| Reverse Proxy | Caddy 2.8 |
| MCP Protocol | SSE/HTTP transport |
| Search | SearXNG, arXiv API, CDS, INSPIRE-HEP |
| Migrations | Alembic |
| UI | OpenWebUI, Flowbite (admin) |
# Check postgres is ready
docker compose exec postgres pg_isready
# Check logs
docker compose logs backend
# Run migrations manually
docker compose exec backend alembic upgrade head# Check mcp_watcher logs
docker compose exec backend supervisorctl tail -f mcp_watcher
# Verify basic_tools_mcp_service
curl http://localhost:5010/health
# Check database for registered tools
docker compose exec postgres psql -U authentik -d authentik \
-c "SELECT name, enabled FROM tool_catalog;"# Test tool discovery
curl -X POST http://localhost:8000/api/tools-skill/query \
-H "Content-Type: application/json" \
-d '{"query": "search for papers", "user_id": "test", "role": "user"}'
# Check TOOL_SELECT_TOPK environment variable
docker compose exec backend env | grep TOOL_SELECT_TOPK# Check RAG MCP service is up
curl http://localhost:5000/health
# Verify injector
curl http://localhost:5001/health
# Test retrieval directly
curl -X POST http://localhost:8000/api/rag-skill/ask \
-H "Content-Type: application/json" \
-d '{"query": "test query", "k": 5}'- Configure
.envwith production values - Set strong passwords for
AK_POSTGRES_PASSWORD,AK_REDIS_PASSWORD - Generate secure
AUTHENTIK_SECRET_KEY(50+ characters) - Configure
DOMAIN(Authentik uses the same domain) - Set up DNS records pointing to your server
- Configure Authentik via admin panel
- Create outpost in Authentik, get token for
AUTHENTIK_OUTPOST_TOKEN
# Start services
docker compose up -d
# Check all services are healthy
docker compose ps
# View logs
docker compose logs -f- Main Application: https://your-domain.com/webui
- Admin Dashboard: https://your-domain.com/admin
- Authentik Admin: https://your-domain.com/if/admin/
# Check service status
docker compose ps
# View resource usage
docker stats
# Check backend services
docker compose exec backend supervisorctl status| Docker Service | Directory | Ports | Purpose |
|---|---|---|---|
caddy |
N/A (image) | 80, 443 | Reverse proxy + TLS |
postgres |
N/A (image) | 5432 | PostgreSQL + pgvector |
redis |
N/A (image) | 6379 | Redis cache |
authentik_server |
N/A (image) | 9000 | Auth server |
authentik_worker |
N/A (image) | - | Background worker |
authentik_proxy |
N/A (image) | 9000 | Forward auth proxy |
openwebui |
N/A (image) | 8080 | Chat interface (uses Authentik + PostgreSQL) |
backend |
backend/backend_app/ |
8000, 4000 | Multi-service backend |
rag_mcp_service |
backend/rag_mcp_service/ |
5000, 5001 | RAG MCP (SSE) + Injector (REST) |
basic_tools_mcp_service |
backend/basic_tools_mcp_service/ |
5010 | Search tools MCP |
hyperparam_advisor_mcp_service |
backend/hyperparam_advisor_mcp_service/ |
5020 | Hyperparameter optimization MCP |
ollama |
N/A (image) | 11434 | LLM inference |
searxng |
N/A (image) | 8081 | Meta search engine |
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
[Add your license here]
- LangChain - Agent framework
- LangGraph - Graph-based agent orchestration
- Authentik - Identity provider
- Caddy - Modern web server
- Ollama - Local LLM inference
- pgvector - Vector similarity search
- Issues: GitHub Issues
- Documentation: See
docs/directory - Copilot Context:
.github/copilot-instructions.md
Made with β€οΈ by BNLNPPS