xiaohongshu
xiaohongshu
cva-setup-vertex
Complete Vertex AI and Google Cloud Platform setup for Clojure agent development. Includes GCP project saas3-476116 credentials, security best practices (IAM, key rotation, LGPD), cost analysis, API enablement, and environment configuration. Use when starting new Clojure+Vertex project, configuri...
Full skill instructions
Last Updated: 2025-10-27 Status: Python/ADK environment validated, ready for Clojure integration GCP Project: saas3-476116
This skill consolidates complete context for the existing Vertex AI project to facilitate integration with Clojure. The goal is to leverage the already-configured GCP infrastructure and lessons learned from Python ADK to create agents using Clojure.
| Property | Value |
|---|---|
| Project ID | saas3-476116 |
| Primary Region | us-central1 |
| Service Account | [email protected] |
| JSON Key | ~/.gcp-credentials/vertex-ai-app-key.json |
| Key Permissions | chmod 600 (always verify) |
# Critical APIs already enabled
- aiplatform.googleapis.com # Vertex AI API
- generativelanguage.googleapis.com # Gemini API
- cloudbuild.googleapis.com # Cloud Build
- run.googleapis.com # Cloud Run
# Verify APIs
gcloud services list --enabled --project=saas3-476116
File: ~/.env (chmod 600, DO NOT commit)
# Google Cloud Configuration
export GOOGLE_CLOUD_PROJECT="saas3-476116"
export GOOGLE_APPLICATION_CREDENTIALS="$HOME/.gcp-credentials/vertex-ai-app-key.json"
export GOOGLE_CLOUD_LOCATION="us-central1"
# Vertex AI Endpoint
export VERTEX_AI_ENDPOINT="us-central1-aiplatform.googleapis.com"
# For Vertex AI with Google Generative AI SDK
export GOOGLE_GENAI_USE_VERTEXAI="TRUE"
# ADK Configuration
export ADK_MODEL="gemini-1.5-flash"
export ADK_TEMPERATURE="0.7"
export ADK_MAX_TOKENS="2048"
⚠️ CRITICAL: Protect file:
chmod 600 ~/.env
Read environment variables in Clojure:
(ns lab.config.google-cloud
"Google Cloud configuration from environment"
(:require [clojure.java.io :as io]))
(defn get-env
"Reads environment variable with fallback"
[key default]
(or (System/getenv key) default))
(def gcp-config
{:project-id (get-env "GOOGLE_CLOUD_PROJECT" "saas3-476116")
:location (get-env "GOOGLE_CLOUD_LOCATION" "us-central1")
:credentials (get-env "GOOGLE_APPLICATION_CREDENTIALS"
(str (System/getProperty "user.home")
"/.gcp-credentials/vertex-ai-app-key.json"))
:endpoint (get-env "VERTEX_AI_ENDPOINT"
"us-central1-aiplatform.googleapis.com")})
(defn validate-credentials
"Validates that credentials file exists and is readable"
[]
(let [creds-file (io/file (:credentials gcp-config))]
(when-not (.exists creds-file)
(throw (ex-info "Credentials file not found"
{:path (:credentials gcp-config)})))
(when-not (.canRead creds-file)
(throw (ex-info "Credentials file not readable"
{:path (:credentials gcp-config)})))
true))
;; Usage
(comment
(validate-credentials)
;; => true or throws ex-info
(:project-id gcp-config)
;; => "saas3-476116"
)
Current Role: roles/aiplatform.user (least privilege)
# Verify current roles
gcloud projects get-iam-policy saas3-476116 \
--flatten="bindings[].members" \
--filter="bindings.members:serviceAccount:vertex-ai-app*"
# Expected output:
# - roles/aiplatform.user (use Vertex AI)
# 1. List existing keys
gcloud iam service-accounts keys list \
[email protected] \
--format="table(name,validAfterTime,validBeforeTime)"
# 2. Create new key
gcloud iam service-accounts keys create \
~/.gcp-credentials/vertex-ai-app-key-new.json \
[email protected]
# 3. Protect
chmod 600 ~/.gcp-credentials/vertex-ai-app-key-new.json
# 4. Test
GOOGLE_APPLICATION_CREDENTIALS=~/.gcp-credentials/vertex-ai-app-key-new.json \
gcloud auth application-default print-access-token
# 5. Update ~/.env and delete old key
gcloud iam service-accounts keys delete OLD_KEY_ID \
[email protected]
| Component | Cost per Execution | Monthly (20 posts) |
|---|---|---|
| S.1.1 (Type B - LGPD Extraction) | $0.045 | $0.90 |
| S.1.2 (Type A - Claims ID) | $0.021 | $0.42 |
| S.2-1.2 (Type C - References) | $0.067 | $1.34 |
| S.3-2 (Type B - SEO) | $0.078 | $1.56 |
| S.4 (Type D - Consolidation) | $0.18 | $3.60 |
| Total per post | $0.391 | $7.82 |
With optimizations (cache + parallel):
| Model | Input (1M tokens) | Output (1M tokens) | Best For |
|---|---|---|---|
| gemini-1.5-flash | $0.075 | $0.30 | Type A/B (70% of tasks) |
| gemini-1.5-pro | $1.25 | $5.00 | Type C/D (complex reasoning) |
| gemini-2.5-flash | $0.10 | $0.40 | Balanced (future) |
Multi-model strategy savings: 41% vs Claude-only
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
;; Google Cloud Vertex AI (Java SDK)
com.google.cloud/google-cloud-aiplatform {:mvn/version "3.36.0"}
com.google.cloud/google-cloud-vertexai {:mvn/version "0.2.0"}
;; Google Auth
com.google.auth/google-auth-library-oauth2-http {:mvn/version "1.19.0"}
;; JSON handling
cheshire/cheshire {:mvn/version "5.11.0"}
;; HTTP client
clj-http/clj-http {:mvn/version "3.12.3"}
;; Database (if using Type B/D)
com.github.seancorfield/next.jdbc {:mvn/version "1.3.909"}
org.postgresql/postgresql {:mvn/version "42.6.0"}
;; Python interop (optional, for libpython-clj)
clj-python/libpython-clj {:mvn/version "2.025"}
;; Logging
org.clojure/tools.logging {:mvn/version "1.2.4"}
ch.qos.logback/logback-classic {:mvn/version "1.4.11"}}
:aliases
{:dev {:extra-paths ["dev"]
:extra-deps {nrepl/nrepl {:mvn/version "1.0.0"}
cider/cider-nrepl {:mvn/version "0.30.0"}}}
:test {:extra-paths ["test"]
:extra-deps {org.clojure/test.check {:mvn/version "1.1.1"}}}}}
(ns lab.agents.basic
"Basic Type A agent example"
(:require [lab.config.google-cloud :as gc]
[cheshire.core :as json])
(:import [com.google.cloud.vertexai VertexAI]
[com.google.cloud.vertexai.generativeai GenerativeModel]
[com.google.cloud.vertexai.api GenerationConfig]))
(defn create-vertex-ai-instance
"Creates Vertex AI instance with credentials."
[]
(let [{:keys [project-id location credentials]} gc/gcp-config]
(gc/validate-credentials)
(VertexAI. project-id location)))
(defn create-generative-model
"Creates a generative model."
([vertex-ai] (create-generative-model vertex-ai "gemini-1.5-flash"))
([vertex-ai model-name]
(let [generation-config (-> (GenerationConfig/newBuilder)
(.setTemperature 0.7)
(.setMaxOutputTokens 2048)
(.setTopP 0.95)
(.build))
model (.getGenerativeModel vertex-ai model-name)]
(.withGenerationConfig model generation-config))))
(defn generate-content
"Generates content from prompt."
[model prompt]
(let [response (.generateContent model prompt)]
{:text (-> response .getText)
:metadata {:model (.getModelName model)
:finish-reason (-> response .getCandidates first .getFinishReason str)}}))
;; REPL Usage
(comment
;; 1. Create Vertex AI instance
(def vertex-ai (create-vertex-ai-instance))
;; 2. Create model
(def model (create-generative-model vertex-ai "gemini-1.5-flash"))
;; 3. Generate content
(def result
(generate-content
model
"Explain functional programming in Clojure in 3 sentences."))
(:text result)
;; => "Functional programming in Clojure emphasizes..."
;; 4. Clean up
(.close vertex-ai)
)
DO:
~/.gcp-credentials/ (outside repo)chmod 600 on all credential filesGOOGLE_APPLICATION_CREDENTIALS environment variableDON'T:
roles/owner)# GCP Credentials
.gcp-credentials/
*-key.json
*.json.enc
# Environment files
.env
.env.local
.env.*.local
# Secrets
secrets/
credentials/
Minimum roles needed:
roles/aiplatform.user - Use Vertex AIroles/logging.viewer - View logs (optional)Avoid:
roles/owner - Too broadroles/editor - Too broadroles/aiplatform.admin - Unless deployingWhen processing personal data:
(ns lab.compliance.lgpd
"LGPD compliance utilities")
(def sensitive-data-patterns
"Patterns for detecting sensitive personal data"
{:cpf #"\d{3}\.\d{3}\.\d{3}-\d{2}"
:rg #"\d{1,2}\.\d{3}\.\d{3}-\d{1,2}"
:email #"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"
:phone #"\(?[0-9]{2}\)?\s?[0-9]{4,5}-?[0-9]{4}"
:health-data #"(?i)(diabetes|hipertens[ãa]o|depress[ãa]o|ansiedade)"})
(defn detect-sensitive-data
"Detects sensitive personal data in text."
[text]
(reduce-kv
(fn [acc data-type pattern]
(if (re-find pattern text)
(conj acc data-type)
acc))
[]
sensitive-data-patterns))
(defn sanitize-for-logging
"Removes sensitive data before logging."
[text]
(reduce-kv
(fn [sanitized data-type pattern]
(clojure.string/replace sanitized pattern "[REDACTED]"))
text
sensitive-data-patterns))
;; Usage
(comment
(detect-sensitive-data "Cliente: João Silva, CPF: 123.456.789-00")
;; => [:cpf]
(sanitize-for-logging "Cliente: João Silva, CPF: 123.456.789-00")
;; => "Cliente: João Silva, CPF: [REDACTED]"
)
📘 Full compliance guide: See
cva-healthcare-complianceskill.
# 1. Verify gcloud auth
gcloud auth application-default print-access-token
# 2. Verify project
gcloud config get-value project
# Expected: saas3-476116
# 3. Verify APIs
gcloud services list --enabled --project=saas3-476116 | grep aiplatform
# 4. Test Vertex AI access
gcloud ai models list --region=us-central1 --project=saas3-476116
(ns lab.test.integration
"Integration tests for Vertex AI"
(:require [clojure.test :refer :all]
[lab.config.google-cloud :as gc]
[lab.agents.basic :as basic]))
(deftest test-vertex-ai-connection
(testing "Can create Vertex AI instance"
(let [vertex-ai (basic/create-vertex-ai-instance)]
(is (some? vertex-ai))
(.close vertex-ai))))
(deftest test-model-generation
(testing "Can generate content"
(let [vertex-ai (basic/create-vertex-ai-instance)
model (basic/create-generative-model vertex-ai)
result (basic/generate-content model "Say 'test'")]
(is (string? (:text result)))
(is (> (count (:text result)) 0))
(.close vertex-ai))))
Run tests:
clojure -X:test
Problem: GOOGLE_APPLICATION_CREDENTIALS not set or file doesn't exist
Solution:
# Verify file exists
ls -la ~/.gcp-credentials/vertex-ai-app-key.json
# Verify permissions
chmod 600 ~/.gcp-credentials/vertex-ai-app-key.json
# Set environment variable
export GOOGLE_APPLICATION_CREDENTIALS="$HOME/.gcp-credentials/vertex-ai-app-key.json"
# Test
gcloud auth application-default print-access-token
Problem: Vertex AI API not enabled for project
Solution:
gcloud services enable aiplatform.googleapis.com --project=saas3-476116
Problem: Service account lacks necessary roles
Solution:
gcloud projects add-iam-policy-binding saas3-476116 \
--member="serviceAccount:[email protected]" \
--role="roles/aiplatform.user"
Problem: Exceeded Vertex AI quotas
Solution:
# Check quotas
gcloud compute project-info describe --project=saas3-476116
# Request quota increase (if needed)
# https://console.cloud.google.com/iam-admin/quotas?project=saas3-476116
cva-setup-clojure - Clojure project structurecva-setup-interop - libpython-clj setupcva-healthcare-compliance - LGPD compliance ⭐cva-concepts-adk - Google ADK architecturecva-quickref-adk - ADK quick referenceThis setup is validated for production healthcare systems with proven ROI. Follow security best practices rigorously.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience