A generative AI-powered agent designed to automate data governance on Google Cloud. It allows users to define, validate, and enforce data policies using natural language queries, translating them into executable code that runs against Google Cloud Dataplex and BigQuery metadata.
The Agent Starter Pack (ASP) is the recommended way to create a new project from this sample: you get deployment options and CI/CD scaffolding. The copy in adk-samples is the upstream source for browsing and contributions.
- Python 3.11+
- uv — fast Python package manager
- Google Cloud SDK (
gcloud) installed and authenticated - Git
The Agent Starter Pack is the recommended way to create and deploy a production-ready version of this agent. Start from a new directory (replace my-policy-as-code with your project name):
uvx agent-starter-pack create my-policy-as-code -a adk@policy-as-code
cd my-policy-as-codeInstall dependencies (including dev tools for tests):
uv sync --group dev-
Copy the example configuration file:
cp .env.example .env
-
Open
.envand fill in your details:GOOGLE_CLOUD_PROJECT: Your Google Cloud Project ID.GOOGLE_CLOUD_LOCATION: (e.g.,us-central1).ENABLE_MEMORY_BANK: Set toTrueto enable long-term memory (requires Firestore). Set toFalseto run without it. See Memory Integration for details.FIRESTORE_DATABASE: (Optional) Leave as(default)unless using a named database.
-
Authenticate with Google Cloud:
gcloud auth application-default login
During setup, the starter pack will prompt you for deployment options and adds production-oriented tooling (for example automated CI/CD deployment scripts).
Alternative: install Agent Starter Pack with pip
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install --upgrade agent-starter-pack
agent-starter-pack create my-policy-as-code -a adk@policy-as-code
cd my-policy-as-codeThen continue with uv sync --group dev and the configuration steps above.
Clone this repository directly (contributors and advanced use)
Use this workflow when working against the upstream repository (for example to open a pull request). New projects should still use the Agent Starter Pack as described above.
git clone https://github.com/google/adk-samples.git
cd adk-samples/python/agents/policy-as-code
uv sync --group dev
cp .env.example .env
# Edit .env with your GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION, etc.
gcloud auth application-default loginRun the agent and tests with the same commands as in the recommended path (uv run adk run, uv run adk web, uv run pytest).
From your project directory (ASP-scaffolded or cloned repo):
uv run adk run policy_as_code_agentOr use the web UI:
uv run adk webOptional: To enable short-term contextual memory (Agent Engine) for better conversation history:
uv run adk web --memory_service_uri="agentengine://AGENT_ENGINE_ID"Open the printed URL in your browser to chat with the agent.
uv run pytestRun only fast unit tests:
uv run pytest tests/unit -vIntegration tests are marked and may require GCP credentials and a configured .env.
- Natural Language Policies: "All tables in the finance dataset must have a description."
- Hybrid Execution: Generates Python code on-the-fly for flexibility, but executes it in a sandboxed environment for safety.
- Memory & Learning: Uses Firestore and Vector Search to remember valid policies. If you ask a similar question later, it reuses the proven code instead of regenerating it.
- Dual-Mode Operation:
- Live Mode: Queries the Dataplex Universal Catalog in real-time.
- Offline Mode: Analyzes metadata exports stored in Google Cloud Storage (GCS).
- Compliance Scorecards: Run a full health check on your data assets with a single command.
- Remediation: Can suggest specific fixes for identified violations.
The agent is built using the Google Cloud Agent Development Kit (ADK) and leverages several Google Cloud services:
- Gemini 2.5 Pro: For complex code generation (converting natural language to Python).
- Gemini 2.5 Flash: For conversational logic, tool selection, and remediation suggestions.
- Vertex AI Vector Search: For semantic retrieval of past policies.
- Firestore: Stores policy definitions, versions, and execution history.
- Dataplex API: For fetching live metadata.
policy_as_code_agent/__init__.py: Application Default Credentials and Vertex environment defaults for ASP/local runs.agent.py: Entry point and core agent definition.memory.py: Handles Firestore interactions (saving/retrieving policies).utils/: Utility modules for LLM logic, Dataplex, GCS, and common tools.simulation.py: Sandboxed execution engine for running policy code.prompts/: Markdown templates for LLM instructions.
tests/: Unit and integration tests.data/: Sample metadata for local testing.
For deep dives into the implementation, check the docs/ folder: