AGILEX agenticX Review

Comprehensive architecture, implementation, and test plan for the A.G.I.L.E. recruitment intelligence platform

Cloudflare Workers AI Gateway Workers AI Gemini 2.5 Claude Sonnet D1 + KV Google Workspace A2A Protocol MCP Tools 3,577 LOC 3 Repos demo-dev.agilex.co.za

1 Architectural Decision

We evaluated four deployment patterns and selected Cloudflare-first with AI Gateway as the production architecture.

OptionRuntimeAI ModelsCostComplexity
B. CF Workers + AI GatewayTS at edgeAll via GatewayFree tier + tokensLow
A. GCP Cloud Run + ADKPython on GCPGemini + LiteLLMCloud Run + VertexHigh
C. Hybrid (CF + GCP)BothSplit by taskBoth platformsHighest
D. Workers AI onlyTS at edgeLlama/Mistral onlyNeurons onlyLow but limited

Why Cloudflare-First

  • Single platform — compute, state, AI, CDN, DNS in one
  • AI Gateway is the multiplexer — one endpoint routes to 24+ providers
  • Edge-first — Workers AI for fast tasks, Gateway for reasoning
  • Existing code is TypeScript — no rewrite needed
  • Free tier is generous — 100K req/day, 5M D1 reads, caching free

GCP Remains as Stubs

  • Python ADK scaffolding preserved as reference patterns
  • Google Workspace APIs called via REST fetch() from Workers
  • Cloud Run available for future heavy compute if needed
  • Vertex AI accessible via AI Gateway (no direct GCP auth required)
  • agenticx-agents repo stays as architecture docs + Python reference

2 System Architecture

AX demo-dev.agilex.co.za — Cloudflare Worker
API Router/api/agents/*
/api/candidates/*
/.well-known/agent.json
Agent DispatcherOrchestrator routes
to 5 sub-agents
D1 DatabaseCandidates, vacancies
Activity, documents
KV StoreSessions, cache
Rate limits, locks
Static AssetsPortal UI
Guides
AI AI Gateway — Multi-Model Inference
Workers AILlama 3.1 8B (edge)
BGE embeddings
Zero cold start
Gemini 2.5 FlashCV parsing (JSON)
Reports, email drafts
via Google AI Studio
Gemini 2.5 ProCandidate scoring
Complex reasoning
via Google AI Studio
Claude SonnetOffer letters
Quality writing
via Anthropic API
Fallback ChainGemini → Claude
→ Workers AI
Automatic
REST fetch() — Google APIs
GW Google Workspace — Content & Documents (stubs ready for real APIs)
Google DriveCV upload, folders
Share, list files
GmailSend, draft
Search, read
CalendarEvents + Meet
FreeBusy, cancel
SheetsPipeline tracker
Append, read
AuthService account
JWT + delegation

3 A.G.I.L.E. Agents

A

Ava

Acquire
Gemini Flash / Edge
G

Grant

Gauge
Gemini Pro
I

Iris

Integrate
Gemini Flash
L

Leo

Leverage
Gemini Flash
E

Elle

Engage
Claude Sonnet

Agent Capabilities

AgentActionsTools UsedStatus
Acquireparse-cv, searchWorkers AI, Drive, Sheets, ATSWorking
Gaugescore, bulk-scoreGemini Pro, ATS, SheetsWorking
IntegratescheduleCalendar, Gmail, ATSStub tools
Leveragereport, dashboardSheets, ATS, DriveWorking
Engagenotify (stage-update, rejection, offer, teams)Claude, GmailStub tools

Orchestrator Flow

CV Received
Acquire
Parse + Store
Gauge
Score 0-100
Integrate
Schedule
Engage
Notify

Gauge auto-advances to Integrate if score ≥ 80. Engage fires after each stage transition.

4 AI Model Routing via AI Gateway

All inference through one OpenAI-compatible endpoint: gateway.ai.cloudflare.com/v1/{account}/{gateway}/compat/chat/completions

TaskModelProviderWhyFallback
CV text → JSONworkers-ai/llama-3.1-8bEdgeFast, free, structuredGemini Flash
CV structured parsegoogle/gemini-2.5-flashGoogleGood JSON output, cheapWorkers AI
Candidate scoringgoogle/gemini-2.5-proGoogleStrong reasoningClaude Sonnet
Offer lettersanthropic/claude-sonnet-4-6AnthropicQuality writing, legalGemini Pro
Rejection feedbackanthropic/claude-sonnet-4-6AnthropicEmpathetic toneGemini Flash
Pipeline reportsgoogle/gemini-2.5-flashGoogleData synthesis, fastWorkers AI 70B
Routine emailsworkers-ai/llama-3.1-8bEdgeVolume, templated, freeGemini Flash
Embeddingsworkers-ai/bge-baseEdgeAlways edge, instant

AI Gateway Features

Semantic Caching

Identical queries return cached results instantly. TTL: 1h parsing, 24h reports. Expect 30-50% hit rate after 3 months.

Cost Tracking

cf-aig-metadata header tags every request with agent name, task type, and vacancy ID. Dashboard shows cost per agent.

Fallback Routing

If Gemini is down, Claude handles scoring. If both fail, Workers AI provides degraded but functional response.

Calling Pattern

// Edge AI (free, instant)
const result = await env.AI.run('@cf/meta/llama-3.1-8b-instruct', { messages, max_tokens });

// AI Gateway → Gemini or Claude (same endpoint, different model string)
const resp = await fetch(`https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/compat/chat/completions`, {
  method: 'POST',
  headers: {
    'cf-aig-authorization': `Bearer ${aigToken}`,
    'cf-aig-metadata': JSON.stringify({ agent: 'gauge', task: 'score' }),
  },
  body: JSON.stringify({ model: 'google/gemini-2.5-pro', messages, max_tokens: 500 }),
});

5 Google Workspace Integration

All Google APIs are standard REST, called via fetch() from Cloudflare Workers. No Python SDK needed. Currently stubbed — returns simulated responses when service account key is not configured.

ServiceFunctionsAgentStatus
DriveuploadFile, createFolder, listFiles, shareFileAcquireStub
GmailsendEmail, createDraft, searchEmailsEngageStub
CalendarcreateEvent (+ Meet), findFreeSlots, listEventsIntegrateStub
SheetsappendRow, readRange, updateCellLeverageStub
AuthService account JWT → access token (cached in KV)AllStub

To Activate Google Workspace

  1. Create GCP project, enable Gmail/Calendar/Drive/Sheets APIs
  2. Create service account with domain-wide delegation
  3. Base64-encode the service account JSON key
  4. wrangler secret put GOOGLE_SA_KEY (paste base64 value)
  5. Set GOOGLE_DELEGATED_USER, folder IDs, sheet ID, calendar ID in wrangler.toml
  6. Deploy — stubs automatically switch to real API calls

6 A2A Agent Discovery

The portal serves an A2A agent card at /.well-known/agent.json advertising 5 recruitment skills. Any A2A-compatible system can discover and interact with agenticX agents.

{
  "name": "agenticX",
  "url": "https://demo-dev.agilex.co.za",
  "skills": [
    { "id": "recruit/parse-cv", "agent": "acquire" },
    { "id": "recruit/score", "agent": "gauge" },
    { "id": "recruit/schedule", "agent": "integrate" },
    { "id": "recruit/report", "agent": "leverage" },
    { "id": "recruit/notify", "agent": "engage" }
  ],
  "authentication": { "schemes": ["bearer"] }
}

7 Codebase Inventory

RepoLanguageFilesLOCPurposeDeployed
agilex-portalTypeScript141,485Cloudflare Worker — agents, AI Gateway, D1, portal UIagilex-app.pages.dev
agenticx-agentsPython382,092Google ADK reference + architecture docs (GCP stubs)Reference
agilex-siteAstro/TS5513Marketing site — agilex.co.zaagilex-site.pages.dev

Key Portal Source Files

FileLOCPurpose
src/agents/router.ts378All 5 A.G.I.L.E. agents — dispatch, tools, Edge AI calls
src/lib/ai-gateway.ts208Multi-model inference — Workers AI + Gemini + Claude via AI Gateway
src/index.ts126Worker entry — router, CORS, A2A card, Env types
src/sim/m365.ts212Legacy M365 simulation (to be replaced by Google stubs)
src/lib/google/*.ts239Google Workspace stubs — auth, Drive, Gmail, Calendar, Sheets
src/api/ai.ts88Raw AI inference + embedding endpoints
src/api/candidates.ts52Candidate CRUD (D1)
src/api/seed.ts94Demo data — 10 clients, 8 vacancies, 15 candidates
schema.sql86D1 schema — 6 tables

8 Implementation Status

Working Now

  • 5 agent endpoints with real logic (D1 + Workers AI)
  • AI Gateway client with model routing table + fallback chain
  • D1 database — candidates, vacancies, clients, activity, AI usage
  • A2A agent card at /.well-known/agent.json
  • CV parsing with Edge AI (Llama 3.1 8B — tested on Cloudflare)
  • Candidate scoring with reasoning (Edge AI)
  • Pipeline report generation from D1 data
  • Demo data seeder (15 candidates, 8 vacancies, 10 clients)
  • Portal UI with 6 tabs (dashboard, agents, pipeline, M365, Huly, Edge AI)
  • Marketing site with homepage + contact page

Stubbed — Ready for Real Implementation

  • Google Drive upload / folder / share / list
  • Gmail send / draft / search
  • Google Calendar events / FreeBusy / Meet links
  • Google Sheets append / read / update
  • Google auth (JWT service account → token exchange)
  • AI Gateway connection (needs CF_AIG_TOKEN secret)
  • Gemini inference (needs GOOGLE_AI_KEY secret)
  • Claude inference (needs ANTHROPIC_API_KEY secret)
  • demo-dev.agilex.co.za DNS routing

Activation Sequence

Each stubbed capability activates by setting one secret or env var — no code changes needed:

#CapabilitySet ThisActivates
1AI Gateway → Geminiwrangler secret put GOOGLE_AI_KEYCV parsing via Gemini Flash, scoring via Gemini Pro
2AI Gateway → Claudewrangler secret put ANTHROPIC_API_KEYOffer letters, rejections via Claude Sonnet
3AI Gateway authwrangler secret put CF_AIG_TOKENAll Gateway routing, caching, cost tracking
4Google Workspacewrangler secret put GOOGLE_SA_KEYDrive, Gmail, Calendar, Sheets — all tools go live
5Custom domainDNS AAAA demo-dev on agilex.co.zaPortal accessible at demo-dev.agilex.co.za

9 Test Cases

Edge AI (no API keys needed)

E1
CV parse via Workers AI

POST /api/agents/acquire/parse-cv with CV text → structured JSON with name, skills, etc.

Pass
E2
Embedding generation

POST /api/ai/embed with text → 768-dim vector preview

Pass
E3
Candidate scoring (edge fallback)

POST /api/agents/gauge/score with candidateId → score 0-100

Pass
E4
Model listing

GET /api/ai/models → edge + gateway models

Pass

AI Gateway → Gemini (needs GOOGLE_AI_KEY)

G1
Gemini Flash CV parse

POST /api/ai/infer with model=google/gemini-2.5-flash → structured candidate JSON

Key needed
G2
Gemini Pro scoring

POST /api/agents/gauge/score with Gemini Pro model → score + reasoning + tier

Key needed
G3
Gemini report generation

POST /api/agents/leverage/report → pipeline narrative + metrics

Key needed
G4
Semantic caching

Same request twice → second returns faster with cache hit header

Key needed

AI Gateway → Anthropic Claude (needs ANTHROPIC_API_KEY)

C1
Claude offer letter

POST /api/agents/engage/notify type=offer → professional offer email in SA English

Key needed
C2
Claude rejection with feedback

POST /api/agents/engage/notify type=rejection → constructive feedback

Key needed
C3
Claude interview questions

Generate 5-8 structured questions for a vacancy + candidate

Key needed

Fallback Chain

F1
Gemini down → Claude

Block Gemini in gateway → same output from Claude

Manual
F2
All gateway down → Workers AI

Block all providers → Llama 8B handles task at edge

Manual

Google Workspace (needs GOOGLE_SA_KEY)

W1
Upload CV to Drive

PDF bytes → file in Candidates/Active/{name}/ with Drive URL

SA key needed
W2
Send email via Gmail

To, subject, body → email delivered from craig@agilex.co.za

SA key needed
W3
Create calendar event

Summary, datetime, attendees → event with Google Meet link

SA key needed
W4
Append to Sheets

Row values → new row in Pipeline Tracker

SA key needed

End-to-End Workflows

E2E1
Full CV intake

Upload PDF → parse → score → Drive upload → Sheets row → activity log

Phase 2
E2E2
Interview scheduling

Select candidate → find slots → book Calendar → send Gmail → update stage

Phase 2
E2E3
Pipeline report

Request → gather Sheets data → Gemini narrative → upload Drive PDF

Phase 2
E2E4
A2A discovery

GET /.well-known/agent.json → valid A2A card with 5 skills

Pass

POPIA Compliance

P1
Consent tracking

Create candidate → consent_given timestamp in D1

Schema ready
P2
No raw CV in DB

Parse CV → only structured fields + Drive URL stored in D1

Pass
P3
Audit trail

Every agent action → activity logged with timestamp, agent, action

Pass

10 Cost Projection

ComponentMonthly (ZAR)Tier
Cloudflare (Workers, D1, KV, Pages, DNS, CDN)R0Free
AI Gateway (metering, caching, analytics)R0Free
Workers AI (Llama 8B + BGE embeddings)~R90 – R180Usage
Gemini API (Flash + Pro via AI Gateway)~R180 – R540Usage
Anthropic API (Claude Sonnet via AI Gateway)~R360 – R720Usage
Google WorkspaceExisting
TotalR630 – R1,440~$35–80/mo

11 Timeline & Next Steps

PhaseScopeEffortStatus
Phase 0Agent scaffold, AI Gateway client, Google stubs, A2A card, architecture docDoneComplete
Phase 1Set API keys (Gemini, Claude, AI Gateway) → activate multi-model routing1 hourNext
Phase 2Wire agents to use ai-gateway.ts infer() instead of direct Workers AI2-3 daysPlanned
Phase 3Google Workspace — implement real auth + Drive + Gmail + Calendar + Sheets1 weekPlanned
Phase 4E2E workflows — CV intake → score → schedule → notify3-4 daysPlanned
Phase 5Deploy to demo-dev.agilex.co.za, POPIA audit, demo readiness2 daysPlanned

Immediate Next Action

Activate AI Gateway (1 hour)

  1. Create AI Gateway in Cloudflare dashboard: AI → AI Gateway → Create → "agilex-agents"
  2. Get a Google AI Studio API key from aistudio.google.com
  3. Get an Anthropic API key from console.anthropic.com
  4. Set secrets:
    wrangler secret put CF_AIG_TOKEN
    wrangler secret put GOOGLE_AI_KEY
    wrangler secret put ANTHROPIC_API_KEY
  5. Deploy: wrangler deploy
  6. Test multi-model:
    curl -X POST agilex-app.pages.dev/api/ai/infer \
      -d '{"model":"google/gemini-2.5-flash","prompt":"Hello from AgileX"}'
    
    curl -X POST agilex-app.pages.dev/api/ai/infer \
      -d '{"model":"anthropic/claude-sonnet-4-6","prompt":"Hello from AgileX"}'