A Real-Time, Privacy-First Agentic System for Dynamic Task-Worker Matching.
- The Project: A dynamic dispatch engine that matches Clients' tasks to the best available Workers using semantic intelligence.
- The Engine: Local FastAPI server managing the "Source of Truth" (Worker status & Vector embeddings).
- The Orchestrator: Vercel-hosted SvelteKit using the Vercel AI SDK to reason over system state and suggest assignments.
The system separates Reasoning (Cloud LLM) from Authoritative State (Local Postgres). This ensures the Agent always knows who is available before suggesting a match.
graph TD
subgraph Vercel_Edge [Cloud: SvelteKit Orchestration]
A[Client/Worker UI] -->|1. Post Task / Update Status| B[Vercel AI SDK]
B -->|2. Reasoning| C[LLM: GPT-4o-Mini]
C -->|3. Tool: query_state| B
end
subgraph Local_Vault [Local: Private Data & State]
B -->|4. Secure Tunnel| D[FastAPI: uv Server]
D -->|5. Hybrid Search| E[(Postgres + pgvector)]
E -->|6. Filter Available + Semantic Match| D
D -->|7. Verified Candidates| B
end
B -->|8. Proposed Assignment| A
A -->|9. Atomic Accept| D
D -->|10. Set Worker BUSY| E
We combine Relational State (Availability) with Vector Search (Skills). This prevents the Agent from assigning a worker who is already busy.
We use Pydantic AI tools to allow the Agent to "see" inside the local database.
Hybrid Search Logic:
| Strategy | Implementation | Benefit |
|---|---|---|
| Hybrid Search | Filter status = 'available' in SQL before the vector match. |
Precision: Prevents the LLM from hallucinating assignments for busy workers. |
| Atomic Claiming | UPDATE tasks SET worker_id = X WHERE worker_id IS NULL. |
Safety: Prevents "Race Conditions" where two workers claim the same task. |
| State Awareness | Agent must call get_available_candidates tool every time. |
Real-time: Ensures the Agent uses the latest updates before generating a response. |
| Local Vault | All PII (Names, Bios, Skill vectors) stays on local hardware. | Privacy: Only minimal candidate IDs are sent to the Cloud LLM. |
| Tool | Install |
|---|---|
| Python 3.11+ | https://python.org |
| uv | pip install uv |
| Docker Desktop | https://docker.com |
| Node.js 18+ | https://nodejs.org |
| Git | https://git-scm.com |
git clone https://github.com/<your-org>/agentic-system.git
cd agentic-systemcd backend
docker compose up -dCreate the schema (first time only):
docker exec -i agentic-system-db-1 psql -U postgres -c "
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE IF NOT EXISTS workers (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
bio TEXT,
location TEXT,
status TEXT DEFAULT 'available',
skills_embedding vector(384)
);
CREATE TABLE IF NOT EXISTS tasks (
id SERIAL PRIMARY KEY,
description TEXT,
worker_id INT REFERENCES workers(id),
status TEXT DEFAULT 'open',
metadata JSONB,
created_at TIMESTAMPTZ DEFAULT now()
);
"# Still inside backend/
uv venv
uv pip install fastapi uvicorn psycopg[binary] sentence-transformers pydantic
copy .env.example .env
# Edit .env — the default DATABASE_URL matches docker-compose defaults
# Seed sample workers (runs local embedding model)
.venv\Scripts\python.exe seed_workers.py.venv\Scripts\python.exe -m uvicorn main:app --host 0.0.0.0 --port 8000 --reloadYou will see Embedding model ready. — model is loaded once at startup, not per request.
# From backend/
.\cloudflared.exe tunnel --url http://localhost:8000Copy the https://*.trycloudflare.com URL from the output.
cd ..\frontend
npm install
copy .env.example .env.local
# Edit .env.local:
# PUBLIC_LOCAL_VAULT_URL=https://<your-tunnel>.trycloudflare.com
# OPENAI_API_KEY=sk-...
npm run dev
# Open http://localhost:5173npx vercel
vercel env add PUBLIC_LOCAL_VAULT_URL # paste tunnel URL
vercel env add OPENAI_API_KEY
vercel --prod- Client posts a task through SvelteKit.
- Agent (Vercel) queries Local Vault for the best available matches.
- Agent presents the top match to the Worker.
- Worker clicks "Accept" → FastAPI atomically marks worker as
busyand task asassigned.
| Status | Component | Command |
|---|---|---|
| ✅ | Local DB | cd backend ; docker compose up -d |
| ✅ | Backend API | cd backend ; .venv\Scripts\python.exe -m uvicorn main:app --port 8000 --reload |
| ✅ | Tunnel | cd backend ; .\cloudflared.exe tunnel --url http://localhost:8000 |
| ✅ | Frontend (dev) | cd frontend ; npm run dev |
| ☁️ | Frontend (prod) | Deploy to Vercel + set PUBLIC_LOCAL_VAULT_URL + OPENAI_API_KEY |